From 1198ee53dd9156db0c236d4fc10b67f9d74706ed Mon Sep 17 00:00:00 2001 From: laincat <1129621+laincat@users.noreply.github.com> Date: Thu, 5 Nov 2026 08:11:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A1=E6=A3=80=E4=B8=8E=E5=8F=8D=E7=88=AC?= =?UTF-8?q?=E8=AF=8A=E6=96=AD=E5=85=B1=E7=94=A8=E5=B9=B6=E5=8F=91=E7=BB=84?= =?UTF-8?q?=EF=BC=8C=E6=8E=A8=E9=80=81=E5=A4=B1=E8=B4=A5=E5=8F=AF=E9=87=8D?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2026-11-04 13:23 的巡检在「提交中文报告与订阅」阶段失败:同一时刻另一个巡检 任务已经推送过同样的生成文件,`git pull --rebase` 在 data/、reports/、 subscriptions/ 上全线冲突,已经跑完的巡检被判红。 - patrol.yml 与 access.yml 共用 concurrency 组 `vensrc-main`:两个工作流都会把 生成文件写回 main,串行执行就不会互撞(release.yml 不写 main,保持原组) - 新增 .github/scripts/push_generated.sh:暂存 → 提交 → fetch → `pull --rebase -X theirs`(本提交只有生成物,冲突时保留本轮结果)→ push,失败退避重试 5 次 - patrol 里「本轮之后受信任的清单或脚本被改过就不能发布」的守卫保留,并把 .github/scripts/ 一并纳入比较范围 - 两个工作流里重复的 commit/pull/push 逻辑收敛到同一个脚本 验证:actionlint 通过;本地沙箱复现了两个提交同时改同一文件的情况——直接 push 被拒,脚本里的 fetch + rebase -X theirs + push 成功且保留本轮的生成内容。 --- .github/scripts/push_generated.sh | 35 +++++++++++++++++++++++++++++++ .github/workflows/access.yml | 9 +++----- .github/workflows/patrol.yml | 14 ++++++------- 3 files changed, 44 insertions(+), 14 deletions(-) create mode 100644 .github/scripts/push_generated.sh diff --git a/.github/scripts/push_generated.sh b/.github/scripts/push_generated.sh new file mode 100644 index 0000000..aca8767 --- /dev/null +++ b/.github/scripts/push_generated.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +# 提交已暂存的生成结果并推到 main:冲突时以本轮生成结果为准,失败退避重试。 +# +# 为什么需要它:巡检(patrol.yml)与反爬诊断(access.yml)是两个独立工作流, +# 都会把生成文件写回 main。两边各自的 `git pull --rebase` 一旦撞车,就会在 +# data/、reports/、subscriptions/ 上产生冲突,把已经跑完的巡检判红 +# (2026-11-04 13:23 就因此失败)。这里把推送收敛成一个步骤:先 fetch 再 +# rebase,冲突时保留本轮生成的版本(rebase 的 -X theirs),推送失败则退避重试。 +set -euo pipefail + +message="${1:?用法: push_generated.sh <提交说明>}" +attempts="${PUSH_ATTEMPTS:-5}" +credential='!gh auth git-credential' + +if git diff --cached --quiet; then + echo "没有需要提交的变更" + exit 0 +fi + +git commit -m "$message" + +for attempt in $(seq 1 "$attempts"); do + git -c credential.helper="$credential" fetch --quiet origin main + # 本提交只含脚本生成物,冲突时以本轮结果为准。 + git -c credential.helper="$credential" pull --rebase -X theirs --quiet origin main + if git -c credential.helper="$credential" push --quiet origin HEAD:main; then + echo "已推送 $(git rev-parse --short HEAD)(第 $attempt 次尝试)" + exit 0 + fi + echo "第 $attempt 次推送失败,退避后重试" >&2 + sleep $((attempt * 5)) +done + +echo "连续 $attempts 次推送失败,保留本地提交 $(git rev-parse --short HEAD)" >&2 +exit 1 diff --git a/.github/workflows/access.yml b/.github/workflows/access.yml index 8c053f1..42bd346 100644 --- a/.github/workflows/access.yml +++ b/.github/workflows/access.yml @@ -11,8 +11,9 @@ permissions: contents: read actions: read +# 与巡检共用 vensrc-main 并发组,避免两个工作流同时往 main 写生成文件。 concurrency: - group: venera-access-diagnostics + group: vensrc-main cancel-in-progress: false jobs: @@ -95,8 +96,4 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add -- reports/ACCESS_RESULTS.md data/access-results.json - if ! git diff --cached --quiet; then - git commit -m "更新反爬与人工验证中文处理清单" - git -c credential.helper='!gh auth git-credential' pull --rebase origin main - git -c credential.helper='!gh auth git-credential' push origin HEAD:main - fi + bash .github/scripts/push_generated.sh "更新反爬与人工验证中文处理清单" diff --git a/.github/workflows/patrol.yml b/.github/workflows/patrol.yml index 3278329..aa41951 100644 --- a/.github/workflows/patrol.yml +++ b/.github/workflows/patrol.yml @@ -16,8 +16,9 @@ on: permissions: contents: read +# 巡检与反爬诊断都会把生成文件写回 main,共用同一个并发组,避免同时推送。 concurrency: - group: venera-source-patrol + group: vensrc-main cancel-in-progress: false jobs: @@ -129,10 +130,7 @@ jobs: git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git add -- subscriptions/ data/ reports/ - if ! git diff --cached --quiet; then - git commit -m "定时巡检:更新主/扩展订阅及中文报告" - git -c credential.helper='!gh auth git-credential' fetch origin main - git diff --quiet HEAD origin/main -- monitor/ scripts/ sources/ .github/workflows/patrol.yml - git -c credential.helper='!gh auth git-credential' pull --rebase origin main - git -c credential.helper='!gh auth git-credential' push origin HEAD:main - fi + git -c credential.helper='!gh auth git-credential' fetch origin main + # 本轮之后受信任的清单或脚本被改过时,不能用旧证据发布。 + git diff --quiet HEAD origin/main -- monitor/ scripts/ sources/ .github/workflows/patrol.yml .github/scripts/ + bash .github/scripts/push_generated.sh "定时巡检:更新主/扩展订阅及中文报告"