You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过GitHub Actions在推送develop分支时自动捕获并存储最新标签

问题:向私有仓库的develop分支推送变更时,自动捕获最新标签并存储到变量

我需要实现:向私有仓库的develop分支推送变更时,自动捕获最新标签并将其存储到变量中。

我曾尝试以下配置但未成功:

name: get-tag-version

on:
  push:
    branches:
      - develop
jobs:
  get-tag:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: "0"
      - name: catch tag
        run: tags=$(git describe --tags --all)
      - name: show tag
        run: echo "$tag"

CLI返回内容:

Run echo "$tag"
echo "$tag"
shell: /usr/bin/bash -e {0}


已解决

通过以下配置成功获取到标签:

describe-tags:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout Repository
        uses: actions/checkout@v2

      - name: Describe Tags
        run: |
          git fetch --prune --unshallow
          latest_tag=$(git describe --tags --abbrev=0 HEAD~)
          echo "Latest Tag: $latest_tag"

感谢!

内容的提问来源于stack exchange,提问作者Victor Antunes B.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.09 14:43:15