Andrew Korin
Andrew Korin

Reputation: 304

How to make Github Actions workflow that is triggered by a pr comment to be reported in the pr checks

I have a called workflow that deploys the app to Heroku. It is triggered by a pr comment.

name: Preview App Deployment
on:
  issue_comment:
    types: [created]
jobs:
  call-heroku-preview-app:
    name: Deploy to Heroku
    if: ${{ contains(github.event.comment.body, '/deploy') }}
    uses: ./.github/workflows/heroku-preview-app.yml

However, it doesn't show up in the pr checks as it does for jobs that are triggered by

on:
  pull_request:
    types: [synchronize, opened, reopened, ready_for_review]
    branches-ignore: [master, production]

which hurts visibility. Also, I'm planning to add another workflow triggered by a comment that runs unit and e2e tests. If the result won't be included in the Github checks it will be a problem.

So is it really impossible to include them there or I'm missing something?

Upvotes: 2

Views: 1524

Answers (1)

rethab
rethab

Reputation: 8403

PR Checks are attached to a commit, but when you're running a workflow on issue_comment what would the context be? Intuitively, comment in a PR is not a thing related to a commit.

In fact, when looking at ${{ github.sha }} inside a workflow triggered by issue_comment, the SHA is actually that of the default branch.


You could manually add a check using the Check Runs API.

However, when triggering this on issue_comment, you're going to have to replace the value github.sha with your own logic to identify the tip of the branch associated with the PR for which the comment was made.

- uses: actions/checkout@v3
- run: echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
- run: echo '{"name":"Test Check","head_sha":"${{ github.sha }}"}' | gh api /repos/{owner}/{repo}/check-runs --input -


Is there are reason you're only deploying when a comment is made? Why not deploy on every push? As you mentioned end-to-end tests as well, this would be another type of thing that is usually run automatically rather than when a person adds a comment.

Upvotes: 1

Related Questions