gpt4 book ai didi

github - 检查 GitHub Actions 上的发布标签是否是最新的

转载 作者:行者123 更新时间:2023-12-03 08:04:10 29 4
gpt4 key购买 nike

我发布了两个标签:0.1.00.0.1。最新的发布标签是0.1.0

如何在 GitHub Action 内部检查工作流程是否由最新版本调度?

name: Test
on:
workflow_dispatch:
branches:
- main
release:
types: [published]
jobs:
test:
name: Test
runs-on: ubuntu-20.04
steps:
- run: echo ${{ github.ref_name }}

${{ github.ref_name }} 返回标签版本 0.1.00.0.1,我想像 GitHub 一样标记正在运行的 Docker 镜像:仅当操作由 0.1.0 调度时为 image:latest,即使 0.0.1,0.1.0 也是最新的 稍后发送,如下面的屏幕截图所示:

enter image description here

最佳答案

遗憾的是,github 上下文不提供此信息。

作为解决方法,您可以使用 git 命令检索最新版本:

git tag | sort --version-sort | tail -n1

然后将其与 github actions 上下文中的当前标签进行比较:

${{ github.ref_name }}

示例:

  - name: "Set latest tag"
id: set-latest-tag
run: echo "latest_tag=$(git tag | sort --version-sort | tail -n1)" >> $GITHUB_ENV

- name: "Tag Docker image as latest"
id: tag-as-latest
if: ${{ github.ref_name == env.latest_tag }}
run: |
...

关于github - 检查 GitHub Actions 上的发布标签是否是最新的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72950289/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com