|
| 1 | +# Automatically approve and merge Dependabot PRs for minor and patch updates |
| 2 | +name: Dependabot auto-merge |
| 3 | +on: pull_request |
| 4 | + |
| 5 | +permissions: |
| 6 | + contents: write |
| 7 | + pull-requests: write |
| 8 | + |
| 9 | +jobs: |
| 10 | + dependabot: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + if: github.event.pull_request.user.login == 'dependabot[bot]' |
| 13 | + steps: |
| 14 | + - name: Check if dependency should be excluded |
| 15 | + id: check_exclusion |
| 16 | + run: | |
| 17 | + # List of dependencies to exclude from auto-merge |
| 18 | + # Add package names as they appear in the dependency-name metadata |
| 19 | + EXCLUDED_DEPS=( |
| 20 | + "org.jboss:jboss-parent" |
| 21 | + # "com.example:another-dependency" |
| 22 | + ) |
| 23 | +
|
| 24 | + DEPENDENCY_NAME="${{ github.event.pull_request.title }}" |
| 25 | + echo "Checking dependency: $DEPENDENCY_NAME" |
| 26 | +
|
| 27 | + EXCLUDED=false |
| 28 | + for dep in "${EXCLUDED_DEPS[@]}"; do |
| 29 | + # Skip empty lines and comments |
| 30 | + [[ -z "$dep" || "$dep" =~ ^#.*$ ]] && continue |
| 31 | +
|
| 32 | + if [[ "$DEPENDENCY_NAME" == *"$dep"* ]]; then |
| 33 | + echo "Dependency '$dep' is excluded from auto-merge" |
| 34 | + EXCLUDED=true |
| 35 | + break |
| 36 | + fi |
| 37 | + done |
| 38 | +
|
| 39 | + echo "excluded=$EXCLUDED" >> $GITHUB_OUTPUT |
| 40 | + echo "Excluded: $EXCLUDED" |
| 41 | +
|
| 42 | + - name: Dependabot metadata |
| 43 | + id: metadata |
| 44 | + uses: dependabot/fetch-metadata@v2 |
| 45 | + with: |
| 46 | + github-token: "${{ secrets.GITHUB_TOKEN }}" |
| 47 | + |
| 48 | + - name: Approve Dependabot PR |
| 49 | + if: steps.check_exclusion.outputs.excluded == 'false' |
| 50 | + run: gh pr review --approve "$PR_URL" |
| 51 | + env: |
| 52 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 53 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 54 | + |
| 55 | + - name: Enable auto-merge for Dependabot PRs |
| 56 | + if: steps.check_exclusion.outputs.excluded == 'false' && (steps.metadata.outputs.update-type == 'version-update:semver-patch' || steps.metadata.outputs.update-type == 'version-update:semver-minor') |
| 57 | + run: gh pr merge --auto --squash "$PR_URL" |
| 58 | + env: |
| 59 | + PR_URL: ${{ github.event.pull_request.html_url }} |
| 60 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + |
| 62 | + - name: Skip auto-merge for excluded dependency |
| 63 | + if: steps.check_exclusion.outputs.excluded == 'true' |
| 64 | + run: | |
| 65 | + echo "This dependency is excluded from auto-merge. Manual review required." |
| 66 | + echo "PR will remain open for manual review and approval." |
0 commit comments