Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

github actions: how to check if current push has new tag (is new release)?

name: test-publish  on: [push]  jobs:   test:     strategy:       ...     steps:       ...    publish:     needs: test     if: github.event_name == 'push' && github.ref???     steps:       ...  # eg: publish package to PyPI 

What should I put in jobs.publish.if in order to check that this commit is new release?

Is this okay: contains(github.ref, '/tags/')?

What will happen if I push code and tag at the same time?

like image 647
aiven Avatar asked Oct 20 '19 18:10

aiven


People also ask

How do I get latest tags in GitHub actions?

github action sets the git tag as an env var. run install & build. use chrislennon/action-aws-cli action to install aws cli using secrets for keys. run command to sync the build to a new S3 bucket using the tag env var as the dir name.

Does a GitHub release need a tag?

this action required a tag because GitHub releases do. That is not a bug. The push event that triggers the workflow run needs to be the push associated with a git push origin {tag} . The reason being that GitHub releases can only be created if GitHub servers know about the associated tag.

What is release and tag in GitHub?

Releases are based on Git tags, which mark a specific point in your repository's history. A tag date may be different than a release date since they can be created at different times. For more information about viewing your existing tags, see "Viewing your repository's releases and tags."


2 Answers

You could do this to check if the current push event is for a tag starting with v.

  publish:     needs: test     if: startsWith(github.ref, 'refs/tags/v') 

As you pointed out though, I don't think you can guarantee that this is a new release. My suggestion would be to use on: release instead of on: push. This will only trigger on a newly tagged release.

See the docs for on: release here: https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release

like image 195
peterevans Avatar answered Sep 25 '22 05:09

peterevans


An alternative way to use a GitHub Release as a trigger (in case if you want to use tags freely and release specific versions only):

on:   release:     types: [created]  jobs:   release-job:     name: Releasing     if: github.event_name == 'release' && github.event.action == 'created' 
like image 37
17 revs, 13 users 59% Avatar answered Sep 24 '22 05:09

17 revs, 13 users 59%