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:
@@ -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"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user