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 <zgsm@sangfor.com.cn>
This commit is contained in:
parent
5de3460884
commit
de53813db3
17
.github/workflows/publish-npm.yml
vendored
17
.github/workflows/publish-npm.yml
vendored
|
|
@ -34,14 +34,23 @@ jobs:
|
||||||
run: |
|
run: |
|
||||||
RAW="${{ github.event.inputs.version || github.ref_name }}"
|
RAW="${{ github.event.inputs.version || github.ref_name }}"
|
||||||
RAW_NO_V="${RAW#v}"
|
RAW_NO_V="${RAW#v}"
|
||||||
if git rev-parse "v${RAW_NO_V}" >/dev/null 2>&1; then
|
TAG="v${RAW_NO_V}"
|
||||||
echo "tag=v${RAW_NO_V}" >> "$GITHUB_OUTPUT"
|
|
||||||
echo "ref=v${RAW_NO_V}" >> "$GITHUB_OUTPUT"
|
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
|
elif git rev-parse "${RAW}" >/dev/null 2>&1; then
|
||||||
echo "tag=${RAW}" >> "$GITHUB_OUTPUT"
|
echo "tag=${RAW}" >> "$GITHUB_OUTPUT"
|
||||||
echo "ref=${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
|
else
|
||||||
echo "Error: neither v${RAW_NO_V} nor ${RAW} exists" >&2
|
echo "Error: tag ${TAG} does not exist" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT"
|
echo "raw=${RAW_NO_V}" >> "$GITHUB_OUTPUT"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user