I’m trying to run a GitHub Action every time a PR is opened or reopened. The GHA triggered on opening works fine.
The GHA triggered by the reopening should run some checks and wait for some minutes before letting the "normal" installation steps reinstall the software, otherwise there’s a race condition: the deletion step takes a while, meanwhile the reinstallation step sees that everything is still installed, and happily exits; after a while the deletion is finished, and the state of the installation is broken because no software is installed once the PR is reopened.
on:
pull_request:
types: [opened, reopened]
jobs:
wait-on-pr-reopening:
runs-on: ubuntu-latest
if: github.event.pull_request.reopened == true
steps:
- name: Wait for deletion to complete before proceeding with reinstallation
run: |
# here there's some logic to check that the GHA that runs when PR is closed is done
install-app:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: |
# here goes the normal installation GHA that should be executed at PR reopening too,
# but only after the deletion is completed
The problem is that the if condition if: github.event.pull_request.reopened
(I tried with both == true
and without) is always skipped.
Is that the correct value to filter on?
Is there another way to synchronize the state when reopening a PR?
2
Answers
There's indeed no variable at
github.event.pull_request.reopened
, so that was probably being evaluated asnull
and the step skipped.@azeem's suggestion worked like a charm instead:
I had to move the step into the main job because I needed the condition to run before the main installation step, not in parallel
According to
pull_request
event payload, there’s thisaction
field that you can use to achieve that. Also, if you want to filter on the specific event, you can usegithub.event_name
to do that.Combining above will give you something like this to enable/disable a job/step based on
pull_request
event and its actionreopened
:Currently, the workflow in your question only has
pull_request
trigger so you can skipgithub.event_name
altogether and that should work too:But, do this if and only if your workflow won’t have any other event.