diff --git a/.github/workflows/auto_merge_renovate_prs.yml b/.github/workflows/auto_merge_renovate_prs.yml index 7a6dd3b8d..3254c6efd 100644 --- a/.github/workflows/auto_merge_renovate_prs.yml +++ b/.github/workflows/auto_merge_renovate_prs.yml @@ -1,73 +1,32 @@ -name: Merge Renovate PRs +name: Auto Process Renovate PRs on: - workflow_dispatch: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + workflow_dispatch: # 允许手动触发 schedule: - - cron: "*/10 * * * *" - -permissions: - contents: read - pull-requests: write - checks: read + - cron: '0 * * * *' # 每小时运行一次,处理可能错过的PR jobs: - merge-renovate-prs: + process-renovate-prs: runs-on: ubuntu-latest steps: - - name: Checkout + - name: Checkout repository uses: actions/checkout@v4 - - name: Set GH_TOKEN for GitHub CLI - run: echo "GH_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> $GITHUB_ENV + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' - - name: List open Renovate PRs - id: list + - name: Process Renovate PRs + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - # 获取 renovate / mend-renovate PR numbers - mapfile -t prs < <(gh pr list --repo "$GITHUB_REPOSITORY" --state open \ - --json number,author \ - --jq '.[] | select(.author.login | test("renovate|mend-renovate"; "i")) | .number') - - # 输出到 GitHub Actions 输出 - prs_json=$(printf '%s\n' "${prs[@]}" | jq -R . | jq -s .) - echo "prs=$prs_json" >> $GITHUB_OUTPUT - echo "Found PRs: ${prs[*]}" + cat << 'EOF' > process_renovate_prs.py + # 在这里插入下面的Python脚本内容 + EOF + python process_renovate_prs.py - - 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 + - name: Clean up + run: rm -f process_renovate_prs.py