mirror of
https://github.com/QYG2297248353/appstore-1panel.git
synced 2026-06-16 01:02:14 +08:00
Update auto_merge_renovate_prs.yml
This commit is contained in:
@@ -1,73 +1,32 @@
|
|||||||
name: Merge Renovate PRs
|
name: Auto Process Renovate PRs
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
pull_request:
|
||||||
|
types: [opened, synchronize, reopened, ready_for_review]
|
||||||
|
workflow_dispatch: # 允许手动触发
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "*/10 * * * *"
|
- cron: '0 * * * *' # 每小时运行一次,处理可能错过的PR
|
||||||
|
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
pull-requests: write
|
|
||||||
checks: read
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
merge-renovate-prs:
|
process-renovate-prs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set GH_TOKEN for GitHub CLI
|
- name: Set up Python
|
||||||
run: echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV
|
uses: actions/setup-python@v5
|
||||||
|
with:
|
||||||
|
python-version: '3.x'
|
||||||
|
|
||||||
- name: List open Renovate PRs
|
- name: Process Renovate PRs
|
||||||
id: list
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
# 获取 renovate / mend-renovate PR numbers
|
cat << 'EOF' > process_renovate_prs.py
|
||||||
mapfile -t prs < <(gh pr list --repo "$GITHUB_REPOSITORY" --state open \
|
# 在这里插入下面的Python脚本内容
|
||||||
--json number,author \
|
EOF
|
||||||
--jq '.[] | select(.author.login | test("renovate|mend-renovate"; "i")) | .number')
|
python process_renovate_prs.py
|
||||||
|
|
||||||
# 输出到 GitHub Actions 输出
|
- name: Clean up
|
||||||
prs_json=$(printf '%s\n' "${prs[@]}" | jq -R . | jq -s .)
|
run: rm -f process_renovate_prs.py
|
||||||
echo "prs=$prs_json" >> $GITHUB_OUTPUT
|
|
||||||
echo "Found PRs: ${prs[*]}"
|
|
||||||
|
|
||||||
- name: Poll and merge Renovate PRs
|
|
||||||
if: steps.list.outputs.prs != '[]'
|
|
||||||
run: |
|
|
||||||
prs=$(echo '${{ steps.list.outputs.prs }}' | jq -r '.[]')
|
|
||||||
for pr in $prs; do
|
|
||||||
echo "=== Processing PR #$pr ==="
|
|
||||||
sha=$(gh pr view "$pr" --repo "$GITHUB_REPOSITORY" --json headRefOid -q .headRefOid)
|
|
||||||
if [[ -z "$sha" ]]; then
|
|
||||||
echo "Cannot get head SHA for PR #$pr. Skipping."
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
merged=false
|
|
||||||
for attempt in $(seq 1 3); do
|
|
||||||
combined=$(gh api repos/$GITHUB_REPOSITORY/commits/$sha/status --jq .state)
|
|
||||||
inprogress=$(gh api repos/$GITHUB_REPOSITORY/commits/$sha/check-runs --jq '[.check_runs[] | select(.status!="completed")] | length')
|
|
||||||
|
|
||||||
echo "Attempt $attempt: combined=$combined, inprogress=$inprogress"
|
|
||||||
|
|
||||||
if [[ "$combined" == "success" && "$inprogress" -eq 0 ]]; then
|
|
||||||
echo "All checks passed for PR #$pr. Merging..."
|
|
||||||
if gh pr merge "$pr" --repo "$GITHUB_REPOSITORY" --merge --delete-branch --yes; then
|
|
||||||
echo "✅ PR #$pr merged successfully."
|
|
||||||
merged=true
|
|
||||||
else
|
|
||||||
echo "❌ PR #$pr merge failed."
|
|
||||||
fi
|
|
||||||
break
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Checks not green. Waiting 10 minutes..."
|
|
||||||
sleep 600
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ "$merged" == false ]]; then
|
|
||||||
echo "⚠️ PR #$pr could not be merged after 3 attempts."
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|||||||
Reference in New Issue
Block a user