avoid double builds when reacting on conditional tag event


I try to set up a CI build that runs a normal build when something gets pushed to master. (https://github.com/esrlabs/chipmunk/actions)

this is the trigger section of my workflow:

name: Main

on: push

so that is clear.

What I now try to do is to have a conditional step that is only executed if a tag is pushed

- name: Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')

now when I push some commit to master and also tag it, I have 2 git-level operations and this results in running my workflow twice. But since the tag command triggers actions that include those I get on a push command, I’d like to skip this and only react to the tag command.

I tried the –follow-tags option for the git push command but apparently this still ends up in 2 distinct git operations.

Is there a way to avoid the first trigger in case of a pushed git tag?

You can configure push to only trigger for tags, see https://help.github.com/en/github/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#onpushpull_requestbranchestags for more details.

thanks for your response @chrispat 

I know I can restrict my workflow to be triggered only on push events that push a tag to GitHub.

my case is different:

  1. I want to trigger my workflow for each push event (no tag needed). works fine.
  2. now let’s say after a couple of commits I want to create a release: so I tag my commit and push the tag
  3. I would want to take the artifacts that were built by my workflow triggered by a regular git push commit
  4. but I don’t have access to the previously triggered workflow so I have to trigger a completely new build and upload the artifacts of this build

what I would want is to atomically push one commit including the tag to GitHub. but those are 2 separate triggers.

a solution could look like:

  • trigger a build on the push commit event
    • this will first check out the sources and then do the build
  • after the build, fetch all tags from the repository to find out if a tag exists for the commit I just checked out and built
  • if such a tag exists, create a release on GitHub and upload the artifacts

I too would find this very helpful.