Skip to content
Latchkey

How to Post Command Results Back to a PR or Slack in GitHub Actions

Closing the loop matters: comment on the PR or message Slack with the outcome and a link to the run so nobody has to hunt for it.

After the command finishes, use github-script to comment on the PR (via client_payload.pull_request.number or context.issue.number) and optionally POST to a Slack webhook with the result.

Steps

  • Capture the command outcome (success or failure).
  • Comment on the PR with a status and the run URL.
  • Optionally send the same summary to Slack.

Result step

.github/workflows/deploy-command.yml
- if: always()
  uses: actions/github-script@v7
  with:
    script: |
      const ok = '${{ job.status }}' === 'success'
      const url = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`
      await github.rest.issues.createComment({
        owner: context.repo.owner,
        repo: context.repo.repo,
        issue_number: context.payload.client_payload.pull_request.number,
        body: `Deploy ${ok ? 'succeeded' : 'failed'}: ${url}`
      })

Gotchas

  • Use if: always() so the result comment posts even when the command fails.
  • Grant pull-requests: write for the comment to succeed.
  • Update a single status comment instead of posting a new one each run to reduce noise.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →