githubgithub-actions

Trigger Github Action only on new tags?


Is there a possibility to trigger a GitHub action only if a new version (which comes with a new tag) is pushed? I don't want run them on every push into master, but I also want to avoid creating a release branch.


Solution

  • Use the following syntax:

    on:
      push:
        # Pattern matched against refs/tags
        tags:        
          - '*'           # Push events to every tag not containing /
    

    For hierarchical tags:

    on:
      push:
        # Pattern matched against refs/tags
        tags:        
          - '**'           # Push events to every tag including hierarchical tags like v1.0/beta
    

    https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#patterns-to-match-branches-and-tags