From 1b87c26a89a77b7417a62ad15e6ca750fbf35824 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 14 Sep 2021 04:23:38 -0500 Subject: [PATCH] fix: fix setup bin by using folderName --- src/cmake/cmake.ts | 21 ++++++++++++--------- src/utils/setup/{setup.ts => setupBin.ts} | 15 ++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) rename src/utils/setup/{setup.ts => setupBin.ts} (75%) diff --git a/src/cmake/cmake.ts b/src/cmake/cmake.ts index c4301df7..5433a701 100644 --- a/src/cmake/cmake.ts +++ b/src/cmake/cmake.ts @@ -2,10 +2,10 @@ import { extractZip, extractTar } from "@actions/tool-cache" import { getInput } from "@actions/core" import semverLte from "semver/functions/lte" import semverCoerce from "semver/functions/coerce" -import { setupBin, PackageInfo } from "../utils/setup/setup" +import { setupBin, PackageInfo } from "../utils/setup/setupBin" /** Get the platform data for cmake */ -function getCmakePlatformData(version: string, platform?: NodeJS.Platform): PackageInfo { +function getCmakePackageInfo(version: string, platform?: NodeJS.Platform): PackageInfo { const semVersion = semverCoerce(version) ?? version const platformStr = platform ?? process.platform const arch = getInput("architecture") || process.arch @@ -18,21 +18,23 @@ function getCmakePlatformData(version: string, platform?: NodeJS.Platform): Pack } else { osArchStr = isOld ? "win64-x64" : "windows-x86_64" } + const folderName = `cmake-${version}-${osArchStr}` return { binRelativeDir: "bin/", - dropSuffix: ".zip", + extractedFolderName: folderName, extractFunction: extractZip, - url: `https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-${osArchStr}.zip`, + url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.zip`, } } case "darwin": { const isOld = semverLte(semVersion, "v3.19.1") const osArchStr = isOld ? "Darwin-x86_64" : "macos-universal" + const folderName = `cmake-${version}-${osArchStr}` return { binRelativeDir: "CMake.app/Contents/bin/", - dropSuffix: ".tar.gz", + extractedFolderName: folderName, extractFunction: extractTar, - url: `https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-${osArchStr}.tar.gz`, + url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`, } } case "linux": { @@ -43,11 +45,12 @@ function getCmakePlatformData(version: string, platform?: NodeJS.Platform): Pack } else { osArchStr = isOld ? "Linux-x86_64" : "linux-x86_64" } + const folderName = `cmake-${version}-${osArchStr}` return { binRelativeDir: "bin/", - dropSuffix: ".tar.gz", + extractedFolderName: ".tar.gz", extractFunction: extractTar, - url: `https://github.com/Kitware/CMake/releases/download/v${version}/cmake-${version}-${osArchStr}.tar.gz`, + url: `https://github.com/Kitware/CMake/releases/download/v${version}/${folderName}.tar.gz`, } } default: @@ -57,5 +60,5 @@ function getCmakePlatformData(version: string, platform?: NodeJS.Platform): Pack /** Setup cmake */ export function setupCmake(version: string): Promise { - return setupBin("cmake", version, getCmakePlatformData) + return setupBin("cmake", version, getCmakePackageInfo) } diff --git a/src/utils/setup/setup.ts b/src/utils/setup/setupBin.ts similarity index 75% rename from src/utils/setup/setup.ts rename to src/utils/setup/setupBin.ts index dc3341c5..27dc451e 100644 --- a/src/utils/setup/setup.ts +++ b/src/utils/setup/setupBin.ts @@ -1,25 +1,25 @@ import { find, downloadTool, cacheDir } from "@actions/tool-cache" import { addPath, group, startGroup, endGroup } from "@actions/core" -import { join, basename } from "path" +import { join } from "path" import { existsSync } from "fs" import * as hasha from "hasha" import { tmpdir } from "os" -import { URL } from "url" export type PackageInfo = { url: string binRelativeDir: string + /** The top folder name once it is extracted */ + extractedFolderName: string extractFunction: { (url: string, outputPath: string): Promise } - dropSuffix: string } /** A function that downloads and installs a tool. Then it caches it in the tool-cache. */ export async function setupBin( name: string, version: string, - getPlatformData: (version: string, platform: NodeJS.Platform) => PackageInfo + getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo ): Promise { // Build artifact name const binName = process.platform === "win32" ? `${name}.exe` : name @@ -31,17 +31,14 @@ export async function setupBin( return join(dir, binName) } - const { url, dropSuffix, binRelativeDir: binRelativePath, extractFunction } = getPlatformData(version, process.platform) + const { url, binRelativeDir, extractedFolderName, extractFunction } = getPackageInfo(version, process.platform) // Get an unique output directory name from the URL. const key: string = await hasha.async(url) const workDir = join(process.env.RUNNER_TEMP ?? tmpdir(), key) - const { pathname } = new URL(url) - const dirName = basename(pathname) - /** The directory which the tool is installed to */ - const binDir = join(workDir, dirName.replace(dropSuffix, ""), binRelativePath) + const binDir = join(workDir, extractedFolderName, binRelativeDir) if (!existsSync(workDir)) { await group(`Download and extract ${name}`, async () => {