How to run GitHub Actions Workflow only for new tags

Hi @ethomson, even when adding quotes around my tags

on:
  create:
    tags:
    - 'v[0-9]+.[0-9]+.[0-9]+*'

my workflow is triggered when pushing to a new branch (without any tags)

git push --set-upstream origin my-new-branch

Is it possible that the on.create.tags filter does not work?

https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestbranchestags

The docs have no indication that on.create.tags exists that I see. tags filter only exists for push and pull_request.

5 Likes

Thanks @lucianposton, I retried the 

on.push.tags

and it is the right event for me. I originally thought that creating the tag directly from the GitHub interface would not be considered a push, but you made me reconsider and you saved me some time. Thanks

1 Like

I got it to work with

on:
  push:
    tags:
      - '*'

I found out that if the tag was previously created (locally) before the workflow was created, no matter how many times I deleted and re-pushed the tag, it would not trigger until I deleted the tag locally and recreated it. The action does not seem to work for tags created before the workflow. Hope that helps someone.

2 Likes

That is the expected behavior. When an event occurs, workflow file is searched in the associated commit SHA version of the repository.

This answer in other thread can help you.

Has anyone ween able to trigger an action on workflow_run when the commit is tagged? I’ve tried

on:
  workflow_run:
    workflows:
    - Build
    types:
    - completed
    tags:
    - '*'

but it does not trigger. Triggering only on workflow_run or only on push.tags.* works fine.

1 Like

I use the following way:

on:
  push:
    branches:
      - "!*"
    tags:
      - "v*"
2 Likes

Worked for me, thanks so much!

Yes, this is a lifesaver, you can use the push event instead