2727 if : github.event.pull_request.user.login == 'dependabot[bot]' || github.event.pull_request.user.login == 'renovate[bot]'
2828 runs-on : ubuntu-latest
2929 permissions :
30- # for hmarr/ auto-approve-action to approve PRs
30+ # for auto-approve step to work
3131 pull-requests : write
3232 # for alexwilson/enable-github-automerge-action to approve PRs
3333 contents : write
@@ -44,15 +44,51 @@ jobs:
4444 with :
4545 repo-token : ${{ secrets.GITHUB_TOKEN }}
4646
47- # GitHub actions bot approve
48- - uses : hmarr/auto-approve-action@f0939ea97e9205ef24d872e76833fa908a770363 # v4.0.0
47+ - name : Dependabot metadata
48+ id : metadata
4949 if : startsWith(steps.branchname.outputs.branch, 'dependabot/')
50+ uses : dependabot/fetch-metadata@25dd0e34f4fe68f24cc83900b1fe3fe149efef98 # v3.1.0
5051 with :
5152 github-token : ${{ secrets.GITHUB_TOKEN }}
5253
54+ - name : Check for ignored dependencies in the PR
55+ id : validate
56+ if : startsWith(steps.branchname.outputs.branch, 'dependabot/')
57+ env :
58+ IGNORE_PATTERN : ${{ env.IGNORE_PATTERN }}
59+ DEPENDENCY_NAMES : ${{ steps.metadata.outputs.dependency-names }}
60+ run : |
61+ if [[ -z ${IGNORE_PATTERN} ]]; then
62+ echo "ignore=false" >> "$GITHUB_OUTPUT"
63+ elif [[ -z ${DEPENDENCY_NAMES} ]]; then
64+ echo "ignore=false" >> "$GITHUB_OUTPUT"
65+ elif [[ ${DEPENDENCY_NAMES} =~ ${IGNORE_PATTERN} ]]; then
66+ echo "ignore=true" >> "$GITHUB_OUTPUT"
67+ fi
68+
69+ - name : GitHub actions bot approve
70+ id : auto_approve
71+ if : ${{
72+ startsWith(steps.branchname.outputs.branch, 'dependabot/')
73+ && steps.validate.outputs.ignore != 'true'
74+ }}
75+ run : gh pr review --approve "$PR_URL"
76+ env :
77+ PR_URL : ${{ github.event.pull_request.html_url }}
78+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
79+
5380 # Enable GitHub auto merge
5481 - name : Auto merge
55- uses : alexwilson/enable-github-automerge-action@56e3117d1ae1540309dc8f7a9f2825bc3c5f06ff # v2.0.0
56- if : startsWith(steps.branchname.outputs.branch, 'dependabot/')
82+ uses : alexwilson/enable-github-automerge-action@2c32e18a76e0726ffe7a573bfff2d42a20885126 # 3.0.0
83+ if : ${{
84+ startsWith(steps.branchname.outputs.branch, 'dependabot/')
85+ && steps.auto_approve.conclusion == 'success'
86+ && (github.event.action == 'opened' || github.event.action == 'reopened')
87+ && (
88+ steps.metadata.outputs.update-type == 'version-update:semver-patch'
89+ || (fromJSON(env.ALLOW_MINOR) && steps.metadata.outputs.update-type == 'version-update:semver-minor')
90+ || (fromJSON(env.ALLOW_MAJOR) && steps.metadata.outputs.update-type == 'version-update:semver-major')
91+ )
92+ }}
5793 with :
5894 github-token : ${{ secrets.GITHUB_TOKEN }}
0 commit comments