From 171548d517a7b989ce720349887ab8a125977ea2 Mon Sep 17 00:00:00 2001 From: liyp Date: Fri, 23 Oct 2026 13:20:01 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E6=89=8B=E5=8A=A8=E8=BF=90=E8=A1=8C?= =?UTF-8?q?=E6=97=B6=20tag=20=E6=94=B9=E4=B8=BA=E5=8F=AF=E9=80=89=EF=BC=8C?= =?UTF-8?q?=E7=95=99=E7=A9=BA=E8=87=AA=E5=8A=A8=E5=8F=96=E6=9C=80=E6=96=B0?= =?UTF-8?q?=20tag?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - workflow_dispatch 的 tag 输入不再是必填,点 Run workflow 直接跑 - 留空时用 git describe --tags --abbrev=0 解析最新 tag - release job 的 checkout 改为 fetch-depth: 0,否则浅克隆里看不到 tag --- .github/workflows/release.yml | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 97b6bfd..5df8799 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,8 +11,9 @@ on: workflow_dispatch: inputs: tag: - description: "Tag to build and publish (for example v1.0.1)" - required: true + description: "Tag to build and publish; leave empty to use the latest tag" + required: false + default: "" type: string permissions: @@ -48,7 +49,10 @@ jobs: if: github.server_url == 'https://github.com' runs-on: ubuntu-latest steps: + # Full history and tags: a manual run resolves the tag with git describe. - uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: actions/setup-go@v5 with: @@ -58,11 +62,20 @@ jobs: - name: Resolve tag id: tag env: - DISPATCH_TAG: ${{ inputs.tag }} - PUSHED_TAG: ${{ github.ref_name }} + INPUT_TAG: ${{ inputs.tag }} + REF_NAME: ${{ github.ref_name }} + EVENT_NAME: ${{ github.event_name }} run: | set -euo pipefail - tag="${DISPATCH_TAG:-$PUSHED_TAG}" + tag="${INPUT_TAG:-}" + if [ -z "$tag" ]; then + if [ "$EVENT_NAME" = "push" ]; then + tag="$REF_NAME" + else + tag="$(git describe --tags --abbrev=0)" + fi + fi + [ -n "$tag" ] || { echo "no tag found, pass one explicitly" >&2; exit 1; } echo "value=$tag" >> "$GITHUB_OUTPUT" echo "building $tag"