Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Pilot Lvl 1
Message 1 of 18

How to run GitHub Actions Workflow only for new tags

Solved! Go to Solution.

Hello.

 

I have a Workflow that I only want to run when a new tag is pushed to the repository.

 

I have set the following "on" condition:

 

 
on:
  create:
    tags:
 
 
But my workflow is being executed also for branches.
 
What I am missing?
 
Thank you.
17 Replies
Ground Controller Lvl 1
Message 2 of 18

Re: How to run GitHub Actions Workflow only for new tags

+1

 

I've the same issue. It seems the tag filtering is not considered.

on:
  create:
    tags:
      - v*
Copilot Lvl 3
Message 3 of 18

Re: How to run GitHub Actions Workflow only for new tags

When I try to use on: I get a syntax error, e.g.

 

workflow "MyWorkflow" {
  on:
    create:
      tags:
        - v*
  resolves = ["MyAction"]
}

 

gives me 

 

unable to parse
Line 2: illegal char

This is in .github/main.workflow, right?

Copilot Lvl 3
Message 4 of 18

Re: How to run GitHub Actions Workflow only for new tags

Ah so GitHub have changed the syntax to YML, I've used their migration tool to get it "working". Well, for me this means that using the syntax above means that for every tag push, I get a failed build and a message saying No event triggers defined in on.

Copilot Lvl 3
Message 5 of 18

Re: How to run GitHub Actions Workflow only for new tags

Hmmm, that's super weird, somehow I got it working with the exact code from @ProvoK .

At first it wasn't working for me, then I tried the exact code from GitHub's workflow on syntax and specified an exact tag v1. This worked, then I changed back to @ProvoK's code and it started working. Not sure what it was.

 

My steps now are: change some code, commit, push code. Change some new code, commit again and push. Then tag when I'm happy, push the tag. The latest commit will get the code build, but the first one will not, as expected.

Copilot Lvl 3
Message 6 of 18

Re: How to run GitHub Actions Workflow only for new tags

Perhaps its because "create" also triggers when a branch is created, so it will run the filter on the first commit, then not until you actually create and push a new tag.

 

@brokge can you confirm that when you created the branch the workflow did not get triggered by the "create" action?

Pilot Lvl 1
Message 7 of 18

Re: How to run GitHub Actions Workflow only for new tags

 

It seems now that I cant even run workflows for tags:

 

I have this:

 

on:
  push:
    tags:
       - '*'

But the workflow is not running at all when a new tag is pushed

Ground Controller Lvl 1
Message 8 of 18

Re: How to run GitHub Actions Workflow only for new tags

@brpaz the code snippet you shared is for workflow
when a push happend on any tagged branch..

I don't think it will work for "when a new tag is created "

you code is similar  to the sample code from here  onpushpull_requesttagsbranches

Copilot Lvl 3
Message 9 of 18

Re: How to run GitHub Actions Workflow only for new tags

None of this is working.

 

This is triggered even when branches are created. The `tags` part is just ignored:

 

on:
  create:
    tags:
      - *

 

This will never be triggered:

 

on:
  push:
    tags:
      - *

 

This will never be triggered either:

 

on:
  push:
    branches:
      - 'refs/tags/*'

I'm creating tags with GitHub's own "Create release" button.

 

Can anyone document this feature? 

Solution
GitHub Staff
Message 10 of 18

Re: How to run GitHub Actions Workflow only for new tags

In your second example, you need to quote the asterisk, that's a YAML syntax requirement.  This should work:

 

on:
  push:
    tags:
    - '*'