68 lines
2.8 KiB
YAML
68 lines
2.8 KiB
YAML
# 益铸 EntitleForge SDK 发布流水线(仅 v* tag 触发)。
|
||
# go module 库的"发版"即 git tag(客户 go get 直接引用);此流水线补齐:
|
||
# Gitea Release 记录 + 源码包附件,成功后清理失败的 action 记录。
|
||
name: sdk-release
|
||
|
||
on:
|
||
push:
|
||
tags: ["v*"]
|
||
|
||
env:
|
||
GOPROXY: https://goproxy.cn,direct
|
||
GOSUMDB: "off"
|
||
|
||
jobs:
|
||
release:
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- uses: actions/checkout@v4
|
||
- uses: actions/setup-go@v5
|
||
with:
|
||
go-version: "1.27"
|
||
mirror: https://mirrors.aliyun.com/golang/
|
||
- name: 发布前测试(tag 必须指向全绿代码)
|
||
run: go test -race -shuffle=on ./...
|
||
|
||
- name: 创建 Release 并上传源码包
|
||
env:
|
||
GITEA_TOKEN: ${{ secrets.GITEA_PERSONAL_ACCESS_TOKEN }}
|
||
run: |
|
||
set -eu
|
||
API="${GITHUB_SERVER_URL}/api/v1"
|
||
REPO="${GITHUB_REPOSITORY}"
|
||
VERSION="${GITHUB_REF_NAME}"
|
||
tar -czf "entitleforge-sdk-${VERSION}.tar.gz" --exclude='.git' .
|
||
PAYLOAD=$(printf '{"tag_name":"%s","name":"益铸 EntitleForge SDK %s","body":"go get %s@%s(零第三方依赖)","draft":false,"prerelease":false}' \
|
||
"${VERSION}" "${VERSION}" "${REPO,,}" "${VERSION}")
|
||
curl -sS -X POST -H "Authorization: token ${GITEA_TOKEN}" \
|
||
-H "Content-Type: application/json" -d "${PAYLOAD}" \
|
||
"${API}/repos/${REPO}/releases" >/dev/null
|
||
echo "Release ${VERSION} 创建完成(go get 引用即发版本体)"
|
||
|
||
# 清理失败的 action 记录——always():release 失败时更要清理(否则失败轮次永久堆积)
|
||
cleanup:
|
||
needs: release
|
||
if: always()
|
||
runs-on: ubuntu-latest
|
||
steps:
|
||
- name: 清理失败的 workflow runs
|
||
env:
|
||
GITEA_TOKEN: ${{ secrets.GITEA_PERSONAL_ACCESS_TOKEN }}
|
||
run: |
|
||
set -eu
|
||
API="${GITHUB_SERVER_URL}/api/v1"
|
||
REPO="${GITHUB_REPOSITORY}"
|
||
PAGE=1
|
||
while :; do
|
||
RUNS=$(curl -sS -H "Authorization: token ${GITEA_TOKEN}" "${API}/repos/${REPO}/actions/tasks?limit=50&page=${PAGE}")
|
||
TOTAL=$(echo "${RUNS}" | python3 -c "import json,sys; print(json.load(sys.stdin).get('total_count',0))")
|
||
echo "${RUNS}" | python3 -c "import json,sys; [print(r['url']) for r in json.load(sys.stdin).get('workflow_runs',[]) if r.get('status')=='failure']" | while read -r url; do
|
||
RUN_API=$(echo "${url}" | sed "s|${GITHUB_SERVER_URL}/\\(.*\\)/actions/runs/|${API}/repos/\\1/actions/runs/|")
|
||
echo "删除失败 run: ${url}"
|
||
curl -sS -o /dev/null -X DELETE -H "Authorization: token ${GITEA_TOKEN}" "${RUN_API}"
|
||
done
|
||
[ "$((PAGE * 50))" -ge "${TOTAL}" ] && break
|
||
PAGE=$((PAGE + 1))
|
||
done
|
||
echo "失败 action 清理完成"
|