From 6089b86935bae0ee488f11955366e129253958f9 Mon Sep 17 00:00:00 2001 From: JianFeeeee Date: Wed, 7 Oct 2026 06:40:24 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20main=20=E8=BF=87=E5=85=A8=E9=83=A8?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=90=8E=E8=87=AA=E5=8A=A8=E5=BF=AB=E8=BF=9B?= =?UTF-8?q?=20gitcode=20=E9=95=9C=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 背景 gitcode 的定位是**只读镜像**(ci-cd-runbook §0),但既有 sync job 只在 release.yml 里推 **tag** —— main 分支从不同步。镜像的 main 停在 09-29、 与主仓分叉 768/746,本次已手工 force push 对齐一次(审计确认 github 是 严格超集,gitcode 无独有内容后才做的)。 光对齐一次,下个月还会旧 —— 镜像的单向性应该由 CI 保证,不靠人记。 ## 改动 ci.yml 新增 sync-gitcode-main job: - **needs 全部 6 个必需检查**(go/race/cross/gui/csrc/docs): 红的代码不进镜像 —— 镜像永远等于「过了 CI 的 main」 - **只在 main 的 push 上跑**(feature/release 不镜像,与 tag 语义一致) - 未配置 GITCODE_TOKEN 时**显式跳过**(与 release.yml 的 sync-gitcode 同口径,不阻断 GitHub 侧 CI) - **快进 push(非 force)**:正常流水线下镜像只可能落后不可能领先; 出现非快进说明有人绕过 CI 动过镜像 ⇒ 响亮失败而非悄悄覆盖, 那是「单向性被破坏」的信号,值得一次人工确认 - checkout 用 fetch-depth: 0:镜像可能在任意旧提交上,快进需要共同祖先 ## 验证 - yaml 可解析;job 名与 needs 引用逐一核对 - 10 项分支保护必需 context 不受影响(本 job 是新增,不在保护清单) Co-Authored-By: Claude Opus 4.8 (1M context) --- .github/workflows/ci.yml | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7200da74..df1f30e1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -204,3 +204,50 @@ jobs: echo "无 mkdocs.yml,跳过" fi test -d docs || echo "无 docs/,跳过" + + # ── gitcode 镜像同步(main 分支)── + # + # 背景(2026-10-06 审计):gitcode 的定位是**只读镜像**(ci-cd-runbook §0), + # 但既有 sync job 只在 release.yml 里推 **tag** —— main 分支从不同步, + # 导致镜像的 main 停在 09-29、与主仓分叉 768/746(当时已 force push 对齐一次)。 + # + # 本 job 把「镜像 = 主仓」交给 CI 保证:main 每次推送且**全部必需检查通过后** + # 才快进镜像分支 —— 红的代码不进镜像,镜像永远等于主仓。 + # + # - 只处理 main(feature/release 分支不镜像,与 tag 语义一致)。 + # - 未配置 GITCODE_TOKEN 时显式跳过(与 release.yml 的 sync-gitcode 同口径, + # 不阻断 GitHub 侧 CI)。 + # - 用快进 push(非 force):正常流水线下镜像只可能落后,不可能领先; + # 若出现非快进说明有人动过镜像,此时响亮失败而不是悄悄覆盖 —— + # 镜像被旁路写入是「单向性被破坏」的信号,值得一次人工确认。 + sync-gitcode-main: + name: Sync main to gitcode (mirror) + runs-on: ubuntu-latest + needs: [go, race, cross, gui, csrc, docs] + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + timeout-minutes: 10 + steps: + - id: tok + name: 检查 gitcode 凭据 + run: | + if [ -n "${{ secrets.GITCODE_TOKEN }}" ]; then + echo "ok=true" >> "$GITHUB_OUTPUT" + else + echo "ok=false" >> "$GITHUB_OUTPUT" + echo " 未配置 GITCODE_TOKEN —— 跳过 gitcode main 同步" + fi + - uses: actions/checkout@v7 + if: steps.tok.outputs.ok == 'true' + with: + # 必须取完整历史:镜像可能在任意旧提交上,快进需要共同祖先。 + fetch-depth: 0 + - name: 推 main 到 gitcode(快进) + if: steps.tok.outputs.ok == 'true' + env: + GC_TOKEN: ${{ secrets.GITCODE_TOKEN }} + run: | + set -euo pipefail + GC_URL="https://JianFeeeee:${GC_TOKEN}@gitcode.com" + git push "${GC_URL}/JianFeeeee/HomeAgent.git" \ + "refs/heads/main:refs/heads/main" + echo " gitcode/main 已快进到 ${GITHUB_SHA}"