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,60 +1,119 @@
|
|||||||
name: Renovate Automerge
|
name: Renovate Auto-merge (patch/minor only)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
inputs:
|
||||||
|
delay_minutes:
|
||||||
|
description: 'Optional delay in minutes before processing PRs (default 5)'
|
||||||
|
required: false
|
||||||
|
default: '5'
|
||||||
schedule:
|
schedule:
|
||||||
- cron: "*/10 * * * *"
|
- cron: "*/10 * * * *" # 每 10 分钟运行一次(可按需修改)
|
||||||
|
pull_request:
|
||||||
|
types: [ready_for_review] # 如果 Renovate 把 PR 标记为 ready_for_review,也会触发一次
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
pull-requests: write
|
||||||
|
checks: read
|
||||||
|
|
||||||
|
env:
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
automerge:
|
automerge:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout (not strictly required)
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v5
|
||||||
|
|
||||||
- name: Setup GitHub CLI
|
- name: Install GitHub CLI
|
||||||
uses: cli/cli-action@v2
|
uses: cli/cli-action@v2
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
|
|
||||||
- name: Find Renovate PRs
|
- name: Optional delay (default 5 minutes)
|
||||||
id: find_prs
|
|
||||||
run: |
|
run: |
|
||||||
prs=$(gh pr list \
|
# value from workflow_dispatch input; empty for schedule events -> default to 5
|
||||||
--repo ${{ github.repository }} \
|
delay_input="${{ github.event.inputs.delay_minutes }}"
|
||||||
--state open \
|
delay="${delay_input:-5}"
|
||||||
--json number,title,author \
|
echo "Delaying for ${delay} minute(s) to let other workflows start/complete..."
|
||||||
--jq '.[] | select(.author.login | test("renovate"; "i")) | .number')
|
sleep $((delay * 60))
|
||||||
|
|
||||||
echo "Found PRs: $prs"
|
- name: Debug list all PRs (for logs)
|
||||||
echo "prs=$prs" >> $GITHUB_ENV
|
run: |
|
||||||
|
echo "All open PRs (number / title / author):"
|
||||||
|
gh pr list --repo "$REPO" --state open --json number,title,author \
|
||||||
|
--jq '.[] | {number,title,author:.author.login}' || true
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
- name: Process PRs
|
- name: Find Renovate PR numbers
|
||||||
if: env.prs != ''
|
id: find_prs
|
||||||
run: |
|
run: |
|
||||||
|
prs=$(gh pr list --repo "$REPO" --state open --json number,title,author \
|
||||||
|
--jq '.[] | select(.author.login | test("renovate"; "i")) | .number' ) || true
|
||||||
|
echo "Found PR numbers: $prs"
|
||||||
|
echo "prs=$prs" >> $GITHUB_OUTPUT
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Process Renovate PRs (patch/minor -> merge when checks OK)
|
||||||
|
if: steps.find_prs.outputs.prs != ''
|
||||||
|
run: |
|
||||||
|
owner_repo="$REPO"
|
||||||
|
owner=$(echo "$owner_repo" | cut -d'/' -f1)
|
||||||
|
repo=$(echo "$owner_repo" | cut -d'/' -f2)
|
||||||
|
|
||||||
|
prs="${{ steps.find_prs.outputs.prs }}"
|
||||||
|
# Ensure newline/space separated handling
|
||||||
for pr in $prs; do
|
for pr in $prs; do
|
||||||
echo "Checking PR #$pr ..."
|
echo "=== Processing PR #$pr ==="
|
||||||
body=$(gh pr view "$pr" \
|
|
||||||
--repo ${{ github.repository }} \
|
|
||||||
--json body \
|
|
||||||
--jq .body)
|
|
||||||
|
|
||||||
# 提取更新类型 (patch/minor/major)
|
# Get PR body
|
||||||
update_type=$(echo "$body" | grep -oP '\|\s*(patch|minor|major)\s*\|' | head -n1 | tr -d '|[:space:]')
|
body=$(gh pr view "$pr" --repo "$owner_repo" --json body --jq .body)
|
||||||
|
echo "PR #$pr body snippet:"
|
||||||
|
echo "$body" | sed -n '1,20p' || true
|
||||||
|
|
||||||
echo "PR #$pr update type: $update_type"
|
# 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'"
|
||||||
|
|
||||||
if [[ "$update_type" == "patch" || "$update_type" == "minor" ]]; then
|
if [[ "$update_type" != "patch" && "$update_type" != "minor" ]]; then
|
||||||
echo "Merging PR #$pr ..."
|
echo "Skipping PR #$pr because update_type is not patch/minor."
|
||||||
gh pr merge "$pr" \
|
continue
|
||||||
--repo ${{ github.repository }} \
|
fi
|
||||||
--squash \
|
|
||||||
--auto
|
# 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"
|
||||||
|
|
||||||
|
# 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"
|
||||||
|
|
||||||
|
if [[ "$combined_state" == "success" && "$inprogress" -eq 0 ]]; then
|
||||||
|
echo "All checks passed for PR #$pr. Merging..."
|
||||||
|
gh pr merge "$pr" --repo "$owner_repo" --squash --delete-branch --confirm || {
|
||||||
|
echo "Merge command failed for PR #$pr. See logs."
|
||||||
|
}
|
||||||
else
|
else
|
||||||
echo "Skipping PR #$pr (type=$update_type)"
|
echo "PR #$pr checks not all green (state=$combined_state, inprogress=$inprogress). Skipping."
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
env:
|
env:
|
||||||
|
|||||||
Reference in New Issue
Block a user