How to ignore branches for delete events?

Hello,

I’m creating a workflow for when branches are deleted. I want to ignore when certain branches are deleted. I’ve tried the following, but they have all been triggered when I have deleted my-fake-branch

on: 
  delete:
    branches-ignore:
      - main
      - staging
      - my-fake-branch
on: 
  delete:
    branches-ignore:
      - 'main'
      - 'staging'
      - 'my-fake-branch'
on: 
  delete:
    branches:
      - '*'
      - '!main'
      - '!staging'
      - '!my-fake-branch'
on: 
  delete:
    branches-ignore:
      - 'refs/heads/main'
      - 'refs/heads/staging'
      - 'refs/heads/my-fake-branch'

There are only two types of events that support the keys branches, branches-ignore, tags, and tags-ignore as far as I see: push and pull_request:

on.<push|pull_request>.<branches|tags>

As a workaround, you could add if conditionals to all of the jobs in that workflow to at least skip their execution, like this:

on: delete
jobs:
  job1:
    if: >-
      github.ref != 'refs/heads/main' &&
      github.ref != 'refs/heads/staging' &&
      github.ref != 'refs/heads/my-fake-branch'
...

Ah, thanks for explaining the docs syntax to me. I missed that.

1 Like