mirror of https://github.com/aminya/setup-cpp
fix: fix setup bin by using folderName
This commit is contained in:
parent
ae8703687a
commit
1b87c26a89
|
@ -2,10 +2,10 @@ import { extractZip, extractTar } from "@actions/tool-cache"
|
||||||
import { getInput } from "@actions/core"
|
import { getInput } from "@actions/core"
|
||||||
import semverLte from "semver/functions/lte"
|
import semverLte from "semver/functions/lte"
|
||||||
import semverCoerce from "semver/functions/coerce"
|
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 */
|
/** 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 semVersion = semverCoerce(version) ?? version
|
||||||
const platformStr = platform ?? process.platform
|
const platformStr = platform ?? process.platform
|
||||||
const arch = getInput("architecture") || process.arch
|
const arch = getInput("architecture") || process.arch
|
||||||
|
@ -18,21 +18,23 @@ function getCmakePlatformData(version: string, platform?: NodeJS.Platform): Pack
|
||||||
} else {
|
} else {
|
||||||
osArchStr = isOld ? "win64-x64" : "windows-x86_64"
|
osArchStr = isOld ? "win64-x64" : "windows-x86_64"
|
||||||
}
|
}
|
||||||
|
const folderName = `cmake-${version}-${osArchStr}`
|
||||||
return {
|
return {
|
||||||
binRelativeDir: "bin/",
|
binRelativeDir: "bin/",
|
||||||
dropSuffix: ".zip",
|
extractedFolderName: folderName,
|
||||||
extractFunction: extractZip,
|
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": {
|
case "darwin": {
|
||||||
const isOld = semverLte(semVersion, "v3.19.1")
|
const isOld = semverLte(semVersion, "v3.19.1")
|
||||||
const osArchStr = isOld ? "Darwin-x86_64" : "macos-universal"
|
const osArchStr = isOld ? "Darwin-x86_64" : "macos-universal"
|
||||||
|
const folderName = `cmake-${version}-${osArchStr}`
|
||||||
return {
|
return {
|
||||||
binRelativeDir: "CMake.app/Contents/bin/",
|
binRelativeDir: "CMake.app/Contents/bin/",
|
||||||
dropSuffix: ".tar.gz",
|
extractedFolderName: folderName,
|
||||||
extractFunction: extractTar,
|
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": {
|
case "linux": {
|
||||||
|
@ -43,11 +45,12 @@ function getCmakePlatformData(version: string, platform?: NodeJS.Platform): Pack
|
||||||
} else {
|
} else {
|
||||||
osArchStr = isOld ? "Linux-x86_64" : "linux-x86_64"
|
osArchStr = isOld ? "Linux-x86_64" : "linux-x86_64"
|
||||||
}
|
}
|
||||||
|
const folderName = `cmake-${version}-${osArchStr}`
|
||||||
return {
|
return {
|
||||||
binRelativeDir: "bin/",
|
binRelativeDir: "bin/",
|
||||||
dropSuffix: ".tar.gz",
|
extractedFolderName: ".tar.gz",
|
||||||
extractFunction: extractTar,
|
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:
|
default:
|
||||||
|
@ -57,5 +60,5 @@ function getCmakePlatformData(version: string, platform?: NodeJS.Platform): Pack
|
||||||
|
|
||||||
/** Setup cmake */
|
/** Setup cmake */
|
||||||
export function setupCmake(version: string): Promise<string> {
|
export function setupCmake(version: string): Promise<string> {
|
||||||
return setupBin("cmake", version, getCmakePlatformData)
|
return setupBin("cmake", version, getCmakePackageInfo)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,25 @@
|
||||||
import { find, downloadTool, cacheDir } from "@actions/tool-cache"
|
import { find, downloadTool, cacheDir } from "@actions/tool-cache"
|
||||||
import { addPath, group, startGroup, endGroup } from "@actions/core"
|
import { addPath, group, startGroup, endGroup } from "@actions/core"
|
||||||
import { join, basename } from "path"
|
import { join } from "path"
|
||||||
import { existsSync } from "fs"
|
import { existsSync } from "fs"
|
||||||
import * as hasha from "hasha"
|
import * as hasha from "hasha"
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
import { URL } from "url"
|
|
||||||
|
|
||||||
export type PackageInfo = {
|
export type PackageInfo = {
|
||||||
url: string
|
url: string
|
||||||
binRelativeDir: string
|
binRelativeDir: string
|
||||||
|
/** The top folder name once it is extracted */
|
||||||
|
extractedFolderName: string
|
||||||
extractFunction: {
|
extractFunction: {
|
||||||
(url: string, outputPath: string): Promise<string>
|
(url: string, outputPath: string): Promise<string>
|
||||||
}
|
}
|
||||||
dropSuffix: string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A function that downloads and installs a tool. Then it caches it in the tool-cache. */
|
/** A function that downloads and installs a tool. Then it caches it in the tool-cache. */
|
||||||
export async function setupBin(
|
export async function setupBin(
|
||||||
name: string,
|
name: string,
|
||||||
version: string,
|
version: string,
|
||||||
getPlatformData: (version: string, platform: NodeJS.Platform) => PackageInfo
|
getPackageInfo: (version: string, platform: NodeJS.Platform) => PackageInfo
|
||||||
): Promise<string> {
|
): Promise<string> {
|
||||||
// Build artifact name
|
// Build artifact name
|
||||||
const binName = process.platform === "win32" ? `${name}.exe` : name
|
const binName = process.platform === "win32" ? `${name}.exe` : name
|
||||||
|
@ -31,17 +31,14 @@ export async function setupBin(
|
||||||
return join(dir, binName)
|
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.
|
// Get an unique output directory name from the URL.
|
||||||
const key: string = await hasha.async(url)
|
const key: string = await hasha.async(url)
|
||||||
const workDir = join(process.env.RUNNER_TEMP ?? tmpdir(), key)
|
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 */
|
/** 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)) {
|
if (!existsSync(workDir)) {
|
||||||
await group(`Download and extract ${name}`, async () => {
|
await group(`Download and extract ${name}`, async () => {
|
Loading…
Reference in New Issue