diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml deleted file mode 100644 index df4cad1..0000000 --- a/.github/workflows/auto-merge.yml +++ /dev/null @@ -1,129 +0,0 @@ -name: Auto-merge Dependabot PRs - -on: - pull_request: - types: [opened, synchronize, reopened] - -permissions: - contents: write - pull-requests: write - checks: read - -jobs: - auto-merge: - runs-on: ubuntu-latest - if: github.actor == 'dependabot[bot]' - - steps: - - name: Check if PR is patch update - id: check-patch - uses: actions/github-script@v7 - with: - script: | - const title = context.payload.pull_request.title; - const isPatch = title.includes('patch') || - title.match(/bump .+ from \d+\.\d+\.\d+ to \d+\.\d+\.\d+$/); - const isSecurityUpdate = title.includes('security') || - context.payload.pull_request.labels.some(label => - label.name === 'security' || label.name === 'vulnerability' - ); - - console.log(`PR Title: ${title}`); - console.log(`Is patch update: ${isPatch}`); - console.log(`Is security update: ${isSecurityUpdate}`); - - return { - should_auto_merge: isPatch || isSecurityUpdate, - is_patch: isPatch, - is_security: isSecurityUpdate - }; - - - name: Wait for CI to complete - if: fromJSON(steps.check-patch.outputs.result).should_auto_merge - uses: actions/github-script@v7 - with: - script: | - const { owner, repo } = context.repo; - const pr_number = context.payload.pull_request.number; - - // Wait for all checks to complete - let allChecksPassed = false; - let attempts = 0; - const maxAttempts = 30; // Wait up to 15 minutes (30 * 30s) - - while (!allChecksPassed && attempts < maxAttempts) { - attempts++; - - const { data: checks } = await github.rest.checks.listForRef({ - owner, - repo, - ref: context.payload.pull_request.head.sha, - }); - - const { data: statuses } = await github.rest.repos.listCommitStatusesForRef({ - owner, - repo, - ref: context.payload.pull_request.head.sha, - }); - - const allChecks = [...checks.check_runs, ...statuses]; - const pendingChecks = allChecks.filter(check => - check.status === 'queued' || - check.status === 'in_progress' || - check.state === 'pending' - ); - - const failedChecks = allChecks.filter(check => - check.conclusion === 'failure' || - check.conclusion === 'cancelled' || - check.state === 'failure' || - check.state === 'error' - ); - - if (failedChecks.length > 0) { - console.log('Some checks failed, will not auto-merge'); - console.log('Failed checks:', failedChecks.map(c => c.name || c.context).join(', ')); - return; - } - - if (pendingChecks.length === 0) { - allChecksPassed = true; - console.log('All checks passed!'); - } else { - console.log(`Waiting for ${pendingChecks.length} checks to complete...`); - console.log('Pending checks:', pendingChecks.map(c => c.name || c.context).join(', ')); - await new Promise(resolve => setTimeout(resolve, 30000)); // Wait 30 seconds - } - } - - if (!allChecksPassed) { - console.log('Timeout waiting for checks to complete'); - return; - } - - // Enable auto-merge - await github.rest.pulls.merge({ - owner, - repo, - pull_number: pr_number, - merge_method: 'squash', - commit_title: `${context.payload.pull_request.title} (#${pr_number})`, - commit_message: 'Auto-merged by Dependabot workflow' - }); - - console.log('PR auto-merged successfully!'); - - - name: Add comment on successful merge - if: fromJSON(steps.check-patch.outputs.result).should_auto_merge - uses: actions/github-script@v7 - with: - script: | - const result = ${{ steps.check-patch.outputs.result }}; - const updateType = result.is_security ? 'security update' : 'patch update'; - - await github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.payload.pull_request.number, - body: `🤖 Auto-merged this ${updateType} after all checks passed successfully!` - }); diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 0000000..efbfa64 --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,23 @@ +name: Dependabot auto-merge +on: pull_request + +permissions: + contents: write + pull-requests: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v2 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + - name: Enable auto-merge for Dependabot PRs + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}