From e5f7d661b4aceaef68d14f4400b7a0cb8093d9a3 Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Wed, 15 Jul 2026 18:40:43 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E5=88=87=E5=88=B0=20Gitea=20golang-1.25?= =?UTF-8?q?=20runner,=20alpine=20=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitea runner 现在用 golang-1.25 标签 (alpine + Go 1.25 预装), 不 再需要 wget + tar 装 Go. 删 "Install Go (Mirror in China)" step, 保留 GOPROXY 设置 (alpine 默认 GOPROXY=proxy.golang.org, 国内 runner 慢). runner: golang-1.25 (两 job 都改) step 1: actions/checkout@v4 (alpine 已有, 不需要 apt 装 git) step 2: "Set GOPROXY" 写 \$GITHUB_ENV, 后续 step 继承 (https://goproxy.cn/,https://goproxy.io,direct) grep -P 兼容性 fix: alpine busybox grep 不支持 -P (PCRE). 之前 release job 用 grep -oP '"id":\s*\K[0-9]+' 拆 release id, 在 alpine 上会 "grep: unrecognized option". 改两次 grep -o: grep -o '"id":[0-9]*' | head -n 1 | grep -o '[0-9]*' 第 1 个 grep 拉出 "id":, 第 2 个去掉引号和 key 名. 不依赖 -P, POSIX grep 也跑. Co-Authored-By: Claude --- .github/workflows/build.yml | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a464ce..f936826 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,9 +2,10 @@ # It performs CI on every push to main and every pull request, and automatically # builds and attaches a Linux amd64 release binary when a version tag (v*) is pushed. # -# Go is installed manually from a Chinese mirror (NJU) instead of using -# actions/setup-go, because the runner is in a region where the official Go -# download endpoint is slow. GOPROXY is set to goproxy.cn for the same reason. +# Runner: golang-1.25 (Gitea-managed image, alpine + Go 1.25 preinstalled). +# No Go installation step needed. GOPROXY is set explicitly to use the +# China-region mirrors (default alpine GOPROXY is proxy.golang.org, which +# is slow from this runner's network). name: CI / Release on: @@ -18,19 +19,13 @@ on: jobs: ci: name: CI - runs-on: ubuntu-latest + runs-on: golang-1.25 steps: - name: Checkout uses: actions/checkout@v4 - - name: Install Go (Mirror in China) + - name: Set GOPROXY run: | - if [ ! -d "/usr/local/go" ]; then - wget https://mirrors.nju.edu.cn/golang/go1.25.5.linux-amd64.tar.gz - sudo tar -C /usr/local -xzf go1.25.5.linux-amd64.tar.gz - rm go1.25.5.linux-amd64.tar.gz - fi - echo "/usr/local/go/bin" >> $GITHUB_PATH echo "GOPROXY=https://goproxy.cn/,https://goproxy.io,direct" >> $GITHUB_ENV - name: Build @@ -66,19 +61,13 @@ jobs: name: Release needs: ci if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest + runs-on: golang-1.25 steps: - name: Checkout uses: actions/checkout@v4 - - name: Install Go (Mirror in China) + - name: Set GOPROXY run: | - if [ ! -d "/usr/local/go" ]; then - wget https://mirrors.nju.edu.cn/golang/go1.25.5.linux-amd64.tar.gz - sudo tar -C /usr/local -xzf go1.25.5.linux-amd64.tar.gz - rm go1.25.5.linux-amd64.tar.gz - fi - echo "/usr/local/go/bin" >> $GITHUB_PATH echo "GOPROXY=https://goproxy.cn/,https://goproxy.io,direct" >> $GITHUB_ENV - name: Build release binary @@ -95,6 +84,7 @@ jobs: # 2. 调用 Gitea API 创建一个 Release 并获取其 ID # 注意:${{ github.api_url }} 会自动解析为你本地 Gitea 的 API 地址 (如 http://your-gitea/api/v1) + # alpine busybox grep 不支持 -P (PCRE), 改用两次 grep -o 拆 id RELEASE_ID=$(curl -X POST "${{ github.api_url }}/repos/${{ github.repository }}/releases" \ -H "accept: application/json" \ -H "authorization: token ${GITEA_TOKEN}" \ @@ -106,7 +96,7 @@ jobs: \"body\": \"Auto generated release assets.\", \"draft\": false, \"prerelease\": false - }" | grep -oP '"id":\s*\K[0-9]+' | head -n 1) + }" | grep -o '"id":[0-9]*' | head -n 1 | grep -o '[0-9]*') echo "Release 创建成功,ID 为: ${RELEASE_ID}"