Skip to content

Commit

Permalink
Use process.exit() to mitigate actions/toolkit#1578 (#12)
Browse files Browse the repository at this point in the history
* Use process.exit() to mitigate actions/toolkit#1578

* package, upgrade dependencies, rev 2.0.1

* use node20 locally

* ci-bump

* trim trailing whitespace

* repackage
  • Loading branch information
nonrational authored Feb 27, 2024
1 parent 9072567 commit deaef57
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 74 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 20.9.0
32 changes: 22 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61843,6 +61843,14 @@ module.exports = require("path");

/***/ }),

/***/ 7282:
/***/ ((module) => {

"use strict";
module.exports = require("process");

/***/ }),

/***/ 5477:
/***/ ((module) => {

Expand Down Expand Up @@ -61968,13 +61976,14 @@ const core = __nccwpck_require__(2186)
const github = __nccwpck_require__(5438)
const cache = __nccwpck_require__(7799)
const fs = __nccwpck_require__(7147)
const process = __nccwpck_require__(7282)

const RESULT_PATH = '/tmp/prev-result'

const run = async () => {
const sha = github.context.sha
core.info(`Running for current SHA ${sha}`)

try {
// inputResult will be 'unknown' if we're in "restore only" mode.
const inputResult = core.getInput('result')
Expand All @@ -61988,7 +61997,6 @@ const run = async () => {

// True if we have a previous result already.
const cacheHit = !!fs.existsSync(RESULT_PATH)

let cacheOutcome = cacheHit ? 'hit' : 'miss'

// If the result is 'unknown' then we won't save it to the cache; we're in "restore only" mode.
Expand All @@ -62000,18 +62008,22 @@ const run = async () => {
actualResult = fs.readFileSync(RESULT_PATH, { encoding: 'utf8' })
}

const resultSummary = [
[{data: 'Output', header: true}, {data: 'Result', header: true}],
['result', actualResult],
['cache_key', key],
['cache_outcome', cacheOutcome],
]

core.setOutput('result', actualResult)
await core.summary.addTable(resultSummary).write()

await core.summary
.addTable([
[{data: 'Output', header: true}, {data: 'Result', header: true}],
['result', actualResult],
['cache_key', key],
['cache_outcome', cacheOutcome],
])
.write()
// https://github.com/actions/toolkit/issues/1578
core.info('All done. Forcing clean exit to avoid process hanging.')
process.exit(0)
} catch(error) {
core.setFailed(error.message)
process.exit(1)
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

104 changes: 52 additions & 52 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cache-result-action",
"version": "2.0.0",
"version": "2.0.1",
"description": "Github Action for storing results from previous runs by SHA",
"main": "index.js",
"scripts": {
Expand Down
24 changes: 14 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ const core = require('@actions/core')
const github = require('@actions/github')
const cache = require('@actions/cache')
const fs = require('fs')
const process = require('process')

const RESULT_PATH = '/tmp/prev-result'

const run = async () => {
const sha = github.context.sha
core.info(`Running for current SHA ${sha}`)

try {
// inputResult will be 'unknown' if we're in "restore only" mode.
const inputResult = core.getInput('result')
Expand All @@ -22,7 +23,6 @@ const run = async () => {

// True if we have a previous result already.
const cacheHit = !!fs.existsSync(RESULT_PATH)

let cacheOutcome = cacheHit ? 'hit' : 'miss'

// If the result is 'unknown' then we won't save it to the cache; we're in "restore only" mode.
Expand All @@ -34,18 +34,22 @@ const run = async () => {
actualResult = fs.readFileSync(RESULT_PATH, { encoding: 'utf8' })
}

const resultSummary = [
[{data: 'Output', header: true}, {data: 'Result', header: true}],
['result', actualResult],
['cache_key', key],
['cache_outcome', cacheOutcome],
]

core.setOutput('result', actualResult)
await core.summary.addTable(resultSummary).write()

await core.summary
.addTable([
[{data: 'Output', header: true}, {data: 'Result', header: true}],
['result', actualResult],
['cache_key', key],
['cache_outcome', cacheOutcome],
])
.write()
// https://github.com/actions/toolkit/issues/1578
core.info('All done. Forcing clean exit to avoid process hanging.')
process.exit(0)
} catch(error) {
core.setFailed(error.message)
process.exit(1)
}
}

Expand Down

0 comments on commit deaef57

Please sign in to comment.