From 0b2fa78d2e87d1abb1e937e5de3fff79526edbc1 Mon Sep 17 00:00:00 2001 From: Meng Sen Date: Wed, 17 Sep 2025 11:29:38 +0800 Subject: [PATCH] Update auto_merge_renovate_prs.yml --- .github/workflows/auto_merge_renovate_prs.yml | 53 ++++++------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/.github/workflows/auto_merge_renovate_prs.yml b/.github/workflows/auto_merge_renovate_prs.yml index ca381c614..301e041c5 100644 --- a/.github/workflows/auto_merge_renovate_prs.yml +++ b/.github/workflows/auto_merge_renovate_prs.yml @@ -8,9 +8,9 @@ on: required: false default: '5' schedule: - - cron: "*/10 * * * *" # 每 10 分钟运行一次(可按需修改) + - cron: "*/10 * * * *" pull_request: - types: [ready_for_review] # 如果 Renovate 把 PR 标记为 ready_for_review,也会触发一次 + types: [ready_for_review] permissions: contents: read @@ -25,23 +25,17 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout (not strictly required) - uses: actions/checkout@v5 + - name: Checkout (optional) + uses: actions/checkout@v4 - - name: Install GitHub CLI - uses: cli/cli-action@v2 - with: - version: latest - - - name: Optional delay (default 5 minutes) + - name: Optional delay run: | - # value from workflow_dispatch input; empty for schedule events -> default to 5 delay_input="${{ github.event.inputs.delay_minutes }}" delay="${delay_input:-5}" - echo "Delaying for ${delay} minute(s) to let other workflows start/complete..." + echo "Delaying for ${delay} minute(s)..." sleep $((delay * 60)) - - name: Debug list all PRs (for logs) + - name: Debug list all PRs run: | echo "All open PRs (number / title / author):" gh pr list --repo "$REPO" --state open --json number,title,author \ @@ -59,7 +53,7 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Process Renovate PRs (patch/minor -> merge when checks OK) + - name: Process Renovate PRs (patch/minor only) if: steps.find_prs.outputs.prs != '' run: | owner_repo="$REPO" @@ -67,53 +61,40 @@ jobs: repo=$(echo "$owner_repo" | cut -d'/' -f2) prs="${{ steps.find_prs.outputs.prs }}" - # Ensure newline/space separated handling for pr in $prs; do echo "=== Processing PR #$pr ===" - # Get PR body body=$(gh pr view "$pr" --repo "$owner_repo" --json body --jq .body) - echo "PR #$pr body snippet:" - echo "$body" | sed -n '1,20p' || true - # Parse update type from the Markdown table: the 'Update' column is usually the 3rd field update_type=$(echo "$body" | awk -F'|' '/\|/ { gsub(/ /,"",$3); if ($3 ~ /(major|minor|patch)/) {print $3; exit} }') update_type=${update_type:-unknown} - echo "PR #$pr detected update_type='$update_type'" + echo "PR #$pr update_type=$update_type" if [[ "$update_type" != "patch" && "$update_type" != "minor" ]]; then - echo "Skipping PR #$pr because update_type is not patch/minor." + echo "Skipping PR #$pr (not patch/minor)" continue fi - # Get head commit SHA of the PR sha=$(gh pr view "$pr" --repo "$owner_repo" --json headRefOid --jq .headRefOid 2>/dev/null || true) if [[ -z "$sha" ]]; then - # fallback to API sha=$(gh api repos/$owner/$repo/pulls/$pr --jq .head.sha) fi echo "PR #$pr head SHA: $sha" - if [[ -z "$sha" ]]; then - echo "Cannot determine head SHA for PR #$pr, skipping." - continue - fi - - # Check combined status for the commit (state = success / failure / pending) combined_state=$(gh api repos/$owner/$repo/commits/$sha/status --jq .state) - echo "Combined status for $sha: $combined_state" + echo "Combined status: $combined_state" - # Additionally ensure there are no in-progress check-runs - inprogress=$(gh api repos/$owner/$repo/commits/$sha/check-runs --jq '.check_runs[] | select(.status == "in_progress" or .conclusion == null) | .name' | wc -l || true) - echo "In-progress / pending check-runs count: $inprogress" + inprogress=$(gh api repos/$owner/$repo/commits/$sha/check-runs \ + --jq '.check_runs[] | select(.status == "in_progress" or .conclusion == null) | .name' | wc -l || true) + echo "In-progress checks: $inprogress" if [[ "$combined_state" == "success" && "$inprogress" -eq 0 ]]; then - echo "All checks passed for PR #$pr. Merging..." + echo "Merging PR #$pr ..." gh pr merge "$pr" --repo "$owner_repo" --squash --delete-branch --confirm || { - echo "Merge command failed for PR #$pr. See logs." + echo "Merge failed for PR #$pr" } else - echo "PR #$pr checks not all green (state=$combined_state, inprogress=$inprogress). Skipping." + echo "Checks not green for PR #$pr, skipping." fi done env: