I have a GitHub Action workflow that runs to deploy a preview of a react-native expo app always when a Pull Request is opened. However, I do not want it to run when the dependabot opens a Pull Request.
How can I filter the dependabot Pull Requests? I saw there is a label dependencies
attached, but I could not make the label to be filtered.
A few attempts I tried:
name: Preview
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
if: ${{ !contains(github.event.pull_request.labels.*.name, '0 diff dependencies') }}
name: Preview
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
if: "!contains(github.event.pull_request.labels.*.name, '0 diff dependencies')"
name: Preview
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
if: "!contains(github.event.pull_request.labels.*.name, '0 dependencies')"
name: Preview
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
if: github.event.label.name != 'dependencies'
name: Preview
on:
pull_request:
types: [opened, synchronize]
jobs:
preview:
if: ${{ github.event.label.name != 'dependencies' }}
If you want, you can find here the repository.
2
Answers
Well, actually, there was a problem. Sometimes, the dependabot adds the label AFTER creating the Pull Request.
However, to solve it, it is possible to filter by user:
github.event.pull_request.labels
is an array, so you index its first element. Assuming dependabot will only assign one label, this should be OK:I just tested it on a dummy repo and it skipped my action when the PR label matched.