Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
feat: Allow install grcov from releases (as faster method that relies…
Browse files Browse the repository at this point in the history
… on GitHub and not 3rd parties)
  • Loading branch information
macisamuele committed Jun 23, 2020
1 parent d9881ad commit 18fae0e
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

117 changes: 117 additions & 0 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"scripts": {
"build": "ncc build src/main.ts --minify",
"watch": "ncc build src/main.ts --watch",
"test": "jest"
"test": "jest --no-watchman"
},
"repository": {
"type": "git",
Expand All @@ -33,7 +33,9 @@
"@actions/core": "^1.2.3",
"@actions/exec": "^1.0.3",
"@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.3.3",
"@iarna/toml": "^2.2.3",
"@octokit/action": "^3.0.0",
"archiver": "^3.1.1",
"fast-glob": "^3.2.2",
"js-yaml": "^3.13.1",
Expand Down
64 changes: 57 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,77 @@ 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)');

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 18fae0e

Please sign in to comment.