From 836260adb97d93ac64bd5cfa036a3a2c7e6c1770 Mon Sep 17 00:00:00 2001 From: eloymg Date: Mon, 6 Oct 2025 15:15:27 +0200 Subject: [PATCH 1/6] feat(with-post-step): create with-post-step action --- .github/workflows/test-with-post-action.yaml | 45 ++++++++++++++++++++ actions/with-post-step/README.md | 5 +++ actions/with-post-step/action.yaml | 22 ++++++++++ actions/with-post-step/main.js | 21 +++++++++ 4 files changed, 93 insertions(+) create mode 100644 .github/workflows/test-with-post-action.yaml create mode 100644 actions/with-post-step/README.md create mode 100644 actions/with-post-step/action.yaml create mode 100644 actions/with-post-step/main.js diff --git a/.github/workflows/test-with-post-action.yaml b/.github/workflows/test-with-post-action.yaml new file mode 100644 index 000000000..34a7085c2 --- /dev/null +++ b/.github/workflows/test-with-post-action.yaml @@ -0,0 +1,45 @@ +name: Test With Post Step Action + +on: + push: + branches: + - main + paths: + - "actions/with-post-action/**" + - ".github/workflows/test-with-post-action.yaml" + + pull_request: + paths: + - "actions/with-post-action/**" + - ".github/workflows/test-with-post-action.yaml" + types: + - edited + - opened + - ready_for_review + - synchronize + + merge_group: + +permissions: + contents: read + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: false + + - name: Run Create GitHub App Token action + id: command + uses: ./actions/create-github-app-token + run: | + echo "running command" + echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}" + + - name: Skip invalid instance + uses: ./actions/with-post-step + run: + echo ${{ steps.command.outputs.test_output }} diff --git a/actions/with-post-step/README.md b/actions/with-post-step/README.md new file mode 100644 index 000000000..0bdf4b7d5 --- /dev/null +++ b/actions/with-post-step/README.md @@ -0,0 +1,5 @@ +# with-post-step + +Action to set a command as a post step + +Source Code reference: https://github.com/pyTooling/Actions/tree/main/with-post-step diff --git a/actions/with-post-step/action.yaml b/actions/with-post-step/action.yaml new file mode 100644 index 000000000..7aa13714b --- /dev/null +++ b/actions/with-post-step/action.yaml @@ -0,0 +1,22 @@ +# Reference https://github.com/pyTooling/Actions/blob/main/with-post-step/action.yml + +name: With post step + +description: 'Generic JS Action to execute a main command and set a command as a post step.' + +inputs: + main: + description: 'Main command/script.' + required: true + post: + description: 'Post command/script.' + required: true + key: + description: 'Name of the state variable used to detect the post step.' + required: false + default: POST + +runs: + using: 'node24' + main: 'main.js' + post: 'main.js' diff --git a/actions/with-post-step/main.js b/actions/with-post-step/main.js new file mode 100644 index 000000000..0f6d704b9 --- /dev/null +++ b/actions/with-post-step/main.js @@ -0,0 +1,21 @@ +// Reference: 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); +} From 83acd4c69925a9361c4a73e9b3bfe0fd543808e1 Mon Sep 17 00:00:00 2001 From: eloymg Date: Mon, 6 Oct 2025 15:34:36 +0200 Subject: [PATCH 2/6] example and release please --- actions/with-post-step/README.md | 33 ++++++++++++++++++++++++++++++++ actions/with-post-step/main.js | 13 +++++++------ eslint.config.mjs | 4 ++++ release-please-config.json | 4 ++++ 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/actions/with-post-step/README.md b/actions/with-post-step/README.md index 0bdf4b7d5..1d3b72dd9 100644 --- a/actions/with-post-step/README.md +++ b/actions/with-post-step/README.md @@ -3,3 +3,36 @@ Action to set a command as a post step Source Code reference: https://github.com/pyTooling/Actions/tree/main/with-post-step + + + +```yaml +name: CI +on: + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + persist-credentials: false + + - name: Run Create GitHub App Token action + id: command + uses: ./actions/create-github-app-token + run: | + echo "running command" + echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}" + + - name: Skip invalid instance + uses: ./actions/with-post-step + run: echo ${{ steps.command.outputs.test_output }} +``` + + diff --git a/actions/with-post-step/main.js b/actions/with-post-step/main.js index 0f6d704b9..a0707938f 100644 --- a/actions/with-post-step/main.js +++ b/actions/with-post-step/main.js @@ -1,8 +1,7 @@ // Reference: 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"); +import spawn from "child_process"; +import { appendFileSync } from "fs"; +import EOL from "os"; function run(cmd) { const subprocess = spawn(cmd, { stdio: "inherit", shell: true }); @@ -13,9 +12,11 @@ function run(cmd) { const key = process.env.INPUT_KEY.toUpperCase(); -if ( process.env[`STATE_${key}`] !== undefined ) { // Are we in the 'post' step? +if (process.env[`STATE_${key}`] !== undefined) { + // Are we in the 'post' step? run(process.env.INPUT_POST); -} else { // Otherwise, this is the main step +} else { + // Otherwise, this is the main step appendFileSync(process.env.GITHUB_STATE, `${key}=true${EOL}`); run(process.env.INPUT_MAIN); } diff --git a/eslint.config.mjs b/eslint.config.mjs index 2a69f7246..1511e2883 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -3,6 +3,7 @@ import eslintPluginJest from "eslint-plugin-jest"; import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended"; import js from "@eslint/js"; import tseslint from "typescript-eslint"; +import globals from "globals"; export default tseslint.config( js.configs.recommended, @@ -31,6 +32,9 @@ export default tseslint.config( parserOptions: { projectService: true, }, + globals: { + ...globals.node, + }, }, }, { diff --git a/release-please-config.json b/release-please-config.json index 147729b6c..6f9ff5957 100644 --- a/release-please-config.json +++ b/release-please-config.json @@ -164,6 +164,10 @@ "package-name": "cleanup-branches", "extra-files": ["README.md"], "initial-version": "0.1.0" + }, + "actions/with-post-step": { + "package-name": "with-post-step", + "extra-files": ["README.md"] } }, "release-type": "simple", From 69891b2f8f955b565aa2b425ee1c38eeaaf91924 Mon Sep 17 00:00:00 2001 From: eloymg Date: Mon, 6 Oct 2025 15:40:37 +0200 Subject: [PATCH 3/6] node20 --- .github/workflows/test-with-post-action.yaml | 10 +++++----- actions/with-post-step/README.md | 5 +++-- actions/with-post-step/action.yaml | 14 +++++++------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test-with-post-action.yaml b/.github/workflows/test-with-post-action.yaml index 34a7085c2..69daed781 100644 --- a/.github/workflows/test-with-post-action.yaml +++ b/.github/workflows/test-with-post-action.yaml @@ -6,12 +6,12 @@ on: - main paths: - "actions/with-post-action/**" - - ".github/workflows/test-with-post-action.yaml" + - ".github/workflows/test-with-post-step.yaml" pull_request: paths: - "actions/with-post-action/**" - - ".github/workflows/test-with-post-action.yaml" + - ".github/workflows/test-with-post-step.yaml" types: - edited - opened @@ -34,12 +34,12 @@ jobs: - name: Run Create GitHub App Token action id: command - uses: ./actions/create-github-app-token run: | echo "running command" echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}" - name: Skip invalid instance uses: ./actions/with-post-step - run: - echo ${{ steps.command.outputs.test_output }} + with: + main: echo "with-post-step run" + post: echo ${{ steps.command.outputs.test_output }} diff --git a/actions/with-post-step/README.md b/actions/with-post-step/README.md index 1d3b72dd9..b9132df5a 100644 --- a/actions/with-post-step/README.md +++ b/actions/with-post-step/README.md @@ -25,14 +25,15 @@ jobs: - name: Run Create GitHub App Token action id: command - uses: ./actions/create-github-app-token run: | echo "running command" echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}" - name: Skip invalid instance uses: ./actions/with-post-step - run: echo ${{ steps.command.outputs.test_output }} + with: + main: echo "with-post-step run" +  post: echo ${{ steps.command.outputs.test_output }} ``` diff --git a/actions/with-post-step/action.yaml b/actions/with-post-step/action.yaml index 7aa13714b..46956b009 100644 --- a/actions/with-post-step/action.yaml +++ b/actions/with-post-step/action.yaml @@ -2,21 +2,21 @@ name: With post step -description: 'Generic JS Action to execute a main command and set a command as a post step.' +description: "Generic JS Action to execute a main command and set a command as a post step." inputs: main: - description: 'Main command/script.' + description: "Main command/script." required: true post: - description: 'Post command/script.' + description: "Post command/script." required: true key: - description: 'Name of the state variable used to detect the post step.' + description: "Name of the state variable used to detect the post step." required: false default: POST runs: - using: 'node24' - main: 'main.js' - post: 'main.js' + using: "node20" + main: "main.js" + post: "main.js" From f31eb0d8904dca20a287b258cf67396f91c21203 Mon Sep 17 00:00:00 2001 From: eloymg Date: Mon, 6 Oct 2025 15:42:42 +0200 Subject: [PATCH 4/6] typo in the names --- .../{test-with-post-action.yaml => test-with-post-step.yaml} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{test-with-post-action.yaml => test-with-post-step.yaml} (92%) diff --git a/.github/workflows/test-with-post-action.yaml b/.github/workflows/test-with-post-step.yaml similarity index 92% rename from .github/workflows/test-with-post-action.yaml rename to .github/workflows/test-with-post-step.yaml index 69daed781..5ee2a4a24 100644 --- a/.github/workflows/test-with-post-action.yaml +++ b/.github/workflows/test-with-post-step.yaml @@ -5,12 +5,12 @@ on: branches: - main paths: - - "actions/with-post-action/**" + - "actions/with-post-step/**" - ".github/workflows/test-with-post-step.yaml" pull_request: paths: - - "actions/with-post-action/**" + - "actions/with-post-step/**" - ".github/workflows/test-with-post-step.yaml" types: - edited From 65a77b5523368dc7fad21d6521241ca8d656ec31 Mon Sep 17 00:00:00 2001 From: eloymg Date: Mon, 6 Oct 2025 15:46:10 +0200 Subject: [PATCH 5/6] from node:child_process --- .github/workflows/test-with-post-step.yaml | 2 +- actions/with-post-step/main.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test-with-post-step.yaml b/.github/workflows/test-with-post-step.yaml index 5ee2a4a24..c096ed6a0 100644 --- a/.github/workflows/test-with-post-step.yaml +++ b/.github/workflows/test-with-post-step.yaml @@ -38,7 +38,7 @@ jobs: echo "running command" echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}" - - name: Skip invalid instance + - name: With post step run uses: ./actions/with-post-step with: main: echo "with-post-step run" diff --git a/actions/with-post-step/main.js b/actions/with-post-step/main.js index a0707938f..477ca9350 100644 --- a/actions/with-post-step/main.js +++ b/actions/with-post-step/main.js @@ -1,5 +1,5 @@ // Reference: https://github.com/pyTooling/Actions/blob/main/with-post-step/main.js -import spawn from "child_process"; +import { spawn } from "node:child_process"; import { appendFileSync } from "fs"; import EOL from "os"; From 7a29e36e7ec3e2187c2a0dc34b077666bffd93b6 Mon Sep 17 00:00:00 2001 From: eloymg Date: Mon, 6 Oct 2025 15:51:20 +0200 Subject: [PATCH 6/6] mjs --- .github/workflows/test-with-post-step.yaml | 12 +++++++++--- actions/with-post-step/action.yaml | 4 ++-- actions/with-post-step/{main.js => main.mjs} | 0 3 files changed, 11 insertions(+), 5 deletions(-) rename actions/with-post-step/{main.js => main.mjs} (100%) diff --git a/.github/workflows/test-with-post-step.yaml b/.github/workflows/test-with-post-step.yaml index c096ed6a0..bc36f66f5 100644 --- a/.github/workflows/test-with-post-step.yaml +++ b/.github/workflows/test-with-post-step.yaml @@ -32,14 +32,20 @@ jobs: with: persist-credentials: false - - name: Run Create GitHub App Token action + - name: Run first command id: command run: | - echo "running command" + echo "running firts command" echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}" - name: With post step run uses: ./actions/with-post-step with: main: echo "with-post-step run" - post: echo ${{ steps.command.outputs.test_output }} + post: | + echo ${{ steps.command.outputs.test_output }} + + - name: Run second command + id: second-command + run: | + echo "running second command" diff --git a/actions/with-post-step/action.yaml b/actions/with-post-step/action.yaml index 46956b009..2b8565494 100644 --- a/actions/with-post-step/action.yaml +++ b/actions/with-post-step/action.yaml @@ -18,5 +18,5 @@ inputs: runs: using: "node20" - main: "main.js" - post: "main.js" + main: "main.mjs" + post: "main.mjs" diff --git a/actions/with-post-step/main.js b/actions/with-post-step/main.mjs similarity index 100% rename from actions/with-post-step/main.js rename to actions/with-post-step/main.mjs