Files
publish-go/entrypoint.sh
T
2026-11-05 02:54:21 +00:00

18 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 發佈:上傳 build-go 產生的 zip → 成功才推送標籤。失敗不留遠端標籤;重跑時套件已存在(409)也視為已上傳,接著推標籤
set -euo pipefail
cd "${GITHUB_WORKSPACE:-$PWD}"
git config --global --add safe.directory "$PWD"
version=${INPUT_VERSION:?缺少 version}; token=${INPUT_TOKEN:?缺少 token}; zip=${INPUT_ZIP:?缺少 zip(build-go 的輸出)}
[ -f "$zip" ] || { echo "找不到 $zip:先執行 build-go" >&2; exit 1; }
git rev-parse -q --verify "refs/tags/$version" >/dev/null || { echo "本機沒有標籤 $version:先執行 build-go" >&2; exit 1; }
if ! out=$(GITEA_TOKEN="$token" GITEA_URL="$GITHUB_SERVER_URL" GITEA_OWNER="${GITHUB_REPOSITORY%%/*}" bash "$(dirname "${BASH_SOURCE[0]}")/go-module-upload.sh" "$zip" 2>&1); then
echo "$out" >&2
case "$out" in *已經存在*) echo "套件 $version 已上傳過,繼續推送標籤" >&2 ;; *) exit 1 ;; esac
else
echo "$out"
fi
remote="${GITHUB_SERVER_URL%%://*}://oauth2:${token}@${GITHUB_SERVER_URL#*://}/${GITHUB_REPOSITORY}.git"
git push "$remote" "refs/tags/$version"
echo "已推送標籤 $version"