Skip to content

Script Comment

Actions

About

Runs a script and posts its output as a sticky PR comment; the exit code decides whether the action passes or fails
v2
Latest
Star (0)

Script Comment

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.

Usage

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 --silent

The 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

Inputs

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.

Outputs

Output Description
exit-code Exit code of the script.

Notes

  • 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_request events (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.

Previewing locally

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.

Development

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

Script Comment is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.

About

Runs a script and posts its output as a sticky PR comment; the exit code decides whether the action passes or fails
v2
Latest

Script Comment is not certified by GitHub. It is provided by a third-party and is governed by separate terms of service, privacy policy, and support documentation.