Skip to content

Commit

Permalink
Create dependabot-auto-merge.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
WomB0ComB0 authored Dec 15, 2023
1 parent dddfabe commit ee5a083
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Dependabot Approve and Merge

on:
pull_request_target:

jobs:
dependabot:
name: Auto approve
runs-on: ubuntu-latest
permissions:
pull-requests: read

if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
steps:
- name: Fetch update types
id: update-types
env:
UPDATE_TYPES: 'version-update:semver-patch version-update:semver-minor'
run: |
arr=(${UPDATE_TYPES//;/ })
count=${#arr[@]}
echo "Types: ${arr[*]}"
echo "Count: ${count}"
echo "types=${arr[*]}" >> $GITHUB_OUTPUT
echo "count=${count}" >> $GITHUB_OUTPUT
- name: Fetch Dependabot metadata
if: ${{ fromJson(steps.update-types.outputs.count) > 0 }}
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1

- name: Generate token
id: generate-token
if: ${{ fromJson(steps.update-types.outputs.count) > 0 && contains(steps.update-types.outputs.types, steps.dependabot-metadata.outputs.update-type) }}
uses: tibdex/github-app-token@v2
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}

- name: Authenticate cli
id: authenticate-cli
if: ${{ fromJson(steps.update-types.outputs.count) > 0 && contains(steps.update-types.outputs.types, steps.dependabot-metadata.outputs.update-type) }}
run: echo "${{ steps.generate-token.outputs.token }}" | gh auth login --with-token

- name: Approve and auto-merge
id: auto-merge
if: ${{ fromJson(steps.update-types.outputs.count) > 0 && contains(steps.update-types.outputs.types, steps.dependabot-metadata.outputs.update-type) }}
run: |
gh pr edit "$PR_URL" --add-label "auto-merged"
gh pr review --approve "$PR_URL"
gh pr merge --auto --merge "$PR_URL"
echo "STATUS=true" >> $GITHUB_OUTPUT
env:
PR_URL: ${{ github.event.pull_request.html_url }}

- name: Write summary
run: |
result="skip. :x:"
if [ "${STATUS}" == "true" ]; then
result=" auto-merge! :white_check_mark:"
fi
echo "### Done with ${result}" >> $GITHUB_STEP_SUMMARY
env:
STATUS: ${{ steps.auto-merge.outputs.STATUS }}

1 comment on commit ee5a083

@vercel
Copy link

@vercel vercel bot commented on ee5a083 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.