mirror of https://github.com/aminya/setup-cpp
feat: add setupNinja
Used some code from https://github.com/aminya/install-cmake/blob/new-versions-and-arch/src/ninja.ts
This commit is contained in:
parent
33a3592a63
commit
0e7542179a
|
@ -11,11 +11,12 @@ inputs:
|
|||
required: false
|
||||
cmake:
|
||||
description: "The cmake version to install."
|
||||
default: '3.20.2'
|
||||
default: "3.20.2"
|
||||
required: false
|
||||
ninja:
|
||||
description: "The ninja version to install."
|
||||
required: false
|
||||
default: "1.10.2"
|
||||
required: true
|
||||
|
||||
runs:
|
||||
using: "node12"
|
||||
|
|
19
src/main.ts
19
src/main.ts
|
@ -1,13 +1,28 @@
|
|||
import * as core from "@actions/core"
|
||||
import { setupCmake } from "./cmake/cmake"
|
||||
import { setupNinja } from "./ninja/ninja"
|
||||
|
||||
function maybeGetInput(key: string) {
|
||||
const value = core.getInput(key)
|
||||
if (value !== "false" && value !== "") {
|
||||
return value
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
export async function main(): Promise<number> {
|
||||
try {
|
||||
// setup cmake
|
||||
const cmakeVersion = core.getInput("cmake")
|
||||
if (cmakeVersion !== "false" && cmakeVersion !== "") {
|
||||
const cmakeVersion = maybeGetInput("cmake")
|
||||
if (cmakeVersion !== undefined) {
|
||||
await setupCmake(cmakeVersion)
|
||||
}
|
||||
|
||||
// setup ninja
|
||||
const ninjaVersion = maybeGetInput("ninja")
|
||||
if (ninjaVersion !== undefined) {
|
||||
await setupNinja(ninjaVersion)
|
||||
}
|
||||
} catch (err) {
|
||||
core.error(err as string | Error)
|
||||
core.setFailed("install-cpp failed")
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
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"
|
||||
|
||||
export async function setupNinja(version: string): Promise<string> {
|
||||
const platform = process.platform
|
||||
|
||||
// Build artifact name
|
||||
const ninjaBin = platform === "win32" ? "ninja.exe" : "ninja"
|
||||
|
||||
// Restore from cache (if found).
|
||||
const ninjaDir = find("ninja", version)
|
||||
if (ninjaDir) {
|
||||
addPath(ninjaDir)
|
||||
return join(ninjaDir, ninjaBin)
|
||||
}
|
||||
|
||||
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 outputDir = join(process.env.RUNNER_TEMP ?? tmpdir(), key)
|
||||
|
||||
const ninjaPath = join(outputDir, ninjaBin)
|
||||
|
||||
if (!existsSync(outputDir)) {
|
||||
await group("Download and extract ninja-build", async () => {
|
||||
const downloaded = await downloadTool(url)
|
||||
await extractZip(downloaded, outputDir)
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
startGroup("Add ninja-build to PATH")
|
||||
addPath(outputDir)
|
||||
} finally {
|
||||
endGroup()
|
||||
}
|
||||
|
||||
await cacheFile(ninjaPath, ninjaBin, "ninja", version)
|
||||
|
||||
return ninjaPath
|
||||
}
|
Loading…
Reference in New Issue