Skip to content

Commit

Permalink
PI-2401 Re-usable Dependabot auto-merge action
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-bcl committed Aug 6, 2024
1 parent 80e4e3a commit 9916a79
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 18 deletions.
33 changes: 33 additions & 0 deletions .github/actions/dependabot-automerge/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Dependabot auto-merge
description: Auto-approve and merge Dependabot pull requests for minor and patch version upgrades

inputs:
token:
description: A personal access token, or GitHub app token, with permissions to approve/merge pull requests
required: true

runs:
using: "composite"
steps:
- name: Dependabot metadata
if: github.actor == 'dependabot[bot]'
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ github.token }}"

- name: Enable auto-merge for Dependabot PRs
if: github.actor == 'dependabot[bot]'
run: gh pr merge --auto --squash "$PR_URL"
shell: bash
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ inputs.token }}

- name: Auto-approve minor or patch versions
run: gh pr review --approve "$PR_URL"
if: github.actor == 'dependabot[bot]' && (steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch')
shell: bash
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ inputs.token }}
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ updates:
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/.github/actions/dependabot-automerge"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/.github/actions/check-changes"
schedule:
Expand Down
21 changes: 3 additions & 18 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,12 @@ jobs:
runs-on: ubuntu-latest
if: github.actor == 'dependabot[bot]'
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2
with:
github-token: "${{ github.token }}"

- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}

- name: Enable auto-merge for Dependabot PRs
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}

- name: Auto-approve minor or patch versions
run: gh pr review --approve "$PR_URL"
if: steps.metadata.outputs.update-type == 'version-update:semver-minor' || steps.metadata.outputs.update-type == 'version-update:semver-patch'
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GH_TOKEN: ${{ steps.app-token.outputs.token }}
- uses: ./.github/actions/dependabot-automerge
with:
token: ${{ steps.app-token.outputs.token }}

0 comments on commit 9916a79

Please sign in to comment.