|
| 1 | +name: Dependabot auto-merge |
| 2 | +on: |
| 3 | + pull_request_target: |
| 4 | + types: [opened, reopened, synchronize, ready_for_review] |
| 5 | +permissions: |
| 6 | + contents: write |
| 7 | + pull-requests: write |
| 8 | +jobs: |
| 9 | + dependabot: |
| 10 | + if: ${{ github.actor == 'dependabot[bot]' }} |
| 11 | + runs-on: ubuntu-latest |
| 12 | + steps: |
| 13 | + - uses: actions/github-script@v7 |
| 14 | + id: files |
| 15 | + with: |
| 16 | + script: | |
| 17 | + const allowed = [ |
| 18 | + /^package\.json$/, /^package-lock\.json$/, /^npm-shrinkwrap\.json$/, /^yarn\.lock$/, /^pnpm-lock\.yaml$/, |
| 19 | + /^pyproject\.toml$/, /^setup\.py$/, /^setup\.cfg$/, /^Pipfile$/, /^Pipfile\.lock$/, /^poetry\.lock$/, /^requirements[^/]*\.txt$/, |
| 20 | + /^go\.mod$/, /^go\.sum$/, /^go\.work$/, /^go\.work\.sum$/, |
| 21 | + /^Cargo\.toml$/, /^Cargo\.lock$/, |
| 22 | + /^Gemfile$/, /^Gemfile\.lock$/, |
| 23 | + /^composer\.json$/, /^composer\.lock$/, |
| 24 | + /^pom\.xml$/, |
| 25 | + /^build\.gradle$/, /^build\.gradle\.kts$/, /^gradle\.properties$/, /^settings\.gradle$/, /^settings\.gradle\.kts$/, |
| 26 | + /^Directory\.Packages\.props$/, /^packages\.config$/, /^packages\.lock\.json$/, /\.csproj$/, /\.fsproj$/, /\.vbproj$/, |
| 27 | + /^mix\.exs$/, /^mix\.lock$/, |
| 28 | + /^pubspec\.yaml$/, /^pubspec\.lock$/, |
| 29 | + /^\.github\/workflows\/[^/]+\.ya?ml$/ |
| 30 | + ]; |
| 31 | + const { owner, repo } = context.repo; |
| 32 | + const pull_number = context.payload.pull_request.number; |
| 33 | + const files = await github.paginate(github.rest.pulls.listFiles, { owner, repo, pull_number, per_page: 100 }); |
| 34 | + const bad = files.map(f => f.filename).filter(p => !allowed.some(re => re.test(p))); |
| 35 | + core.setOutput('ok', bad.length === 0 ? 'true' : 'false'); |
| 36 | + if (bad.length > 0) core.notice(`Skipping auto-merge; disallowed files: ${bad.join(', ')}`); |
| 37 | + - uses: dependabot/fetch-metadata@v2 |
| 38 | + id: metadata |
| 39 | + with: |
| 40 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 41 | + - name: Enable auto-merge |
| 42 | + if: steps.files.outputs.ok == 'true' |
| 43 | + uses: peter-evans/enable-pull-request-automerge@v3 |
| 44 | + with: |
| 45 | + token: "${{ secrets.GITHUB_TOKEN }}" |
| 46 | + merge-method: squash |
0 commit comments