From 10c66cc30e4b3c0aed20117fe63576deeafcd057 Mon Sep 17 00:00:00 2001 From: Daniel Wu Date: Mon, 9 Nov 2026 18:09:57 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20runner=20=E6=97=A0=20go=20=E8=87=AA?= =?UTF-8?q?=E4=B8=BE=E3=80=81=E5=8F=91=E7=89=88=E6=B5=81=E6=B0=B4=E7=BA=BF?= =?UTF-8?q?=E4=B8=8E=E6=96=87=E6=A1=A3=E7=BB=9D=E5=AF=B9=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - ci 加 actions/setup-go(此前 runner 无 go 直接失败);交叉编译笔误修正 - 新增 release.yml(v* tag:发布前测试 + Gitea Release + 源码包附件 + 发版成功后清理失败 action 记录) - README 相对链接(../EntitleForge)在 Gitea 网页 404 → 绝对 URL --- .gitea/workflows/ci.yml | 5 +++ .gitea/workflows/release.yml | 63 ++++++++++++++++++++++++++++++++++++ README.md | 4 +-- 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 4935fd4..2dbcc9e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -4,6 +4,7 @@ name: sdk-ci on: push: branches: ["*"] + tags: ["v*"] pull_request: env: @@ -14,6 +15,10 @@ jobs: 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: 全量测试(race + shuffle) run: go test -race -shuffle=on ./... - name: 依赖闭包断言(零第三方依赖红线) diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..8a75120 --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,63 @@ +# 益铸 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 清理完成" diff --git a/README.md b/README.md index 30885df..3bc7203 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ 益铸(EntitleForge)授权管理系统的客户端 SDK——**零第三方依赖**(纯 Go 标准库)。 -服务端与控制台见 [EntitleForge 主仓](../EntitleForge)。 +服务端与控制台见 [EntitleForge 主仓](https://git.wxccs.org/EntitleForge/EntitleForge)。 ## 引入 @@ -57,7 +57,7 @@ client.Check("module.x") // (bool, Reason)——GRACE/EXPIRED/REVO ## 与服务端的关系 本仓的 `license`/`crypto` 是协议实现的**单一归属**——服务端(EntitleForge 主仓)反向依赖本仓, -杜绝两套实现漂移([设计文档 §2](../EntitleForge/docs/design/07-sdk.md))。 +杜绝两套实现漂移([设计文档 §2](https://git.wxccs.org/EntitleForge/EntitleForge/blob/main/docs/design/07-sdk.md))。 ## 开发