Hey :wave: I have a repo with a GitHub action whi...
# github-actions
s
Hey 👋 I have a repo with a GitHub action which triggers on
push
to the master branch (when PRs get merged to master, I believe) I would like to add a couple of jobs that will run if the PR that just got merged to master had certain labels. The
push
event does not have a
labels
attribute, but the
pull_request
event does. I’m now wondering: is
Copy code
on:
  push:
    branches:
      - master # commits to master I believe
equivalent to:
Copy code
on:
  pull_request:
    branches:
      - master
    types: ["closed"] # I suspect that this would also be the same as the above commit to master. We auto-close PRs upon merging to master
If these two triggers are identical logically, then I can change the PR trigger from the former to the latter without breaking the existing jobs. I just want to be sure that it won’t break. If the two triggers are not logically similar, someone please explain to me how I can achieve what I am trying to without breaking the other older, existing jobs Thanks in advance
✅ 1
d
The best way I’ve found is to use the
pull_request
trigger and then check
if
the label is included in the job itself. For example:
Copy code
on:
  pull_request:
    types:
      - closed
    branches:
      - main

jobs:
  foo:
    if: ${{ github.event.pull_request.merged && !contains( github.event.pull_request.labels.*.name, 'mylabel') }}
👌 1
And the triggers you’ve mentioned are the same if you can only push to master through pull requests. Otherwise you could push directly to master and bypass the pull_request trigger Plus the GitHub event will have a different context on a push verse on a merged pull request. For example you can only get the pull request labels from the event on a closed PR
s
Thanks Dan. Much appreciated
np 1