新增:registry-versions task(Go 套件庫版本,Go 專用邏輯留在 release-go)
ci / test (pull_request) Successful in 1s

This commit is contained in:
bot
2026-11-05 04:25:08 +00:00
parent 22a7a36130
commit da3f2c74bf
5 changed files with 83 additions and 6 deletions
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# 列出 Gitea Go 套件庫裡這個套件已有的版本(vX.Y.Z 或 vX.Y.Z-dev.N,一行一個,分頁讀完)。
# 手動發佈或標籤沒推成功時,套件庫會比 git 標籤新;呼叫端把清單傳給 next-version 的 extra_versions,才不會算出已存在的版本(上傳會回 409)。
# PACKAGES_API=<例如 https://gitea.jsc.idv.tw/api/v1/packages/<擁有者>?type=go&q=<套件名稱>> [GITEA_TOKEN=<需要 read:package>] registry-versions.sh
# 查詢失敗就整個失敗,不猜。
set -euo pipefail
api=${PACKAGES_API:?請設定 PACKAGES_API}
page=1
auth=()
[ -z "${GITEA_TOKEN:-}" ] || auth=(-H "Authorization: token $GITEA_TOKEN")
while :; do
body=$(curl -fsS --max-time 20 "${auth[@]}" "$api&limit=50&page=$page") || { echo "查詢套件庫版本失敗:$api" >&2; exit 1; }
found=$(printf %s "$body" | grep -oE '"version" *: *"v[0-9]+\.[0-9]+\.[0-9]+(-dev\.[0-9]+)?"' | grep -oE 'v[0-9]+\.[0-9]+\.[0-9]+(-dev\.[0-9]+)?' || true)
[ -n "$found" ] || exit 0
printf '%s\n' "$found"
page=$((page + 1))
done