diff --git a/src/cmake/__tests__/cmake.test.ts b/src/cmake/__tests__/cmake.test.ts index b305dbe8..1db2b42b 100644 --- a/src/cmake/__tests__/cmake.test.ts +++ b/src/cmake/__tests__/cmake.test.ts @@ -6,7 +6,7 @@ jest.setTimeout(300000) describe("setup-cmake", () => { let directory: string beforeAll(async () => { - directory = await setupTmpDir("setup-cmake") + directory = await setupTmpDir("cmake") }) it("should setup CMake", async () => { @@ -21,6 +21,6 @@ describe("setup-cmake", () => { }) afterAll(async () => { - await cleanupTmpDir("setup-cmake") + await cleanupTmpDir("cmake") }, 100000) }) diff --git a/src/cmake/cmake.ts b/src/cmake/cmake.ts index 4ddd8716..d9599609 100644 --- a/src/cmake/cmake.ts +++ b/src/cmake/cmake.ts @@ -3,6 +3,7 @@ import { getInput } from "@actions/core" import semverLte from "semver/functions/lte" import semverCoerce from "semver/functions/coerce" import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin" +import { addBinExtension } from "../utils/extension/extension" /** Get the platform data for cmake */ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): PackageInfo { @@ -21,6 +22,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa const folderName = `cmake-${version}-${osArchStr}` return { binRelativeDir: "bin/", + binFileName: addBinExtension("cmake"), extractedFolderName: folderName, extractFunction: extractZip, url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.zip`, @@ -32,6 +34,7 @@ function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): Packa const folderName = `cmake-${version}-${osArchStr}` return { binRelativeDir: "CMake.app/Contents/bin/", + binFileName: addBinExtension("cmake"), extractedFolderName: folderName, extractFunction: extractTar, 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 const folderName = `cmake-${version}-${osArchStr}` return { binRelativeDir: "bin/", + binFileName: addBinExtension("cmake"), extractedFolderName: folderName, extractFunction: extractTar, url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`, diff --git a/src/llvm/__tests__/llvm.test.ts b/src/llvm/__tests__/llvm.test.ts index 2bec0936..613814cc 100644 --- a/src/llvm/__tests__/llvm.test.ts +++ b/src/llvm/__tests__/llvm.test.ts @@ -15,7 +15,7 @@ async function testUrl(version: string) { describe("setup-llvm", () => { let directory: string beforeAll(async () => { - directory = await setupTmpDir("setup-llvm") + directory = await setupTmpDir("llvm") }) it("Finds valid LLVM URLs", async () => { diff --git a/src/llvm/llvm.ts b/src/llvm/llvm.ts index d8803619..afbfa791 100644 --- a/src/llvm/llvm.ts +++ b/src/llvm/llvm.ts @@ -7,6 +7,7 @@ import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin import { extractExe, extractTarByExe } from "../utils/setup/extract" import { getSpecificVersionAndUrl, getVersions } from "../utils/setup/version" import { setupMacOSSDK } from "../macos-sdk/macos-sdk" +import { addBinExtension } from "../utils/extension/extension" //================================================ // Version @@ -227,6 +228,7 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform): P url, extractedFolderName: "", binRelativeDir: "bin", + binFileName: addBinExtension("clang"), extractFunction: platform === "win32" ? extractExe : extractTarByExe, } } diff --git a/src/ninja/__tests__/ninja.test.ts b/src/ninja/__tests__/ninja.test.ts index e6ac30d7..65218e2e 100644 --- a/src/ninja/__tests__/ninja.test.ts +++ b/src/ninja/__tests__/ninja.test.ts @@ -11,7 +11,7 @@ async function testNinja(directory: string) { describe("setup-ninja", () => { let directory: string beforeEach(async () => { - directory = await setupTmpDir("setup-ninja") + directory = await setupTmpDir("ninja") }) it("should setup Ninja", async () => { diff --git a/src/ninja/ninja.ts b/src/ninja/ninja.ts index 3fa4b175..ca533602 100644 --- a/src/ninja/ninja.ts +++ b/src/ninja/ninja.ts @@ -1,4 +1,5 @@ import { extractZip } from "@actions/tool-cache" +import { addBinExtension } from "../utils/extension/extension" import { setupBin, PackageInfo, InstallationInfo } from "../utils/setup/setupBin" /** Get the platform name Ninja uses in their download links */ @@ -20,6 +21,7 @@ function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): Packag const ninjaPlatform = getNinjaPlatform(platform) return { binRelativeDir: "", + binFileName: addBinExtension("ninja"), extractedFolderName: "", extractFunction: extractZip, url: `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${ninjaPlatform}.zip`, diff --git a/src/utils/setup/setupBin.ts b/src/utils/setup/setupBin.ts index 4fb10fbc..a1f9c910 100644 --- a/src/utils/setup/setupBin.ts +++ b/src/utils/setup/setupBin.ts @@ -14,6 +14,8 @@ export type PackageInfo = { extractedFolderName: string /** The relative directory in which the binary is located. It can be `""` if the exe is in the top folder */ binRelativeDir: string + /** The main binary file. */ + binFileName: string /** The function to extract the downloaded archive. It can be `undefined`, if the binary itself is downloaded directly. */ extractFunction?: { (file: string, dest: string): Promise | Promise @@ -42,36 +44,42 @@ export async function setupBin( setupDir: string ): Promise { process.env.RUNNER_TEMP = process.env.RUNNER_TEMP ?? tmpdir() - process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(tmpdir(), "setup_cpp", "ToolCache") + process.env.RUNNER_TOOL_CACHE = process.env.RUNNER_TOOL_CACH ?? join(tmpdir(), "setup-cpp", "ToolCache") - const { url, binRelativeDir, extractedFolderName, extractFunction } = await getPackageInfo(version, process.platform) + const { url, binRelativeDir, binFileName, extractedFolderName, extractFunction } = await getPackageInfo( + version, + process.platform + ) // Restore from cache (if found). if (isCI()) { try { const dir = find(name, version) if (dir) { - info(`${name} ${version} was found in the cache.`) const installDir = join(dir, extractedFolderName) const binDir = join(installDir, binRelativeDir) - addPath(binDir) - return { installDir, binDir } + if (existsSync(binDir) && existsSync(join(binRelativeDir, binFileName))) { + info(`${name} ${version} was found in the cache.`) + addPath(binDir) + return { installDir, binDir } + } } } catch { // fails on a local machine? } } + const installDir = join(setupDir, extractedFolderName) + const binDir = join(installDir, binRelativeDir) + const binFile = join(binDir, binFileName) + // download ane extract the package into the installation directory. - if (!existsSync(setupDir)) { + if (!existsSync(binDir) || !existsSync(binFile)) { info(`Download and extract ${name} ${version}`) const downloaded = await downloadTool(url) await extractFunction?.(downloaded, setupDir) } - const installDir = join(setupDir, extractedFolderName) - const binDir = join(installDir, binRelativeDir) - // Adding the bin dir to the path /** The directory which the tool is installed to */ info(`Add ${binDir} to PATH`) diff --git a/src/vcpkg/__tests__/vcpkg.test.ts b/src/vcpkg/__tests__/vcpkg.test.ts index 4e2c9bd7..53129400 100644 --- a/src/vcpkg/__tests__/vcpkg.test.ts +++ b/src/vcpkg/__tests__/vcpkg.test.ts @@ -1,15 +1,20 @@ import { setupVcpkg } from "../vcpkg" -import { testBin } from "../../utils/tests/test-helpers" +import { testBin, setupTmpDir } from "../../utils/tests/test-helpers" jest.setTimeout(300000) -async function testvcpkg() { - const { binDir } = await setupVcpkg("", "", "") +async function testvcpkg(directory: string) { + const { binDir } = await setupVcpkg("", directory, "") await testBin("vcpkg", ["--version"], binDir) return binDir } describe("setup-vcpkg", () => { + let directory: string + beforeAll(async () => { + directory = await setupTmpDir("vcpkg") + }) + it("should setup vcpkg", async () => { - await testvcpkg() + await testvcpkg(directory) }) }) diff --git a/src/vcpkg/vcpkg.ts b/src/vcpkg/vcpkg.ts index 7b56fca8..f3a6222b 100644 --- a/src/vcpkg/vcpkg.ts +++ b/src/vcpkg/vcpkg.ts @@ -1,6 +1,7 @@ -import { addPath } from "@actions/core" +import { addPath, warning } from "@actions/core" import execa from "execa" -import path, { dirname } from "path" +import { existsSync } from "fs" +import { dirname, join } from "path" import which from "which" import { addShellExtension, addShellHere } from "../utils/extension/extension" import { InstallationInfo } from "../utils/setup/setupBin" @@ -10,12 +11,16 @@ let hasVCPKG = false // eslint-disable-next-line @typescript-eslint/no-unused-vars export function setupVcpkg(_version: string, setupDir: string, _arch: string): InstallationInfo { if (!hasVCPKG || which.sync("vcpkg", { nothrow: true }) === null) { - execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) }) + if (!existsSync(join(setupDir, addShellExtension("bootstrap-vcpkg")))) { + execa.sync("git", ["clone", "https://github.com/microsoft/vcpkg"], { cwd: dirname(setupDir) }) + } else { + warning(`Vcpkg folder already exists at ${setupDir}`) + } execa.sync(addShellExtension(addShellHere("bootstrap-vcpkg")), { cwd: setupDir, shell: true }) addPath(setupDir) hasVCPKG = true return { binDir: setupDir } } - return { binDir: path.dirname(which.sync("vcpkg")) } + return { binDir: dirname(which.sync("vcpkg")) } }