github动作:如何检查当前推送是否具有新标签(是新版本)?

时间:2019-10-20 18:00:00

标签: git github github-actions

dictionary_in_question = {"name" : "Value", "1":"1.3"}
new_dict = {}
for k,v in dictionary_in_question.items():
     if k.isdigit() or v.isdigit():
         new_dict[k] = v

我应该在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

如果我同时推送代码和标签会怎样?

2 个答案:

答案 0 :(得分:4)

使用 GitHub Release 作为触发器的另一种方法(如果您想自由使用标签并仅发布特定版本):

on:
  release:
    types: [created]

jobs:
  release-job:
    name: Releasing
    if: github.event_name == 'release' && github.event.action == 'created'

答案 1 :(得分:3)

您可以执行此操作以检查当前的推送事件是否针对以v开头的标签。

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

但是,正如您指出的那样,我认为您不能保证这是一个新版本。我的建议是使用on: release而不是on: push。这只会在新标记的版本上触发。

在此处查看on: release的文档: https://help.github.com/en/articles/events-that-trigger-workflows#release-event-release