Skip to content

Commit b6c531a

Browse files
committed
feat(with-post-step): create with-post-step action
1 parent f248984 commit b6c531a

File tree

4 files changed

+93
-0
lines changed

4 files changed

+93
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Test With Post Step Action
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "actions/with-post-action/**"
9+
- ".github/workflows/test-with-post-action.yaml"
10+
11+
pull_request:
12+
paths:
13+
- "actions/with-post-action/**"
14+
- ".github/workflows/test-with-post-action.yaml"
15+
types:
16+
- edited
17+
- opened
18+
- ready_for_review
19+
- synchronize
20+
21+
merge_group:
22+
23+
permissions:
24+
contents: read
25+
26+
jobs:
27+
test:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
32+
with:
33+
persist-credentials: false
34+
35+
- name: Run Create GitHub App Token action
36+
id: command
37+
uses: ./actions/create-github-app-token
38+
run: |
39+
echo "running command"
40+
echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}"
41+
42+
- name: Skip invalid instance
43+
uses: ./actions/with-post-step
44+
run:
45+
echo ${{ steps.command.outputs.test_output }}

actions/with-post-step/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# with-post-step
2+
3+
Action to set a command as a post step
4+
5+
Source Code reference: https://github.com/pyTooling/Actions/tree/main/with-post-step

actions/with-post-step/action.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Reference https://github.com/pyTooling/Actions/blob/main/with-post-step/action.yml
2+
3+
name: With post step
4+
5+
description: 'Generic JS Action to execute a main command and set a command as a post step.'
6+
7+
inputs:
8+
main:
9+
description: 'Main command/script.'
10+
required: true
11+
post:
12+
description: 'Post command/script.'
13+
required: true
14+
key:
15+
description: 'Name of the state variable used to detect the post step.'
16+
required: false
17+
default: POST
18+
19+
runs:
20+
using: 'node24'
21+
main: 'main.js'
22+
post: 'main.js'

actions/with-post-step/main.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Reference: https://github.com/pyTooling/Actions/blob/main/with-post-step/main.js
2+
3+
const { spawn } = require("child_process");
4+
const { appendFileSync } = require("fs");
5+
const { EOL } = require("os");
6+
7+
function run(cmd) {
8+
const subprocess = spawn(cmd, { stdio: "inherit", shell: true });
9+
subprocess.on("exit", (exitCode) => {
10+
process.exitCode = exitCode;
11+
});
12+
}
13+
14+
const key = process.env.INPUT_KEY.toUpperCase();
15+
16+
if ( process.env[`STATE_${key}`] !== undefined ) { // Are we in the 'post' step?
17+
run(process.env.INPUT_POST);
18+
} else { // Otherwise, this is the main step
19+
appendFileSync(process.env.GITHUB_STATE, `${key}=true${EOL}`);
20+
run(process.env.INPUT_MAIN);
21+
}

0 commit comments

Comments
 (0)