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?
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.
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.
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."
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
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With