mirror of https://github.com/aminya/setup-cpp
fix: use setup bin for ninja
This commit is contained in:
parent
1b87c26a89
commit
e77708aa48
|
@ -6,11 +6,11 @@ jest.setTimeout(30 * 1000)
|
|||
|
||||
describe("setup-ninja", () => {
|
||||
beforeEach(async () => {
|
||||
await setupTmpDir("setup-cmake")
|
||||
await setupTmpDir("setup-ninja")
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
await cleanupTmpDir("setup-cmake")
|
||||
await cleanupTmpDir("setup-ninja")
|
||||
}, 100000)
|
||||
|
||||
it("should setup Ninja", async () => {
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
import { extractZip, find, downloadTool, cacheFile } from "@actions/tool-cache"
|
||||
import { addPath, group, startGroup, endGroup } from "@actions/core"
|
||||
import { join } from "path"
|
||||
import { existsSync } from "fs"
|
||||
import * as hasha from "hasha"
|
||||
import { tmpdir } from "os"
|
||||
import { extractZip } from "@actions/tool-cache"
|
||||
import { setupBin, PackageInfo } from "../utils/setup/setupBin"
|
||||
|
||||
/** Get the platform name Ninja uses in their download links */
|
||||
function getNinjaPlatform(platform: NodeJS.Platform) {
|
||||
|
@ -19,42 +15,17 @@ function getNinjaPlatform(platform: NodeJS.Platform) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function setupNinja(version: string): Promise<string> {
|
||||
const platform = getNinjaPlatform(process.platform)
|
||||
|
||||
// Build artifact name
|
||||
const ninjaBin = platform === "win" ? "ninja.exe" : "ninja"
|
||||
|
||||
// Restore from cache (if found).
|
||||
const ninjaDir = find("ninja", version)
|
||||
if (ninjaDir) {
|
||||
addPath(ninjaDir)
|
||||
return join(ninjaDir, ninjaBin)
|
||||
/** Get the platform data for ninja */
|
||||
function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): PackageInfo {
|
||||
const ninjaPlatform = getNinjaPlatform(platform)
|
||||
return {
|
||||
binRelativeDir: "",
|
||||
extractedFolderName: "",
|
||||
extractFunction: extractZip,
|
||||
url: `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${ninjaPlatform}.zip`,
|
||||
}
|
||||
|
||||
const url = `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${platform}.zip`
|
||||
|
||||
// Get an unique output directory name from the URL.
|
||||
const key: string = await hasha.async(url)
|
||||
const finalDir = join(process.env.RUNNER_TEMP ?? tmpdir(), key)
|
||||
|
||||
const finalBinPath = join(finalDir, ninjaBin)
|
||||
|
||||
if (!existsSync(finalDir)) {
|
||||
await group("Download and extract ninja", async () => {
|
||||
const downloaded = await downloadTool(url)
|
||||
await extractZip(downloaded, finalDir)
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
startGroup("Add ninja to PATH")
|
||||
addPath(finalDir)
|
||||
} finally {
|
||||
endGroup()
|
||||
}
|
||||
|
||||
await cacheFile(finalBinPath, ninjaBin, "ninja", version)
|
||||
|
||||
return finalBinPath
|
||||
}
|
||||
|
||||
export function setupNinja(version: string): Promise<string> {
|
||||
return setupBin("ninja", version, getNinjaPackageInfo)
|
||||
}
|
||||
|
|
|
@ -5,11 +5,15 @@ import { existsSync } from "fs"
|
|||
import * as hasha from "hasha"
|
||||
import { tmpdir } from "os"
|
||||
|
||||
/** A type that describes a package */
|
||||
export type PackageInfo = {
|
||||
/** url to download the package */
|
||||
url: string
|
||||
binRelativeDir: string
|
||||
/** The top folder name once it is extracted */
|
||||
/** The top folder name once it is extracted. It can be `""` if there is no top folder */
|
||||
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 function to extract the downloaded archive */
|
||||
extractFunction: {
|
||||
(url: string, outputPath: string): Promise<string>
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue