From de53813db33c3c0b268233bb051198f0c0461a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E5=87=AF90331?= <90331@sangfor.com> Date: Thu, 14 May 2026 16:37:35 +0800 Subject: [PATCH] ci(publish-npm): auto-create missing tag on manual dispatch When triggering the publish workflow manually with a version that does not yet have a corresponding git tag, automatically create and push the v-prefixed tag on the current HEAD instead of failing. Co-authored-by: CoStrict --- .github/workflows/publish-npm.yml | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.github/workflows/publish-npm.yml b/.github/workflows/publish-npm.yml index cb461a7da..b4d73c683 100644 --- a/.github/workflows/publish-npm.yml +++ b/.github/workflows/publish-npm.yml @@ -34,14 +34,23 @@ jobs: run: | RAW="${{ github.event.inputs.version || github.ref_name }}" RAW_NO_V="${RAW#v}" - if git rev-parse "v${RAW_NO_V}" >/dev/null 2>&1; then - echo "tag=v${RAW_NO_V}" >> "$GITHUB_OUTPUT" - echo "ref=v${RAW_NO_V}" >> "$GITHUB_OUTPUT" + TAG="v${RAW_NO_V}" + + if git rev-parse "${TAG}" >/dev/null 2>&1; then + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + echo "ref=${TAG}" >> "$GITHUB_OUTPUT" elif git rev-parse "${RAW}" >/dev/null 2>&1; then echo "tag=${RAW}" >> "$GITHUB_OUTPUT" echo "ref=${RAW}" >> "$GITHUB_OUTPUT" + elif [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git tag "${TAG}" + git push origin "${TAG}" + echo "tag=${TAG}" >> "$GITHUB_OUTPUT" + echo "ref=${TAG}" >> "$GITHUB_OUTPUT" else - echo "Error: neither v${RAW_NO_V} nor ${RAW} exists" >&2 + echo "Error: tag ${TAG} does not exist" >&2 exit 1 fi echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT"