skip to Main Content

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


  1. Chosen as BEST ANSWER

    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:

    name: Verification
    on:
      push:
        branches:
          - main
      pull_request:
        types: [opened, synchronize, reopened]
    
    jobs:
      verification:
        if: contains(github.actor, 'dependabot') == false
    

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search