'In GitHub Actions, how can I trigger on push but only if a PR is active?
Say I have 2 branches, a feature branch and a develop branch.
There's no SLA on feature branch normally, meaning I can push broken code up to it all day long and no CI build should be triggered.
Then I open a PR into develop. I trigger a CI build action on pull_request: created. Let's say this build fails. By default I can't merge the PR, which is correct.
Now I want to push edits to feature branch to update the PR. I want these pushes to trigger a CI build (because we're now working inside an open PR). I don't want to allow the PR to proceed/be merged until these push-CIs pass.
How can I do that in GitHub Actions? I tried on pull_request: edited
but that didn't work for me.
I'm looking for the functional equivalent of:
on:
push:
if: inside_open_pr
Solution 1:[1]
Use the event pull_request
and don't specify activities or specify the activity synchronize
:
on:
pull_request:
Note: By default, a workflow only runs when a
pull_request
's activity type isopened
,synchronize
, orreopened
. To trigger workflows for more activity types, use the types keyword.
if you push a new commit to the HEAD ref of a pull request then this “synchronize” event will be triggered. This is because the system is syncing the pull requests with the latest changes. This will NOT trigger if the base ref is updated.
If you also need to react to a change of the base branch, then you have to add the activity edited
.
Solution 2:[2]
If pull_request
is not an option, you can try using https://github.com/marketplace/actions/get-current-pull-request
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Kushagra Gour |