Skip to content

Commit

Permalink
Install grcov from releases
Browse files Browse the repository at this point in the history
Rebased version of actions-rs#81.
  • Loading branch information
macisamuele authored and rraval committed Jan 10, 2022
1 parent 6838d22 commit a13193f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

67 changes: 60 additions & 7 deletions src/grcov.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as core from '@actions/core';
import * as io from '@actions/io';
import * as exec from '@actions/exec';
import {Cargo} from '@actions-rs/core';
const { Octokit } = require("@octokit/action");
const tc = require('@actions/tool-cache');

import * as configuration from './configuration';

Expand All @@ -15,29 +17,80 @@ export class Grcov {
this.path = path;
}

public static async get(): Promise<Grcov> {
static async install(): Promise<void> {
try {
const path = await io.which('grcov', true);

return new Grcov(path);
core.startGroup('Install grcov (from releases)');
if (process.env.GITHUB_TOKEN === undefined) {
core.warning("Define GITHUB_TOKEN into the step environment to have access to the published releases. Adding `env: { GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} }` to your step is usually enough")
throw "env.GITHUB_TOKEN not defined";
}
const data = await new Octokit().graphql(`
{
repository(owner: "mozilla", name: "grcov") {
releases(last: 1) {
edges {
node {
releaseAssets(name: "grcov-linux-x86_64.tar.bz2", last: 1) {
edges {
node {
downloadUrl,
release {
tagName
}
}
}
}
}
}
}
}
}
`);
const tagName = data.repository.releases.edges[0].node.releaseAssets.edges[0].node.release.tagName;
const downloadUrl = data.repository.releases.edges[0].node.releaseAssets.edges[0].node.downloadUrl;
core.info("Installing grcov (" + tagName + ") from " + downloadUrl);
const grcovTarBz2Path = await tc.downloadTool(downloadUrl);
const grcovTarBz2ExtractedFolder = await tc.extractTar(grcovTarBz2Path, process.env.RUNNER_TEMP, "xj");
core.addPath(grcovTarBz2ExtractedFolder);
return ;
} catch (error) {
core.info('grcov is not installed, installing now');
console.log(error);
core.error(error);
} finally {
core.endGroup();
}

const cargo = await Cargo.get();
try {
core.startGroup('Install grcov');
core.startGroup('Install grcov (from sources)');
await cargo.call(['install', 'grcov']);
} catch (error) {
throw error;
} finally {
core.endGroup();
}
}

public static async get(): Promise<Grcov> {
try {
const path = await io.which('grcov', true);

return new Grcov(path);
} catch (error) {
core.info('grcov is not installed, installing now');
}

await Grcov.install();

// Expecting it to be in PATH already
return new Grcov('grcov');
const grcovInstance = new Grcov('grcov');

await exec.exec(grcovInstance.path, ['--version']);

return grcovInstance;
}


public async call(config: configuration.Config, archive: string): Promise<string> {
const postfix = Math.random().toString(36).substring(2, 15)
const reportPath = config.user.outputPath ? path.resolve(config.user.outputPath) : path.join(os.tmpdir(), `grcov-report-${postfix}`);
Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async function run() {
}

const exe = await grcov.Grcov.get();
console.log(exe);
const outputPath = await exe.call(config, coverageArchive);

core.setOutput('report', outputPath);
Expand Down

0 comments on commit a13193f

Please sign in to comment.