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", () => {
|
describe("setup-ninja", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
await setupTmpDir("setup-cmake")
|
await setupTmpDir("setup-ninja")
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await cleanupTmpDir("setup-cmake")
|
await cleanupTmpDir("setup-ninja")
|
||||||
}, 100000)
|
}, 100000)
|
||||||
|
|
||||||
it("should setup Ninja", async () => {
|
it("should setup Ninja", async () => {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
import { extractZip, find, downloadTool, cacheFile } from "@actions/tool-cache"
|
import { extractZip } from "@actions/tool-cache"
|
||||||
import { addPath, group, startGroup, endGroup } from "@actions/core"
|
import { setupBin, PackageInfo } from "../utils/setup/setupBin"
|
||||||
import { join } from "path"
|
|
||||||
import { existsSync } from "fs"
|
|
||||||
import * as hasha from "hasha"
|
|
||||||
import { tmpdir } from "os"
|
|
||||||
|
|
||||||
/** Get the platform name Ninja uses in their download links */
|
/** Get the platform name Ninja uses in their download links */
|
||||||
function getNinjaPlatform(platform: NodeJS.Platform) {
|
function getNinjaPlatform(platform: NodeJS.Platform) {
|
||||||
|
@ -19,42 +15,17 @@ function getNinjaPlatform(platform: NodeJS.Platform) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setupNinja(version: string): Promise<string> {
|
/** Get the platform data for ninja */
|
||||||
const platform = getNinjaPlatform(process.platform)
|
function getNinjaPackageInfo(version: string, platform: NodeJS.Platform): PackageInfo {
|
||||||
|
const ninjaPlatform = getNinjaPlatform(platform)
|
||||||
// Build artifact name
|
return {
|
||||||
const ninjaBin = platform === "win" ? "ninja.exe" : "ninja"
|
binRelativeDir: "",
|
||||||
|
extractedFolderName: "",
|
||||||
// Restore from cache (if found).
|
extractFunction: extractZip,
|
||||||
const ninjaDir = find("ninja", version)
|
url: `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${ninjaPlatform}.zip`,
|
||||||
if (ninjaDir) {
|
}
|
||||||
addPath(ninjaDir)
|
|
||||||
return join(ninjaDir, ninjaBin)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `https://github.com/ninja-build/ninja/releases/download/v${version}/ninja-${platform}.zip`
|
export function setupNinja(version: string): Promise<string> {
|
||||||
|
return setupBin("ninja", version, getNinjaPackageInfo)
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,11 +5,15 @@ import { existsSync } from "fs"
|
||||||
import * as hasha from "hasha"
|
import * as hasha from "hasha"
|
||||||
import { tmpdir } from "os"
|
import { tmpdir } from "os"
|
||||||
|
|
||||||
|
/** A type that describes a package */
|
||||||
export type PackageInfo = {
|
export type PackageInfo = {
|
||||||
|
/** url to download the package */
|
||||||
url: string
|
url: string
|
||||||
binRelativeDir: string
|
/** The top folder name once it is extracted. It can be `""` if there is no top folder */
|
||||||
/** The top folder name once it is extracted */
|
|
||||||
extractedFolderName: string
|
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: {
|
extractFunction: {
|
||||||
(url: string, outputPath: string): Promise<string>
|
(url: string, outputPath: string): Promise<string>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue