fix: fix setup bin by using folderName

This commit is contained in:
Amin Yahyaabadi 2021-09-14 04:23:38 -05:00
parent ae8703687a
commit 1b87c26a89
2 changed files with 18 additions and 18 deletions

View File

@ -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<string> {
return setupBin("cmake", version, getCmakePlatformData)
return setupBin("cmake", version, getCmakePackageInfo)
}

View File

@ -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<string>
}
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<string> {
// 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 () => {