I want to trigger an action when the following constraints fulfilled.
pr merged to main branch AND pr contains label == 'site'.
This is what I came up with, the problem that this one is running when the pr is created.
Nothing happens when I merge it to main.
What am I doing wrong?
name: Build and push site
on:
pull_request:
branches: [main]
types: [labeled, closed]
jobs:
build-push-site:
if: github.event.pull_request.merged == true && contains( github.event.pull_request.labels.*.name, 'site')
uses: avifatal/nx-tokenct/.github/workflows/build-push.yml@main
with:
...
(inspired by this Run Github Actions when pull requests have a specific label)
Thanks
Do not work on "labeled" branches just because you want to check the label. This check is done later. Work on "labeled" branches only if you want to trigger the action each time the PR is labelled.
To trigger the action at merge, work on "closed" branches and check the merge as below.
This code will execute when PR is closed, and check that
sitename: Build and push site
on:
pull_request:
types:
- closed
jobs:
build-push-site:
if: ${{ (github.event.pull_request.merged == true) && (contains(github.event.pull_request.labels.*.name, 'site')) }}
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With