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
|
required: false
|
||||||
cmake:
|
cmake:
|
||||||
description: "The cmake version to install."
|
description: "The cmake version to install."
|
||||||
default: '3.20.2'
|
default: "3.20.2"
|
||||||
required: false
|
required: false
|
||||||
ninja:
|
ninja:
|
||||||
description: "The ninja version to install."
|
description: "The ninja version to install."
|
||||||
required: false
|
default: "1.10.2"
|
||||||
|
required: true
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "node12"
|
using: "node12"
|
||||||
|
|
19
src/main.ts
19
src/main.ts
|
@ -1,13 +1,28 @@
|
||||||
import * as core from "@actions/core"
|
import * as core from "@actions/core"
|
||||||
import { setupCmake } from "./cmake/cmake"
|
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> {
|
export async function main(): Promise<number> {
|
||||||
try {
|
try {
|
||||||
// setup cmake
|
// setup cmake
|
||||||
const cmakeVersion = core.getInput("cmake")
|
const cmakeVersion = maybeGetInput("cmake")
|
||||||
if (cmakeVersion !== "false" && cmakeVersion !== "") {
|
if (cmakeVersion !== undefined) {
|
||||||
await setupCmake(cmakeVersion)
|
await setupCmake(cmakeVersion)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// setup ninja
|
||||||
|
const ninjaVersion = maybeGetInput("ninja")
|
||||||
|
if (ninjaVersion !== undefined) {
|
||||||
|
await setupNinja(ninjaVersion)
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.error(err as string | Error)
|
core.error(err as string | Error)
|
||||||
core.setFailed("install-cpp failed")
|
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