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: writefor the comment to succeed. - Update a single status comment instead of posting a new one each run to reduce noise.
Related guides
How to React to a Command Comment in GitHub ActionsAcknowledge a slash command in GitHub Actions by adding an emoji reaction to the comment with the reactions A…
How to Send Ephemeral Responses to Slack ChatOps CommandsSend ephemeral responses to Slack ChatOps commands so acknowledgements and errors are visible only to the inv…