From 287d098e061b2e0f08707c7f771f66ef560ebdb2 Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Wed, 15 Jul 2026 09:37:57 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20release=20upload=20=E6=94=B9=E7=94=A8=20G?= =?UTF-8?q?itea=20API=20=E7=9B=B4=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit softprops/action-gh-release@v2 在 Gitea 上偶发不工作, 改用 Gitea 原生 API: POST /repos/{owner}/{repo}/releases <- 创建 release POST /repos/{owner}/{repo}/releases/{id}/assets <- 上传 binary token 走 secrets.GITHUB_TOKEN (Gitea 自动注入平台 token), api_url 走 \${{ github.api_url }} (Gitea 自动解析). RELEASE_ID 从 POST /releases 响应 grep 出来 (用 -oP "id":\s*\K[0-9]+). - PCRE 模式 (grep -P) 依赖 GNU grep, ubuntu 镜像自带有, alpine runner 需要补 pcre 工具. 跟之前去 jq 一样是 runner 镜像依赖, 这次保留因为已经在用 \${{ secrets.GITHUB_TOKEN }} 这种 GitHub 风格 secret, runner 假定 ubuntu-family. asset 上传字段是 attachment (Gitea API 文档要求, 不是 name). Co-Authored-By: Claude --- .github/workflows/build.yml | 38 ++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5c4e2e8..f9b3417 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,11 +71,39 @@ jobs: - name: Build release binary run: GOOS=linux GOARCH=amd64 go build -o spark-mcp-linux-amd64 ./main.go - - name: Upload release asset - uses: softprops/action-gh-release@v2 - with: - files: spark-mcp-linux-amd64 - generate_release_notes: true + - name: Upload release asset via Gitea API + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + # 1. 获取当前 Tag 名字 (例如 v0.0.1-beta) + TAG_NAME="${{ github.ref_name }}" + + echo "正在为 Tag ${TAG_NAME} 创建 Gitea Release..." + + # 2. 调用 Gitea API 创建一个 Release 并获取其 ID + # 注意:${{ github.api_url }} 会自动解析为你本地 Gitea 的 API 地址 (如 http://your-gitea/api/v1) + RELEASE_ID=$(curl -X POST "${{ github.api_url }}/repos/${{ github.repository }}/releases" \ + -H "accept: application/json" \ + -H "authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{ + \"tag_name\": \"${TAG_NAME}\", + \"target_commitish\": \"${{ github.sha }}\", + \"name\": \"Release ${TAG_NAME}\", + \"body\": \"Auto generated release assets.\", + \"draft\": false, + \"prerelease\": false + }" | grep -oP '"id":\s*\K[0-9]+' | head -n 1) + + echo "Release 创建成功,ID 为: ${RELEASE_ID}" + + # 3. 将你的二进制文件上传到该 Release 中 + echo "开始上传文件 spark-mcp-linux-amd64 ..." + curl -X POST "${{ github.api_url }}/repos/${{ github.repository }}/releases/${RELEASE_ID}/assets" \ + -H "accept: application/json" \ + -H "authorization: token ${GITEA_TOKEN}" \ + -H "Content-Type: multipart/form-data" \ + -F "attachment=@spark-mcp-linux-amd64" - name: Notify release via Bark if: success()