@@ -3,14 +3,12 @@ import { globSync } from 'glob';
33import { chmodSync , existsSync , readFileSync } from 'fs' ;
44import path from 'path' ;
55
6- const ROOT_DIR = process . argv [ 2 ] ;
6+ // Usage
7+ // node ./scripts/codecov-upload-flags.mjs
8+
79const branchName = process . argv [ 3 ] ;
810const commitSha = process . argv [ 4 ] ;
911
10- if ( typeof ROOT_DIR !== 'string' ) {
11- console . log ( 'Workspace missing! Exiting' ) ;
12- process . exit ( - 1 ) ;
13- }
1412if ( typeof branchName !== 'string' ) {
1513 console . log ( 'Branch name missing! Exiting' ) ;
1614 process . exit ( - 1 ) ;
@@ -21,11 +19,8 @@ if (typeof commitSha !== 'string') {
2119}
2220
2321const readPkg = ( dir ) => JSON . parse ( readFileSync ( path . join ( dir , 'package.json' ) , 'utf8' ) ) ;
24- const execCmd = ( cmd , opts = { } ) => execSync ( cmd , { cwd : process . argv [ 2 ] , encoding : 'utf-8' , stdio : 'inherit' , ...opts } ) ;
25-
26- const pkgInfo = readPkg ( ROOT_DIR ) ;
22+ const pkgInfo = readPkg ( '.' ) ;
2723const pkgFiles = pkgInfo . workspaces . map ( ( exp ) => globSync ( path . join ( exp , 'package.json' ) ) ) ;
28- const codecovPath = path . resolve ( ROOT_DIR , 'codecov' ) ;
2924const pkgsWithFlag = pkgFiles . flat ( ) . map ( ( f ) => {
3025 const path = f . replace ( 'package.json' , '' ) ;
3126 const info = readPkg ( path ) ;
@@ -70,16 +65,17 @@ if (!url) {
7065 process . exit ( - 1 ) ;
7166}
7267
68+ const execOpts = { encoding : 'utf-8' , stdio : 'inherit' } ;
7369if ( existsSync ( codecovPath ) ) {
7470 console . log ( `Codecov binary found.` ) ;
7571} else {
7672 console . log ( `Codecov binary missing. Downloading from ${ url } ` ) ;
77- execCmd ( `curl -O "${ url } "` ) ;
78- console . log ( `Verifying codecov binary downloaded to ${ codecovPath } ` ) ;
79- execCmd ( `echo "$(curl -s https://keybase.io/codecovsecurity/pgp_keys.asc)" | gpg --no-default-keyring --import` ) ;
80- execCmd ( `curl -O "${ url } .SHA256SUM"` ) ;
81- execCmd ( `curl -O "${ url } .SHA256SUM.sig"` ) ;
82- execCmd ( `gpg --verify "${ codecovPath } .SHA256SUM.sig" "${ codecovPath } .SHA256SUM"` ) ;
73+ execSync ( `curl -O "${ url } "` , execOpts ) ;
74+ console . log ( `Verifying codecov binary downloaded to "./codecov" ` ) ;
75+ execSync ( `echo "$(curl -s https://keybase.io/codecovsecurity/pgp_keys.asc)" | gpg --no-default-keyring --import` , execOpts ) ;
76+ execSync ( `curl -O "${ url } .SHA256SUM"` , execOpts ) ;
77+ execSync ( `curl -O "${ url } .SHA256SUM.sig"` , execOpts ) ;
78+ execSync ( `gpg --verify "codecov .SHA256SUM.sig" "codecov .SHA256SUM"` , execOpts ) ;
8379}
8480// make sure we have exec perms
8581chmodSync ( codecovPath , 0o555 ) ;
@@ -88,6 +84,6 @@ chmodSync(codecovPath, 0o555);
8884for ( const pkg of pkgsWithFlag ) {
8985 if ( existsSync ( pkg . report ) ) {
9086 console . log ( `\n\nCODECOV: Uploading report of "${ pkg . name } " with flag "${ pkg . flag } "\n${ pkg . command } ` ) ;
91- execCmd ( pkg . command ) ;
87+ execSync ( pkg . command , execOpts ) ;
9288 }
9389}
0 commit comments