Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/test-with-post-step.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Test With Post Step Action

on:
push:
branches:
- main
paths:
- "actions/with-post-step/**"
- ".github/workflows/test-with-post-step.yaml"

pull_request:
paths:
- "actions/with-post-step/**"
- ".github/workflows/test-with-post-step.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 first command
id: command
run: |
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 }}

- name: Run second command
id: second-command
run: |
echo "running second command"
39 changes: 39 additions & 0 deletions actions/with-post-step/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# 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

<!-- x-release-please-start-version -->

```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
run: |
echo "running command"
echo "test_output=test_output_content" >> "${GITHUB_OUTPUT}"

- name: Skip invalid instance
uses: ./actions/with-post-step
with:
main: echo "with-post-step run"
 post: echo ${{ steps.command.outputs.test_output }}
```

<!-- x-release-please-end-version -->
22 changes: 22 additions & 0 deletions actions/with-post-step/action.yaml
Original file line number Diff line number Diff line change
@@ -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: "node20"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using: "node20"
using: "node22"

Would this also work?

main: "main.mjs"
post: "main.mjs"
22 changes: 22 additions & 0 deletions actions/with-post-step/main.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Reference: https://github.com/pyTooling/Actions/blob/main/with-post-step/main.js
import { spawn } from "node:child_process";
import { appendFileSync } from "fs";
import EOL from "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);
}
4 changes: 4 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -31,6 +32,9 @@ export default tseslint.config(
parserOptions: {
projectService: true,
},
globals: {
...globals.node,
},
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading