ci: 手动运行时 tag 改为可选,留空自动取最新 tag

- workflow_dispatch 的 tag 输入不再是必填,点 Run workflow 直接跑
- 留空时用 git describe --tags --abbrev=0 解析最新 tag
- release job 的 checkout 改为 fetch-depth: 0,否则浅克隆里看不到 tag
This commit is contained in:
liyp
2026-10-23 13:20:01 +08:00
parent c3af8b4ab9
commit 171548d517
+18 -5
View File
@@ -11,8 +11,9 @@ on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
tag: tag:
description: "Tag to build and publish (for example v1.0.1)" description: "Tag to build and publish; leave empty to use the latest tag"
required: true required: false
default: ""
type: string type: string
permissions: permissions:
@@ -48,7 +49,10 @@ jobs:
if: github.server_url == 'https://github.com' if: github.server_url == 'https://github.com'
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
# Full history and tags: a manual run resolves the tag with git describe.
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v5 - uses: actions/setup-go@v5
with: with:
@@ -58,11 +62,20 @@ jobs:
- name: Resolve tag - name: Resolve tag
id: tag id: tag
env: env:
DISPATCH_TAG: ${{ inputs.tag }} INPUT_TAG: ${{ inputs.tag }}
PUSHED_TAG: ${{ github.ref_name }} REF_NAME: ${{ github.ref_name }}
EVENT_NAME: ${{ github.event_name }}
run: | run: |
set -euo pipefail 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 "value=$tag" >> "$GITHUB_OUTPUT"
echo "building $tag" echo "building $tag"