github - 如何使用 GitHub Actions 对构建工件进行版本控制?

标签 github automation versioning continuous-delivery github-actions

我的用例是我希望每个构建/运行的工件都有一个唯一的版本号。对于 CircleCI、Travis 等当前工具,有一个可用的内部版本号,它基本上是一个始终上升的计数器。因此,我可以创建像 0.1.0-27 这样的版本字符串。即使对于相同的提交,该计数器每次都会增加。

我如何使用 GitHub Actions 做类似的事情? Github 操作仅提供 GITHUB_SHA 和 GITHUB_REF。

最佳答案

GitHub Actions 现在拥有用于在 github 上下文中运行/构建的唯一编号和 ID。

github.run_id : A unique number for each workflow run within a repository. This number does not change if you re-run the workflow run.

github.run_number : A unique number for each run of a particular workflow in a repository. This number begins at 1 for the workflow's first run, and increments with each new run. This number does not change if you re-run the workflow run.

github.run_attempt : A unique number for each attempt of a particular workflow run in a repository. This number begins at 1 for the workflow run's first attempt, and increments with each re-run.

引用:https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#github-context

您可以在工作流程中引用它们,如下所示:

- name: Output Run ID
  run: echo ${{ github.run_id }}
- name: Output Run Number
  run: echo ${{ github.run_number }}
- name: Output Run Attempt
  run: echo ${{ github.run_attempt }}

关于github - 如何使用 GitHub Actions 对构建工件进行版本控制?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54310050/

相关文章:

linux - 如何将提交从一个 Git 存储库复制到另一个?

git - 重命名 GitHub 组织会影响该组织项目的分支吗?

selenium - 如何在 TestNG.xml 中确定包执行的优先级?

elasticsearch - 自动进行logstash配置更改

javascript - Protractor - 当元素不可见且不执行 "else"条件时测试失败

java - 如何比较字符串列表中的元素与字符串数组列表?

git - git branch --set-upstream-to 与 git remote add origin 之间的区别

java - 清理代码会破坏二进制兼容性

ios - 将 agvtool 与一个目录中的多个 .xcodeproject 文件一起使用

github - 为所有 github 存储库生成 jenkins 作业