79743944

Date: 2025-08-23 00:40:20
Score: 1.5
Natty:
Report link

I want to comment in a PR and trigger a check on that PR (not on master)

I think all the other answers are missing this point. They all test things on your branch as opposed to main but they do not report these tests on the PR without creating a commit.

To report things on your branch you'll need to handle commit creation:

- name: Get PR info and set pending status
        id: pr
        uses: actions/github-script@v7
        with:
          script: |
            const { data: pr } = await github.rest.pulls.get({
              owner: context.repo.owner,
              repo: context.repo.repo,
              pull_number: context.issue.number
            });
            
            await github.rest.repos.createCommitStatus({
              owner: context.repo.owner,
              repo: context.repo.repo,
              sha: pr.head.sha,
              state: 'pending',
              target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
              description: 'Running integration tests...',
              context: 'Integration Tests'
            });
            
            core.setOutput('head_sha', pr.head.sha);
            core.setOutput('head_ref', pr.head.ref);

and then set the final status:

      - name: Set final status
        if: always()
        uses: actions/github-script@v7
        with:
          script: |
            const state = '${{ job.status }}' === 'success' ? 'success' : 'failure';
            
            await github.rest.repos.createCommitStatus({
              owner: context.repo.owner,
              repo: context.repo.repo,
              sha: '${{ steps.pr.outputs.head_sha }}',
              state: state,
              target_url: `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`,
              description: `Integration tests ${state}`,
              context: 'Integration Tests'
            });

wrote a sample repo for this with the CI workflow:

https://github.com/luccabb/git-ci-pr-comment-automation

You can test for yourself on PR2, if you comment '/bot tests', it triggers a ci job that fails due to the changes introduced by the PR

Reasons:
  • Blacklisted phrase (1): to comment
  • RegEx Blacklisted phrase (1): I want
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Lucca B