1
- import { platform } from 'os' ;
2
- import { chdir } from 'process' ;
1
+ import { platform } from 'node:os' ;
2
+ import { chdir } from 'node:process' ;
3
+ import { unlinkSync } from 'node:fs' ;
3
4
import { debug , error , setFailed , warning , info } from '@actions/core' ;
4
5
import { exec } from '@actions/exec' ;
5
6
import { context } from '@actions/github' ;
@@ -31,6 +32,17 @@ const SUPPORTED_GITHUB_EVENTS = [
31
32
'pull_request_target' ,
32
33
] ;
33
34
35
+ const fileArtifacts = new Set < string > ( ) ;
36
+
37
+ async function downloadAndRecord (
38
+ url : string ,
39
+ file : string ,
40
+ mode ?: number
41
+ ) : Promise < void > {
42
+ await downloadToFile ( url , file , mode ) ;
43
+ fileArtifacts . add ( file ) ;
44
+ }
45
+
34
46
function prepareEnv ( ) {
35
47
const env = process . env as { [ key : string ] : string } ;
36
48
@@ -120,7 +132,7 @@ export function run(
120
132
121
133
try {
122
134
debug ( `ℹ️ Downloading CC Reporter from ${ downloadUrl } ...` ) ;
123
- await downloadToFile ( downloadUrl , executable ) ;
135
+ await downloadAndRecord ( downloadUrl , executable ) ;
124
136
debug ( '✅ CC Reporter downloaded...' ) ;
125
137
} catch ( err ) {
126
138
error ( ( err as Error ) . message ) ;
@@ -141,7 +153,7 @@ export function run(
141
153
142
154
try {
143
155
debug ( `ℹ️ Verifying CC Reporter checksum...` ) ;
144
- await downloadToFile ( checksumUrl , checksumFilePath ) ;
156
+ await downloadAndRecord ( checksumUrl , checksumFilePath ) ;
145
157
const checksumVerified = await verifyChecksum (
146
158
executable ,
147
159
checksumFilePath ,
@@ -158,8 +170,8 @@ export function run(
158
170
159
171
try {
160
172
debug ( `ℹ️ Verifying CC Reporter GPG signature...` ) ;
161
- await downloadToFile ( signatureUrl , signatureFilePath ) ;
162
- await downloadToFile (
173
+ await downloadAndRecord ( signatureUrl , signatureFilePath ) ;
174
+ await downloadAndRecord (
163
175
CODECLIMATE_GPG_PUBLIC_KEY_URL ,
164
176
ccPublicKeyFilePath
165
177
) ;
@@ -353,14 +365,25 @@ if (require.main === module) {
353
365
'verifyDownload' ,
354
366
DEFAULT_VERIFY_DOWNLOAD
355
367
) ;
356
- run (
357
- DOWNLOAD_URL ,
358
- EXECUTABLE ,
359
- coverageCommand ,
360
- workingDirectory ,
361
- codeClimateDebug ,
362
- coverageLocations ,
363
- coveragePrefix ,
364
- verifyDownload
365
- ) ;
368
+ try {
369
+ run (
370
+ DOWNLOAD_URL ,
371
+ EXECUTABLE ,
372
+ coverageCommand ,
373
+ workingDirectory ,
374
+ codeClimateDebug ,
375
+ coverageLocations ,
376
+ coveragePrefix ,
377
+ verifyDownload
378
+ ) ;
379
+ } catch ( err ) {
380
+ throw err ;
381
+ } finally {
382
+ // Finally clean up all artifacts that we downloaded.
383
+ for ( const artifact of fileArtifacts ) {
384
+ try {
385
+ unlinkSync ( artifact ) ;
386
+ } catch { }
387
+ }
388
+ }
366
389
}
0 commit comments