Skip to content

Commit

Permalink
move gcovr.check to deps
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Jan 27, 2023
1 parent 3575f33 commit b93f894
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 54 deletions.
60 changes: 32 additions & 28 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.

33 changes: 27 additions & 6 deletions src/deps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as io from "@actions/io";
import * as os from "os";
import * as action from "./action";

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

Expand All @@ -24,6 +25,10 @@ async function brewInstall(pkg: string) {
await exec.exec("brew", ["install", pkg]);
}

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

async function smartInstall(pkg: string) {
switch (os.type()) {
case "Windows_NT":
Expand All @@ -40,11 +45,27 @@ async function smartInstall(pkg: string) {
}
}

export async function checkLlvm() {
const available = await isAvailable("llvm-cov");
if (!available) {
async function checkGcovr() {
if (await isMissing("llvm-cov")) {
await core.group("Install gcovr", async () => {
await pipInstall("gcovr");
});
}
}

async function checkLlvm() {
if (await isMissing("llvm-cov")) {
await core.group("Install LLVM", async () => {
await smartInstall("llvm");
});
}
}

export async function check(inputs: action.Inputs) {
await checkGcovr();
if (inputs.gcovExecutable !== null) {
if (inputs.gcovExecutable.includes("llvm-cov")) {
await checkLlvm();
}
}
}
12 changes: 0 additions & 12 deletions src/gcovr.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as io from "@actions/io";
import * as action from "./action";

export async function check() {
try {
await io.which("gcovr", true);
} catch {
// gcovr is not available, installing
await core.group("Install gcovr", async () => {
await exec.exec("pip3 install gcovr");
});
}
}

function getArgs(inputs: action.Inputs): string[] {
let args: string[] = [];
if (inputs.root !== null) {
Expand Down
8 changes: 1 addition & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ 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")
) {
await deps.checkLlvm();
}
await deps.check(inputs);
await gcovr.run(inputs);
} catch (error) {
if (error instanceof Error) core.setFailed(error.message);
Expand Down

0 comments on commit b93f894

Please sign in to comment.