How to restrict execution of GitHub Actions workflow on tags creation only #24925
-
Hey guys! Been using GitHub Actions v2 (CI/CD) to implement publishing of npm packages when a new tag is pushed to our GitHub repo. I have looked into https://help.github.com/en/articles/workflow-syntax-for-github-actions#example-restricting-the-workflow-run-to-specific-refs-and-paths but can’t get it to work. Here’s a snippet of my workflow file:
Problem is when I push a new commit even with no tags it still gets triggered. I also tried using the Am I doing something wrong with filters? Would you have an alternative perhaps on how to trigger a workflow only when a new tag is created? Also, if I want to filter tags that have a @ sign, is that the way to do it?
Which should mean "Only run on tags that start with Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 13 comments 1 reply
-
I was just running into this. I solved just using a full ref path:
So I’m pretty sure you can then restrict to scopes like this:
I basically wanted to wildcard any tag push only, but this is the only way I could get it to work right. |
Beta Was this translation helpful? Give feedback.
-
Should it be with
Will give this a try, thanks! |
Beta Was this translation helpful? Give feedback.
-
Tags is just shorthand for My guess is |
Beta Was this translation helpful? Give feedback.
-
Worked like a charm, thanks a lot @pilotconway ! |
Beta Was this translation helpful? Give feedback.
-
I just ran into this myself - seems like a bug in Actions itself? The branches workaround seems fine for now but not properly descriptive IMO. |
Beta Was this translation helpful? Give feedback.
-
I agree, I have a couple work flows I really want to do something like, on _any_ tag push or these specific branches, but the docs don’t have a good way to mix and match like that either. I’m not sure if its not enough documentation or a lack of understanding on yaml on my part. |
Beta Was this translation helpful? Give feedback.
-
In fact it seems it works half and half, as in:
will only trigger when new tag is pushed, but , if I push a tag named _test-tag _for example it will still trigger the workflow. What I’m wondering is if this “filter” looks at all existing tags in refs/ and thus will match if you already have any “@orgname/*” tag present. Still confused by this whole workflow execution restriction thing, but hey its still beta 😉 |
Beta Was this translation helpful? Give feedback.
-
This is a bug that should be fixed this week. It should only trigger when a tag is pushed. |
Beta Was this translation helpful? Give feedback.
-
That are wonderful news. Thanks a lot! |
Beta Was this translation helpful? Give feedback.
-
did you manage to fix this error ? |
Beta Was this translation helpful? Give feedback.
-
This is still an issue for me, using the following syntax:
and I also tried the other suggestions. Doesn’t seem to work. I would like to build only for commits that are tagged. |
Beta Was this translation helpful? Give feedback.
-
Around here I can see the correct behavior (only execute only when the tag is pushed) when I fork the repo to my personal account, but it is triggered for every push on the organization’s repo. |
Beta Was this translation helpful? Give feedback.
-
This doesn’t work. It runs on every single commit regardless of whether the commit was tagged. Double-quotes, single-quotes - doesn’t matter. on: |
Beta Was this translation helpful? Give feedback.
I was just running into this. I solved just using a full ref path:
So I’m pretty sure you can then restrict to scopes like this:
I basically wanted to wildcard any tag push only, but this is the only way I could get it to work right.