Search code examples
githubgithub-apigithub-actions

How to link a GitHub Actions manual run to a PR


For a variety of reasons, I need to manually trigger a GitHub Actions run from a comment on a PR mentioning a bot (I’m using ProBot). I figured out how to start the workflow by setting the start to on: workflow_dispatch and calling the API. Where I’m running into an issue is linking the run to the PR. Right now, the action just starts and completes without ever appearing in the checks section of the PR.

I noticed that there is a checks create method on the API, but it seems more geared towards making your own check suite. I could use that to create a check run, manually watching the GitHub Actions process, and appropriately updating the check run, but it seems like overkill. I haven’t seen anything in The API that would allow this to happen. There may be a way to do it from the action itself too, but I haven’t found anything.


Solution

  • I don't think you can use workflow_dispatch to add/update checks on a PR. This seems to be confirmed by this response to a similar question on the community forums.

    Checks are only added/updated for the following events:

    • pull_request
    • pull_request_review
    • pull_request_review_comment
    • pull_request_target
    • push

    So your manual operation needs to trigger one of these events to run. There are probably a number of different ways you can do this, depending on your use case. Just as an example, you could call the API to add a label and allow a pull_request workflow to execute on that type.

    on:
      pull_request:
        types: [labeled, opened, synchronize, reopened]
    

    The other thing to note is that the API call (or git push) must use a PAT instead of GITHUB_TOKEN. This is to allow further workflows to execute.