@@ -5,6 +5,8 @@ import * as core from '@actions/core';
5
5
import * as io from '@actions/io' ;
6
6
import * as exec from '@actions/exec' ;
7
7
import { Cargo } from '@actions-rs/core' ;
8
+ const { Octokit } = require ( "@octokit/action" ) ;
9
+ const tc = require ( '@actions/tool-cache' ) ;
8
10
9
11
import * as configuration from './configuration' ;
10
12
@@ -15,29 +17,77 @@ export class Grcov {
15
17
this . path = path ;
16
18
}
17
19
18
- public static async get ( ) : Promise < Grcov > {
20
+ static async install ( ) : Promise < void > {
19
21
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 ;
23
53
} catch ( error ) {
24
- core . info ( 'grcov is not installed, installing now' ) ;
54
+ console . log ( error ) ;
55
+ core . error ( error ) ;
56
+ } finally {
57
+ core . endGroup ( ) ;
25
58
}
26
59
27
60
const cargo = await Cargo . get ( ) ;
28
61
try {
29
- core . startGroup ( 'Install grcov' ) ;
62
+ core . startGroup ( 'Install grcov (from sources) ' ) ;
30
63
await cargo . call ( [ 'install' , 'grcov' ] ) ;
31
64
} catch ( error ) {
32
65
throw error ;
33
66
} finally {
34
67
core . endGroup ( ) ;
35
68
}
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 ( ) ;
36
81
37
82
// 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 ;
39
88
}
40
89
90
+
41
91
public async call ( config : configuration . Config , archive : string ) : Promise < string > {
42
92
const postfix = Math . random ( ) . toString ( 36 ) . substring ( 2 , 15 )
43
93
const reportPath = config . user . outputPath ? path . resolve ( config . user . outputPath ) : path . join ( os . tmpdir ( ) , `grcov-report-${ postfix } ` ) ;
0 commit comments