Repository navigation
巡检与反爬诊断共用并发组,推送失败可重试 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When another patrol has published results since this run's checkout,
-X theirscan 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 👍 / 👎.