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
我应该放什么
jobs.publish.if
为了检查这个提交是新版本?可以吗:
contains(github.ref, '/tags/')
?如果我同时推送代码和标签会发生什么?
最佳答案
您可以这样做来检查当前推送事件是否针对以 v
开头的标签。 .
publish:
needs: test
if: startsWith(github.ref, 'refs/tags/v')
不过,正如您所指出的,我认为您不能保证这是一个新版本。我的建议是使用 on: release
而不是 on: push
.这只会在新标记的版本上触发。请参阅
on: release
的文档这里:https://docs.github.com/en/actions/reference/events-that-trigger-workflows#release
关于github 操作 : how to check if current push has new tag (is new release)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58475748/