Aiv*_*ven 24 git github github-actions
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
Run Code Online (Sandbox Code Playgroud)
我应该输入什么jobs.publish.if来检查这个提交是否是新版本?
可以吗:contains(github.ref, '/tags/')?
如果我同时推送代码和标签会发生什么?
pet*_*ans 33
您可以这样做来检查当前推送事件是否针对以 开头的标签v。
publish:
needs: test
if: startsWith(github.ref, 'refs/tags/v')
Run Code Online (Sandbox Code Playgroud)
不过,正如您所指出的,我认为您不能保证这是一个新版本。我的建议是使用on: release而不是on: push. 这只会在新标记的版本上触发。
请参阅on: release此处的文档:https :
//docs.github.com/en/actions/reference/events-that-trigger-workflows#release
使用 GitHub Release 作为触发器的另一种方法(如果您想自由使用标签并仅发布特定版本):
on:
release:
types: [created]
jobs:
release-job:
name: Releasing
if: github.event_name == 'release' && github.event.action == 'created'
Run Code Online (Sandbox Code Playgroud)
小智 5
您可以用来github.ref_type检查触发工作流程运行的引用类型。
触发工作流运行的引用类型。有效值为
branch或tag。
publish:
needs: test
if: github.ref_type == 'tag'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8119 次 |
| 最近记录: |