Files
EntitleForge-SDK-go/.gitea/workflows/release.yml
T
iceking2nd 10c66cc30e
sdk-ci / test (push) Failing after 10s
fix(ci): runner 无 go 自举、发版流水线与文档绝对链接
- ci 加 actions/setup-go(此前 runner 无 go 直接失败);交叉编译笔误修正
- 新增 release.yml(v* tag:发布前测试 + Gitea Release + 源码包附件 +
  发版成功后清理失败 action 记录)
- README 相对链接(../EntitleForge)在 Gitea 网页 404 → 绝对 URL
2026-11-09 18:09:57 +08:00

64 lines
2.7 KiB
YAML

# 益铸 EntitleForge SDK 发布流水线(仅 v* tag 触发)。
# go module 库的"发版"即 git tag(客户 go get 直接引用);此流水线补齐:
# Gitea Release 记录 + 源码包附件,成功后清理失败的 action 记录。
name: sdk-release
on:
push:
tags: ["v*"]
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 记录
cleanup:
needs: release
if: success()
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 清理完成"