Skip to content

Commit 4c4a048

Browse files
committed
Use process.exit() to mitigate actions/toolkit#1578
1 parent 9072567 commit 4c4a048

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/index.js

+15-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const core = require('@actions/core')
22
const github = require('@actions/github')
33
const cache = require('@actions/cache')
44
const fs = require('fs')
5+
const process = require('process')
56

67
const RESULT_PATH = '/tmp/prev-result'
78

@@ -15,14 +16,13 @@ const run = async () => {
1516
const cacheGroup = core.getInput('cache-group')
1617
const keyPrefix = `cache-result-action-${cacheGroup}-${sha}`
1718
const key = keyPrefix + '-' + Math.floor(Date.now() / 1000)
18-
19+
1920
await cache.restoreCache([RESULT_PATH], key, [keyPrefix])
2021

2122
let actualResult = inputResult
2223

2324
// True if we have a previous result already.
2425
const cacheHit = !!fs.existsSync(RESULT_PATH)
25-
2626
let cacheOutcome = cacheHit ? 'hit' : 'miss'
2727

2828
// 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 () => {
3434
actualResult = fs.readFileSync(RESULT_PATH, { encoding: 'utf8' })
3535
}
3636

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+
3744
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)
4750
} catch(error) {
4851
core.setFailed(error.message)
52+
process.exit(1)
4953
}
5054
}
5155

0 commit comments

Comments
 (0)