A GitHub Action that runs a script and posts its output as a single sticky PR comment. The script's exit code decides whether the check passes or fails.
- The script's stdout becomes the comment body (rendered as markdown); stderr goes to the action log.
- Keeps one comment per PR, updated in place on every run.
- Deletes the comment automatically once the script produces no output.
- A non-zero exit code fails the action — after the comment is posted, so the results are still visible.
name: Lint report
on:
pull_request:
types: [opened, synchronize, reopened]
permissions:
pull-requests: write
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: includable/script-comment-action@v3
with:
comment-header: "Lint results"
script: |
npm ci --silent
npm run lint --silentThe script runs with bash -eo pipefail, matching a regular shell: bash step: the first failing command aborts the script, and its exit code fails the action.
To keep multiple comments from different runs of this action on the same PR, give each one its own comment-id:
- uses: includable/script-comment-action@v3
with:
comment-id: coverage
comment-header: "Coverage report"
script: ./scripts/coverage-summary.sh| Input | Default | Description |
|---|---|---|
script |
(required) | Bash script to run. Its stdout becomes the PR comment body; a non-zero exit code fails the action. |
token |
${{ github.token }} |
Token with pull-requests: write permission. |
comment-id |
script-comment |
Identifier for the sticky comment, so multiple instances can keep separate comments. |
comment-header |
(none) | Optional heading shown at the top of the comment. |
working-directory |
workspace root | Directory to run the script in. |
| Output | Description |
|---|---|
exit-code |
Exit code of the script. |
- If the script produces no output, no comment is posted (and any existing one is deleted) — the exit code still decides pass/fail. This makes "only comment when there's something to say" scripts trivial: stay silent on success.
- Output longer than GitHub's 65,536-character comment limit is truncated with a notice.
- On non-
pull_requestevents (e.g.push,workflow_dispatch) the script still runs and the exit code still decides pass/fail — the comment step is skipped with a warning, and the output is written to the action log instead.
You can render the comment for any script without posting anything:
node bin/preview.js 'npm run lint --silent'
node bin/preview.js --header 'Lint results' --comment-id lint './scripts/report.sh'The comment markdown is printed to stdout, and the process exits with the script's exit code.
The script execution and comment rendering live in src/script-comment.js, shared by the action (action.yml, via actions/github-script) and the local preview CLI. Run the tests with:
npm test