@@ -2,6 +2,7 @@ const core = require('@actions/core')
2
2
const github = require ( '@actions/github' )
3
3
const cache = require ( '@actions/cache' )
4
4
const fs = require ( 'fs' )
5
+ const process = require ( 'process' )
5
6
6
7
const RESULT_PATH = '/tmp/prev-result'
7
8
@@ -15,14 +16,13 @@ const run = async () => {
15
16
const cacheGroup = core . getInput ( 'cache-group' )
16
17
const keyPrefix = `cache-result-action-${ cacheGroup } -${ sha } `
17
18
const key = keyPrefix + '-' + Math . floor ( Date . now ( ) / 1000 )
18
-
19
+
19
20
await cache . restoreCache ( [ RESULT_PATH ] , key , [ keyPrefix ] )
20
21
21
22
let actualResult = inputResult
22
23
23
24
// True if we have a previous result already.
24
25
const cacheHit = ! ! fs . existsSync ( RESULT_PATH )
25
-
26
26
let cacheOutcome = cacheHit ? 'hit' : 'miss'
27
27
28
28
// If the result is 'unknown' then we won't save it to the cache; we're in "restore only" mode.
@@ -34,18 +34,22 @@ const run = async () => {
34
34
actualResult = fs . readFileSync ( RESULT_PATH , { encoding : 'utf8' } )
35
35
}
36
36
37
+ const resultSummary = [
38
+ [ { data : 'Output' , header : true } , { data : 'Result' , header : true } ] ,
39
+ [ 'result' , actualResult ] ,
40
+ [ 'cache_key' , key ] ,
41
+ [ 'cache_outcome' , cacheOutcome ] ,
42
+ ]
43
+
37
44
core . setOutput ( 'result' , actualResult )
38
-
39
- await core . summary
40
- . addTable ( [
41
- [ { data : 'Output' , header : true } , { data : 'Result' , header : true } ] ,
42
- [ 'result' , actualResult ] ,
43
- [ 'cache_key' , key ] ,
44
- [ 'cache_outcome' , cacheOutcome ] ,
45
- ] )
46
- . write ( )
45
+ await core . summary . addTable ( resultSummary ) . write ( )
46
+
47
+ // https://github.com/actions/toolkit/issues/1578
48
+ core . info ( 'All done. Forcing clean exit to avoid process hanging.' )
49
+ process . exit ( 0 )
47
50
} catch ( error ) {
48
51
core . setFailed ( error . message )
52
+ process . exit ( 1 )
49
53
}
50
54
}
51
55
0 commit comments