Search code examples
labelgithub-actionsworkflowpull-requestdependabot

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.


Solution

  • 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.