mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-22 08:33:12 -05:00
pr_overlap.py links each conflicting range to main at the commit it ran on, so every push to main changes every non-empty report. The workflow keeps a hash of each report to read the comments of changed reports only, but with the commit in the hash every report counts as changed: each run reads the comments of every pull request with an overlap and rewrites its comment although only the commit differs. In one hour on 2026-10-13 it rewrote 107 existing overlap comments, against the 1000 requests per hour GITHUB_TOKEN has for the repository. The hash and the comparison with the posted comment now replace the commit in blob links with a fixed ref, so a report whose ranges, exports and files are unchanged makes no request. Posted comments keep their links pinned to the commit they were written at. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
72 lines
2.7 KiB
YAML
72 lines
2.7 KiB
YAML
name: PR overlap
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
schedule:
|
|
- cron: '15 * * * *'
|
|
workflow_dispatch:
|
|
|
|
permissions: {}
|
|
|
|
concurrency:
|
|
group: pr-overlap
|
|
|
|
jobs:
|
|
overlap:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
steps:
|
|
- uses: actions/checkout@v7
|
|
with:
|
|
fetch-depth: 0
|
|
- uses: actions/cache/restore@v6
|
|
with:
|
|
path: ${{ runner.temp }}/overlap-state.json
|
|
key: pr-overlap-${{ github.run_id }}
|
|
restore-keys: pr-overlap-
|
|
- env:
|
|
GH_TOKEN: ${{ github.token }}
|
|
GH_REPO: ${{ github.repository }}
|
|
run: |
|
|
out=$RUNNER_TEMP/overlap
|
|
state=$RUNNER_TEMP/overlap-state.json
|
|
python3 tools/pr_overlap.py --base "${{ github.event.repository.default_branch }}" --out "$out"
|
|
[ -s "$state" ] || echo '{}' > "$state"
|
|
record() { jq --arg pr "$1" --arg h "$2" '.[$pr] = $h' "$state" > "$state.new" && mv "$state.new" "$state"; }
|
|
shopt -s nullglob
|
|
marker='<!-- pr-overlap -->'
|
|
unpinned() { sed -E 's#/blob/[0-9a-f]{40}/#/blob/main/#g'; }
|
|
prev=
|
|
for file in "$out"/*.md; do
|
|
[ -z "$prev" ] || record "$prev" "$hash"
|
|
pr=$(basename "$file" .md)
|
|
hash=$(unpinned < "$file" | sha256sum | cut -d' ' -f1)
|
|
prev=
|
|
[ "$(jq -r --arg pr "$pr" '.[$pr] // empty' "$state")" = "$hash" ] && continue
|
|
prev=$pr
|
|
comment=$(gh api "repos/$GH_REPO/issues/$pr/comments" --paginate \
|
|
--jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$marker\"))) | [.id, .body] | @json" | head -n1)
|
|
id=$(jq -r '.[0] // empty' <<< "${comment:-null}")
|
|
if [ -s "$file" ]; then
|
|
[ "$(jq -r '.[1]' <<< "${comment:-null}" | unpinned)" = "$(unpinned < "$file")" ] && continue
|
|
if [ -n "$id" ]; then
|
|
gh api -X PATCH "repos/$GH_REPO/issues/comments/$id" -F body=@"$file" > /dev/null
|
|
else
|
|
gh pr comment "$pr" --body-file "$file"
|
|
fi
|
|
elif [ -n "$id" ]; then
|
|
gh api -X DELETE "repos/$GH_REPO/issues/comments/$id"
|
|
fi
|
|
done
|
|
[ -z "$prev" ] || record "$prev" "$hash"
|
|
reports=$(for file in "$out"/*.md; do basename "$file" .md; done | jq -R . | jq -sc .)
|
|
jq -c --argjson keep "$reports" 'with_entries(select(.key | IN($keep[])))' "$state" > "$state.new" && mv "$state.new" "$state"
|
|
- if: always()
|
|
uses: actions/cache/save@v6
|
|
with:
|
|
path: ${{ runner.temp }}/overlap-state.json
|
|
key: pr-overlap-${{ github.run_id }}
|