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 "定时巡检:更新主/扩展订阅及中文报告"