Search code examples
githubgithub-actionscicd

Run GitHub Action when pushing commit but not on tag


In my GitHub repo, I have three different GitHub Actions (see here):

  • CI.yml
  • Mutation Testing.yml
  • Release.yml

The CI pipeline gets triggered on every commit:

on:
  push:
  pull_request:

The Release pipeline gets triggered whenever a new tag gets pushed:

on:
  push:
    tags:
      - '*'

But when pushing a new tag for a release, the CI pipeline also gets triggered and I want to avoid this. So I tried the following syntax for CI.yml (according to the docs):

on:
  push:
    tags-ignore:        
      - '*'
  pull_request:

But now the CI pipeline is not triggered anymore when pushing a new commit.

So what's the correct syntax for triggering a GitHub Action for a commit but not a tag?

Thx!


Solution

  • If you ignore branches or tags, you have to explicitly not ignore the other events you want to trigger on (see docs). So, if you want to ignore all tags, but trigger on all branches:

    on:
      push:
        tags-ignore:
          - '**'
        branches:
          - '**'
    

    Also, notice the * doesn't match the / character, so tags or branches with / would not be included.