Skip to content

Commit

Permalink
check and auto-install if llvm-cov is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jan 27, 2023
1 parent 868bb4f commit a5de9da
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 1 deletion.
106 changes: 106 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

50 changes: 50 additions & 0 deletions src/deps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as io from "@actions/io";
import * as os from "os";

async function isAvailable(tool: string): Promise<boolean> {
try {
await io.which(tool, true);
return true;
} catch {
return false;
}
}

async function chocoInstall(pkg: string) {
await exec.exec("choco", ["install", "-y", pkg]);
}

async function aptInstall(pkg: string) {
await exec.exec("sudo", ["apt-get", "install", "-y", pkg]);
}

async function brewInstall(pkg: string) {
await exec.exec("brew", ["install", pkg]);
}

async function smartInstall(pkg: string) {
switch (os.type()) {
case "Windows_NT":
chocoInstall(pkg);
break;
case "Linux":
aptInstall(pkg);
break;
case "Darwin":
brewInstall(pkg);
break;
default:
throw new Error(`unknown OS type: ${os.type()}`);
}
}

export async function checkLlvm() {
const available = await isAvailable("llvm-cov");
if (!available) {
await core.group("Install LLVM", async () => {
await smartInstall("llvm");
});
}
}
7 changes: 7 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import * as core from "@actions/core";
import * as action from "./action";
import * as deps from "./deps";
import * as gcovr from "./gcovr";

async function run(): Promise<void> {
try {
const inputs = action.parseInputs();
await gcovr.check();
if (
inputs.gcovExecutable !== null &&
inputs.gcovExecutable.includes("llvm-cov")
) {
deps.checkLlvm();
}
await gcovr.run(inputs);
} catch (error) {
if (error instanceof Error) core.setFailed(error.message);
Expand Down

0 comments on commit a5de9da

Please sign in to comment.