How to create filter on both tag and branch #25244
-
Hello everyone! We’ve spent quite some time trying to figure out how to create a workflow that will only be run for commits that are both on master and tagged with The workflow we have in mind for creating releases is as follows:
Once everything is fine, the branch (along with the tag) will be merged into master which is then supposed to trigger publishing a release both to github and pypi. If you’re interested, our project is: The filter variants we’ve tried are:
We’re now falling back to a solution where the workflow itself fails when the conditions are not met. How do other people do this? I know there is a release draft option but there is so much you can miss in a release code wise that we’d like to enforce reviews and tests on it before it’s actually published. |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
Based on current paths/tags filter for on: push event, it doesn’t supported to filter a commit which are included in a release tag meanwhile in master branch. There is a way to trigger a workflow when a new release published , using on: release: types: [published] Please refer to this document: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#release-event-release |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for your answer! That is actually what we do now. So once the release PR gets merged, we create a release manually. Once that release is published, it creates the tag and the corresponding pipeline pushes the package to pypi. Guess there isn’t really a way to do it fully automated. |
Beta Was this translation helpful? Give feedback.
-
Though I am replying to an old message, this is how I found the workaround. Create a filter on both tag and branch is to compare the hash commit of the tag and master. We can create a job that will check the hash commit. If the hash commit match than run another job to perform your desired actions. Else, if the hash commit don’t match you can make the workflow fail so that your next job doesn’t run. This is how I do it.
|
Beta Was this translation helpful? Give feedback.
-
Based on the answer of @khatiwadanilav I created an action which currently using in my workflows to only trigger jobs when a tag was pushed to a specific branch:
You can see this workflow in action here. I also send a feature request to the GitHub support to support this without using a workaround. Hope GitHub adds this feature soon. In the meantime, feel free to create an issue or a pull request onto my workaround if something is missing. |
Beta Was this translation helpful? Give feedback.
-
Thanks @rickstaa for sharing this workaround, |
Beta Was this translation helpful? Give feedback.
-
@benipeled At the time of writing, I could not find a public place to submit the feature request. I therefore followed the advice of Where do I post feature requests for Github ? - #22 by AndreaGriffiths11 and opened a private support ticket. I did not receive a response on that ticket. Feel free to create a feature request somewhere else if there is now a public place where a feature request can be submitted. |
Beta Was this translation helpful? Give feedback.
-
@rickstaa, yes they now call it discussions - submitted [0], btw, github recently released (public-beta) the “Protected Tags” feature [1] which might be helpful for this case by controlling who can push tags (admin & maintainers). [0] Trigger workflow on push-tag event to a specific branch · Discussion #13226 · github/feedback · GitHub |
Beta Was this translation helpful? Give feedback.
-
@benipeled Ah, thanks a lot for letting me know about the discussions and the “Protected Tags” feature! |
Beta Was this translation helpful? Give feedback.
Based on current paths/tags filter for on: push event, it doesn’t supported to filter a commit which are included in a release tag meanwhile in master branch.
There is a way to trigger a workflow when a new release published , using
on:
release:
types: [published]
Please refer to this document: https://help.github.com/en/actions/automating-your-workflow-with-github-actions/events-that-trigger-workflows#release-event-release