@@ -5,6 +5,8 @@ import * as core from '@actions/core';
55import  *  as  io  from  '@actions/io' ; 
66import  *  as  exec  from  '@actions/exec' ; 
77import  { Cargo }  from  '@actions-rs/core' ; 
8+ const  {  Octokit }  =  require ( "@octokit/action" ) ; 
9+ const  tc  =  require ( '@actions/tool-cache' ) ; 
810
911import  *  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 }  ` ) ; 
0 commit comments