Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/scripts/push_generated.sh
Original file line number Diff line number Diff line change
@@ -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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve generated outputs as a complete snapshot during retries

When another patrol has published results since this run's checkout, -X theirs can silently publish inconsistent subscriptions and evidence rather than preserve this run's complete outputs. The Git documentation explains that the option resolves “conflicting hunks”; nonconflicting changes are still merged. I reproduced this with the new script in two local clones: the remote patrol added a third subscription, while the local patrol generated two subscriptions with updated lock timestamps and report. The script successfully pushed an index containing three entries, but a lock file and report containing only two. Previously, the conflicting timestamps/report stopped publication. Preserve and reapply the entire generated snapshot, including files unchanged relative to the original checkout, or regenerate and validate the outputs against the fetched base before pushing.

Useful? React with 👍 / 👎.

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
9 changes: 3 additions & 6 deletions .github/workflows/access.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 "更新反爬与人工验证中文处理清单"
14 changes: 6 additions & 8 deletions .github/workflows/patrol.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ on:
permissions:
contents: read

# 巡检与反爬诊断都会把生成文件写回 main,共用同一个并发组,避免同时推送。
concurrency:
group: venera-source-patrol
group: vensrc-main
cancel-in-progress: false

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