Skip to content

Commit ec22e02

Browse files
committed
fix: fix setupBin
1 parent c6eb5ca commit ec22e02

File tree

9 files changed

+47
-21
lines changed

9 files changed

+47
-21
lines changed

src/cmake/__tests__/cmake.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jest.setTimeout(300000)
66
describe("setup-cmake", () => {
77
let directory: string
88
beforeAll(async () => {
9-
directory = await setupTmpDir("setup-cmake")
9+
directory = await setupTmpDir("cmake")
1010
})
1111

1212
it("should setup CMake", async () => {
@@ -21,6 +21,6 @@ describe("setup-cmake", () => {
2121
})
2222

2323
afterAll(async () => {
24-
await cleanupTmpDir("setup-cmake")
24+
await cleanupTmpDir("cmake")
2525
}, 100000)
2626
})

src/cmake/cmake.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { getInput } from "@actions/core"
33
import semverLte from "semver/functions/lte"
44
import semverCoerce from "semver/functions/coerce"
55
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
6+
import { addBinExtension } from "../utils/extension/extension"
67

78
/** Get the platform data for cmake */
89
function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): PackageInfo {
@@ -21,6 +22,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
2122
const folderName = `cmake-${version}-${osArchStr}`
2223
return {
2324
binRelativeDir: "bin/",
25+
binFileName: addBinExtension("cmake"),
2426
extractedFolderName: folderName,
2527
extractFunction: extractZip,
2628
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.zip`,
@@ -32,6 +34,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
3234
const folderName = `cmake-${version}-${osArchStr}`
3335
return {
3436
binRelativeDir: "CMake.app/Contents/bin/",
37+
binFileName: addBinExtension("cmake"),
3538
extractedFolderName: folderName,
3639
extractFunction: extractTar,
3740
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,
@@ -48,6 +51,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa
4851
const folderName = `cmake-${version}-${osArchStr}`
4952
return {
5053
binRelativeDir: "bin/",
54+
binFileName: addBinExtension("cmake"),
5155
extractedFolderName: folderName,
5256
extractFunction: extractTar,
5357
url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`,

src/llvm/__tests__/llvm.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ async function testUrl(version: string) {
1515
describe("setup-llvm", () => {
1616
let directory: string
1717
beforeAll(async () => {
18-
directory = await setupTmpDir("setup-llvm")
18+
directory = await setupTmpDir("llvm")
1919
})
2020

2121
it("Finds valid LLVM URLs", async () => {

src/llvm/llvm.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin
77
import { extractExe, extractTarByExe } from "../utils/setup/extract"
88
import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version"
99
import { setupMacOSSDK } from "../macos-sdk/macos-sdk"
10+
import { addBinExtension } from "../utils/extension/extension"
1011

1112
//================================================
1213
// Version
@@ -227,6 +228,7 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P
227228
url,
228229
extractedFolderName: "",
229230
binRelativeDir: "bin",
231+
binFileName: addBinExtension("clang"),
230232
extractFunction: platform === "win32" ? extractExe : extractTarByExe,
231233
}
232234
}

src/ninja/__tests__/ninja.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ async function testNinja(directory: string) {
1111
describe("setup-ninja", () => {
1212
let directory: string
1313
beforeEach(async () => {
14-
directory = await setupTmpDir("setup-ninja")
14+
directory = await setupTmpDir("ninja")
1515
})
1616

1717
it("should setup Ninja", async () => {

src/ninja/ninja.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { extractZip } from "@actions/tool-cache"
2+
import { addBinExtension } from "../utils/extension/extension"
23
import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin"
34

45
/** Get the platform name Ninja uses in their download links */
@@ -20,6 +21,7 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag
2021
const ninjaPlatform = getNinjaPlatform(platform)
2122
return {
2223
binRelativeDir: "",
24+
binFileName: addBinExtension("ninja"),
2325
extractedFolderName: "",
2426
extractFunction: extractZip,
2527
url: `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${ninjaPlatform}.zip`,

src/utils/setup/setupBin.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export type PackageInfo = {
1414
extractedFolderName: string
1515
/** The relative directory in which the binary is located. It can be `""` if the exe is in the top folder */
1616
binRelativeDir: string
17+
/** The main binary file. */
18+
binFileName: string
1719
/** The function to extract the downloaded archive. It can be `undefined`, if the binary itself is downloaded directly. */
1820
extractFunction?: {
1921
(file: string, dest: string): Promise<string> | Promise<void>
@@ -42,36 +44,42 @@ export async function setupBin(
4244
setupDir: string
4345
): Promise<InstallationInfo> {
4446
process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir()
45-
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(tmpdir(), "setup_cpp", "ToolCache")
47+
process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(tmpdir(), "setup-cpp", "ToolCache")
4648

47-
const { url, binRelativeDir, extractedFolderName, extractFunction } = await getPackageInfo(version, process.platform)
49+
const { url, binRelativeDir, binFileName, extractedFolderName, extractFunction } = await getPackageInfo(
50+
version,
51+
process.platform
52+
)
4853

4954
// Restore from cache (if found).
5055
if (isCI()) {
5156
try {
5257
const dir = find(name, version)
5358
if (dir) {
54-
info(`${name} ${version} was found in the cache.`)
5559
const installDir = join(dir, extractedFolderName)
5660
const binDir = join(installDir, binRelativeDir)
57-
addPath(binDir)
58-
return { installDir, binDir }
61+
if (existsSync(binDir) && existsSync(join(binRelativeDir, binFileName))) {
62+
info(`${name} ${version} was found in the cache.`)
63+
addPath(binDir)
64+
return { installDir, binDir }
65+
}
5966
}
6067
} catch {
6168
// fails on a local machine?
6269
}
6370
}
6471

72+
const installDir = join(setupDir, extractedFolderName)
73+
const binDir = join(installDir, binRelativeDir)
74+
const binFile = join(binDir, binFileName)
75+
6576
// download ane extract the package into the installation directory.
66-
if (!existsSync(setupDir)) {
77+
if (!existsSync(binDir) || !existsSync(binFile)) {
6778
info(`Download and extract ${name} ${version}`)
6879
const downloaded = await downloadTool(url)
6980
await extractFunction?.(downloaded, setupDir)
7081
}
7182

72-
const installDir = join(setupDir, extractedFolderName)
73-
const binDir = join(installDir, binRelativeDir)
74-
7583
// Adding the bin dir to the path
7684
/** The directory which the tool is installed to */
7785
info(`Add ${binDir} to PATH`)

src/vcpkg/__tests__/vcpkg.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import { setupVcpkg } from "../vcpkg"
2-
import { testBin } from "../../utils/tests/test-helpers"
2+
import { testBin, setupTmpDir } from "../../utils/tests/test-helpers"
33

44
jest.setTimeout(300000)
5-
async function testvcpkg() {
6-
const { binDir } = await setupVcpkg("", "", "")
5+
async function testvcpkg(directory: string) {
6+
const { binDir } = await setupVcpkg("", directory, "")
77
await testBin("vcpkg", ["--version"], binDir)
88
return binDir
99
}
1010

1111
describe("setup-vcpkg", () => {
12+
let directory: string
13+
beforeAll(async () => {
14+
directory = await setupTmpDir("vcpkg")
15+
})
16+
1217
it("should setup vcpkg", async () => {
13-
await testvcpkg()
18+
await testvcpkg(directory)
1419
})
1520
})

src/vcpkg/vcpkg.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { addPath } from "@actions/core"
1+
import { addPath, warning } from "@actions/core"
22
import execa from "execa"
3-
import path, { dirname } from "path"
3+
import { existsSync } from "fs"
4+
import { dirname, join } from "path"
45
import which from "which"
56
import { addShellExtension, addShellHere } from "../utils/extension/extension"
67
import { InstallationInfo } from "../utils/setup/setupBin"
@@ -10,12 +11,16 @@ let hasVCPKG = false
1011
// eslint-disable-next-line @typescript-eslint/no-unused-vars
1112
export function setupVcpkg(_version: string, setupDir: string, _arch: string): InstallationInfo {
1213
if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) {
13-
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
14+
if (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) {
15+
execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) })
16+
} else {
17+
warning(`Vcpkg folder already exists at ${setupDir}`)
18+
}
1419
execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true })
1520
addPath(setupDir)
1621
hasVCPKG = true
1722
return { binDir: setupDir }
1823
}
1924

20-
return { binDir: path.dirname(which.sync("vcpkg")) }
25+
return { binDir: dirname(which.sync("vcpkg")) }
2126
}

0 commit comments

Comments
 (0)