@@ -23,98 +23,111 @@ import versionInfo from './version';
2323
2424let failCi ;
2525
26- try {
27- const { commitExecArgs, commitOptions, commitCommand} = buildCommitExec ( ) ;
28- const { reportExecArgs, reportOptions, reportCommand} = buildReportExec ( ) ;
29- const {
30- uploadExecArgs,
31- uploadOptions,
32- failCi,
33- os,
34- uploaderVersion,
35- uploadCommand,
36- } = buildUploadExec ( ) ;
37- const { args, verbose} = buildGeneralExec ( ) ;
26+ /**
27+ * Main function of the codecov-action
28+ */
29+ async function run ( ) : Promise < void > {
30+ try {
31+ const { commitExecArgs, commitOptions, commitCommand} = buildCommitExec ( ) ;
32+ const {
33+ reportExecArgs,
34+ reportOptions,
35+ reportCommand,
36+ } = await buildReportExec ( ) ;
37+ const {
38+ uploadExecArgs,
39+ uploadOptions,
40+ failCi,
41+ os,
42+ uploaderVersion,
43+ uploadCommand,
44+ } = buildUploadExec ( ) ;
45+ const { args, verbose} = buildGeneralExec ( ) ;
3846
39- const platform = getPlatform ( os ) ;
47+ const platform = getPlatform ( os ) ;
4048
41- const filename = path . join ( __dirname , getUploaderName ( platform ) ) ;
42- https . get ( getBaseUrl ( platform , uploaderVersion ) , ( res ) => {
49+ const filename = path . join ( __dirname , getUploaderName ( platform ) ) ;
50+ https . get ( getBaseUrl ( platform , uploaderVersion ) , ( res ) => {
4351 // Image will be stored at this path
44- const filePath = fs . createWriteStream ( filename ) ;
45- res . pipe ( filePath ) ;
46- filePath
47- . on ( 'error' , ( err ) => {
48- setFailure (
49- `Codecov: Failed to write uploader binary: ${ err . message } ` ,
50- true ,
51- ) ;
52- } ) . on ( 'finish' , async ( ) => {
53- filePath . close ( ) ;
52+ const filePath = fs . createWriteStream ( filename ) ;
53+ res . pipe ( filePath ) ;
54+ filePath
55+ . on ( 'error' , ( err ) => {
56+ setFailure (
57+ `Codecov: Failed to write uploader binary: ${ err . message } ` ,
58+ true ,
59+ ) ;
60+ } ) . on ( 'finish' , async ( ) => {
61+ filePath . close ( ) ;
5462
55- await verify ( filename , platform , uploaderVersion , verbose , failCi ) ;
56- await versionInfo ( platform , uploaderVersion ) ;
57- await fs . chmodSync ( filename , '777' ) ;
63+ await verify ( filename , platform , uploaderVersion , verbose , failCi ) ;
64+ await versionInfo ( platform , uploaderVersion ) ;
65+ await fs . chmodSync ( filename , '777' ) ;
5866
59- const unlink = ( ) => {
60- fs . unlink ( filename , ( err ) => {
61- if ( err ) {
62- setFailure (
63- `Codecov: Could not unlink uploader: ${ err . message } ` ,
64- failCi ,
65- ) ;
66- }
67- } ) ;
68- } ;
69- const doUpload = async ( ) => {
70- await exec . exec ( getCommand ( filename , args , uploadCommand ) . join ( ' ' ) ,
71- uploadExecArgs ,
72- uploadOptions )
73- . catch ( ( err ) => {
67+ const unlink = ( ) => {
68+ fs . unlink ( filename , ( err ) => {
69+ if ( err ) {
7470 setFailure (
75- `Codecov:
76- Failed to properly upload report: ${ err . message } ` ,
71+ `Codecov: Could not unlink uploader: ${ err . message } ` ,
7772 failCi ,
7873 ) ;
79- } ) ;
80- } ;
81- const createReport = async ( ) => {
74+ }
75+ } ) ;
76+ } ;
77+ const doUpload = async ( ) => {
78+ await exec . exec (
79+ getCommand ( filename , args , uploadCommand ) . join ( ' ' ) ,
80+ uploadExecArgs ,
81+ uploadOptions )
82+ . catch ( ( err ) => {
83+ setFailure (
84+ `Codecov:
85+ Failed to properly upload report: ${ err . message } ` ,
86+ failCi ,
87+ ) ;
88+ } ) ;
89+ } ;
90+ const createReport = async ( ) => {
91+ await exec . exec (
92+ getCommand ( filename , args , reportCommand ) . join ( ' ' ) ,
93+ reportExecArgs ,
94+ reportOptions )
95+ . then ( async ( exitCode ) => {
96+ if ( exitCode == 0 ) {
97+ await doUpload ( ) ;
98+ }
99+ } ) . catch ( ( err ) => {
100+ setFailure (
101+ `Codecov:
102+ Failed to properly create report: ${ err . message } ` ,
103+ failCi ,
104+ ) ;
105+ } ) ;
106+ } ;
82107 await exec . exec (
83- getCommand ( filename , args , reportCommand ) . join ( ' ' ) ,
84- reportExecArgs ,
85- reportOptions )
108+ getCommand (
109+ filename ,
110+ args ,
111+ commitCommand ,
112+ ) . join ( ' ' ) ,
113+ commitExecArgs , commitOptions )
86114 . then ( async ( exitCode ) => {
87115 if ( exitCode == 0 ) {
88- await doUpload ( ) ;
116+ await createReport ( ) ;
89117 }
118+ unlink ( ) ;
90119 } ) . catch ( ( err ) => {
91120 setFailure (
92- `Codecov:
93- Failed to properly create report: ${ err . message } ` ,
121+ `Codecov: Failed to properly create commit:
122+ ${ err . message } ` ,
94123 failCi ,
95124 ) ;
96125 } ) ;
97- } ;
98- await exec . exec (
99- getCommand (
100- filename ,
101- args ,
102- commitCommand ,
103- ) . join ( ' ' ) ,
104- commitExecArgs , commitOptions )
105- . then ( async ( exitCode ) => {
106- if ( exitCode == 0 ) {
107- await createReport ( ) ;
108- }
109- unlink ( ) ;
110- } ) . catch ( ( err ) => {
111- setFailure (
112- `Codecov: Failed to properly create commit: ${ err . message } ` ,
113- failCi ,
114- ) ;
115- } ) ;
116- } ) ;
117- } ) ;
118- } catch ( err ) {
119- setFailure ( `Codecov: Encountered an unexpected error ${ err . message } ` , failCi ) ;
126+ } ) ;
127+ } ) ;
128+ } catch ( err ) {
129+ setFailure ( `Codecov: Encountered an unexpected error ${ err . message } ` ,
130+ failCi ) ;
131+ }
120132}
133+ run ( ) ;
0 commit comments