diff --git a/README.md b/README.md index d77fc60c..f3d85b19 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,9 @@ The package will be usable from any environment (locally, GitHub Actions, etc). - [x] setup cmake - [x] setup ninja - [x] setup llvm +- [x] setup conan - [ ] setup gcc/mingw - [ ] setup msvc -- [ ] setup conan - [ ] setup meson - [ ] setup vcpkg - [ ] setup gcovr diff --git a/action.yml b/action.yml index 2dceee2e..db8c4ce3 100644 --- a/action.yml +++ b/action.yml @@ -16,7 +16,10 @@ inputs: ninja: description: "The ninja version to install." default: "1.10.2" - required: true + required: false + conan: + description: "The concan version to install." + required: false runs: using: "node12" diff --git a/src/conan/__tests__/conan.test.ts b/src/conan/__tests__/conan.test.ts new file mode 100644 index 00000000..88e5b1e2 --- /dev/null +++ b/src/conan/__tests__/conan.test.ts @@ -0,0 +1,15 @@ +import { setupConan } from "../conan" +import { spawnSync as spawn } from "child_process" + +jest.setTimeout(100000) + +describe("setup-conan", () => { + it("should setup conan", async () => { + await setupConan("1.40.1") + + const { status } = spawn("conan", ["--version"], { + encoding: "utf8", + }) + expect(status).toBe(0) + }) +}) diff --git a/src/conan/conan.ts b/src/conan/conan.ts new file mode 100644 index 00000000..03e8ffda --- /dev/null +++ b/src/conan/conan.ts @@ -0,0 +1,15 @@ +import { setupPip } from "../utils/setup/setupPip" +import { addPath, startGroup, endGroup } from "@actions/core" + +export async function setupConan(version?: string) { + await setupPip("conan", version) + + if (process.platform === "linux") { + try { + startGroup(`Add /home/runner/.local/bin to PATH`) + addPath("/home/runner/.local/bin/") + } finally { + endGroup() + } + } +} diff --git a/src/main.ts b/src/main.ts index 5e8a6c02..86396bde 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import * as core from "@actions/core" import { setupCmake } from "./cmake/cmake" +import { setupConan } from "./conan/conan" import { setupLLVM } from "./llvm/llvm" import { setupNinja } from "./ninja/ninja" @@ -26,6 +27,12 @@ export async function main(): Promise { await setupNinja(ninjaVersion, setupCppDir) } + // setup conan + const conanVersion = maybeGetInput("conan") + if (conanVersion !== undefined) { + await setupConan(conanVersion) + } + // setup llvm const llvmVersion = maybeGetInput("llvm") if (llvmVersion !== undefined) { diff --git a/src/utils/setup/setupPip.ts b/src/utils/setup/setupPip.ts new file mode 100644 index 00000000..daf9eeef --- /dev/null +++ b/src/utils/setup/setupPip.ts @@ -0,0 +1,11 @@ +import { exec } from "@actions/exec" + +/** A function that installs a package using pip */ +export async function setupPip(name: string, version?: string) { + // pip3 install conan --upgrade + + const exit = await exec("pip", ["install", "--user", version !== undefined ? `${name}==${version}` : name]) + if (exit !== 0) { + throw new Error(`Failed to install ${name} ${version}`) + } +}