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

Commit 18fae0e

Browse files
committed
feat: Allow install grcov from releases (as faster method that relies on GitHub and not 3rd parties)
1 parent d9881ad commit 18fae0e

File tree

5 files changed

+179
-9
lines changed

5 files changed

+179
-9
lines changed

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 117 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"build": "ncc build src/main.ts --minify",
1313
"watch": "ncc build src/main.ts --watch",
14-
"test": "jest"
14+
"test": "jest --no-watchman"
1515
},
1616
"repository": {
1717
"type": "git",
@@ -33,7 +33,9 @@
3333
"@actions/core": "^1.2.3",
3434
"@actions/exec": "^1.0.3",
3535
"@actions/io": "^1.0.2",
36+
"@actions/tool-cache": "^1.3.3",
3637
"@iarna/toml": "^2.2.3",
38+
"@octokit/action": "^3.0.0",
3739
"archiver": "^3.1.1",
3840
"fast-glob": "^3.2.2",
3941
"js-yaml": "^3.13.1",

src/grcov.ts

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as core from '@actions/core';
55
import * as io from '@actions/io';
66
import * as exec from '@actions/exec';
77
import {Cargo} from '@actions-rs/core';
8+
const { Octokit } = require("@octokit/action");
9+
const tc = require('@actions/tool-cache');
810

911
import * as configuration from './configuration';
1012

@@ -15,29 +17,77 @@ export class Grcov {
1517
this.path = path;
1618
}
1719

18-
public static async get(): Promise<Grcov> {
20+
static async install(): Promise<void> {
1921
try {
20-
const path = await io.which('grcov', true);
21-
22-
return new Grcov(path);
22+
core.startGroup('Install grcov (from releases)');
23+
24+
const data = await new Octokit().graphql(`
25+
{
26+
repository(owner: "mozilla", name: "grcov") {
27+
releases(last: 1) {
28+
edges {
29+
node {
30+
releaseAssets(name: "grcov-linux-x86_64.tar.bz2", last: 1) {
31+
edges {
32+
node {
33+
downloadUrl,
34+
release {
35+
tagName
36+
}
37+
}
38+
}
39+
}
40+
}
41+
}
42+
}
43+
}
44+
}
45+
`);
46+
const tagName = data.repository.releases.edges[0].node.releaseAssets.edges[0].node.release.tagName;
47+
const downloadUrl = data.repository.releases.edges[0].node.releaseAssets.edges[0].node.downloadUrl;
48+
core.info("Installing grcov (" + tagName + ") from " + downloadUrl);
49+
const grcovTarBz2Path = await tc.downloadTool(downloadUrl);
50+
const grcovTarBz2ExtractedFolder = await tc.extractTar(grcovTarBz2Path, process.env.RUNNER_TEMP, "xj");
51+
core.addPath(grcovTarBz2ExtractedFolder);
52+
return ;
2353
} catch (error) {
24-
core.info('grcov is not installed, installing now');
54+
console.log(error);
55+
core.error(error);
56+
} finally {
57+
core.endGroup();
2558
}
2659

2760
const cargo = await Cargo.get();
2861
try {
29-
core.startGroup('Install grcov');
62+
core.startGroup('Install grcov (from sources)');
3063
await cargo.call(['install', 'grcov']);
3164
} catch (error) {
3265
throw error;
3366
} finally {
3467
core.endGroup();
3568
}
69+
}
70+
71+
public static async get(): Promise<Grcov> {
72+
try {
73+
const path = await io.which('grcov', true);
74+
75+
return new Grcov(path);
76+
} catch (error) {
77+
core.info('grcov is not installed, installing now');
78+
}
79+
80+
await Grcov.install();
3681

3782
// Expecting it to be in PATH already
38-
return new Grcov('grcov');
83+
const grcovInstance = new Grcov('grcov');
84+
85+
await exec.exec(grcovInstance.path, ['--version']);
86+
87+
return grcovInstance;
3988
}
4089

90+
4191
public async call(config: configuration.Config, archive: string): Promise<string> {
4292
const postfix = Math.random().toString(36).substring(2, 15)
4393
const reportPath = config.user.outputPath ? path.resolve(config.user.outputPath) : path.join(os.tmpdir(), `grcov-report-${postfix}`);

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async function run() {
1616
}
1717

1818
const exe = await grcov.Grcov.get();
19+
console.log(exe);
1920
const outputPath = await exe.call(config, coverageArchive);
2021

2122
core.setOutput('report', outputPath);

0 commit comments

Comments
 (0)