-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4696a6a
commit 3411ddc
Showing
3 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: With Post Step | ||
|
||
description: > | ||
JavaScript Action to run a main command and a subsequent post command. | ||
inputs: | ||
main: | ||
description: "Primary command or script to execute." | ||
required: true | ||
post: | ||
description: "Command or script to run after the main command." | ||
required: true | ||
key: | ||
description: "State variable name to identify the post step." | ||
required: false | ||
default: POST | ||
|
||
runs: | ||
using: "node20" | ||
main: "main.cjs" | ||
post: "main.cjs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Ref: https://github.com/pyTooling/Actions/blob/main/with-post-step/main.js | ||
const { spawn } = require('child_process'); | ||
const { appendFileSync } = require('fs'); | ||
const { EOL } = require('os'); | ||
|
||
function run(cmd) { | ||
const subprocess = spawn(cmd, { stdio: 'inherit', shell: true }); | ||
subprocess.on('exit', exitCode => { | ||
process.exitCode = exitCode; | ||
}); | ||
} | ||
|
||
const key = process.env.INPUT_KEY.toUpperCase(); | ||
|
||
if (process.env[`STATE_${key}`] !== undefined) { | ||
// Are we in the 'post' step? | ||
run(process.env.INPUT_POST); | ||
} else { | ||
// Otherwise, this is the main step | ||
appendFileSync(process.env.GITHUB_STATE, `${key}=true${EOL}`); | ||
run(process.env.INPUT_MAIN); | ||
} |