Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to NOT run a GitHub Action when a specific label is set?

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.

like image 804
Lavínia Beghini Avatar asked Nov 30 '25 12:11

Lavínia Beghini


1 Answers

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:

name: Preview
on:
  pull_request:
    types: [opened, synchronize]
jobs:
  preview:
    if: github.event.pull_request.labels[0].name != 'dependencies'

I just tested it on a dummy repo and it skipped my action when the PR label matched.

like image 124
joanis Avatar answered Dec 03 '25 15:12

joanis



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!