Skip to content

Commit

Permalink
feat: add GitHub Actions workflow for automatic merging of Dependabot…
Browse files Browse the repository at this point in the history
… PRs based on compatibility score
  • Loading branch information
MasterLaplace committed Dec 9, 2024
1 parent 17e49aa commit 6d2ffc0
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions .github/workflows/auto_merge_depandabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Auto Merge Depandabot PRs

on:
pull_request:
types: [opened, labeled]
branches: [master, main]

permissions:
contents: write
id-token: write
attestations: write
security-events: write
pull-requests: write

jobs:
auto_merge_depandabot_pr:
name: Auto Merge Depandabot PR
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'dependencies') && contains(github.event.pull_request.labels.*.name, 'github-actions') }}
steps:
- uses: actions/checkout@v4

- name: Extract Badge URL
id: extract_url
run: |
pr_body="${{ github.event.pull_request.body }}"
badge_url=$(echo "$pr_body" | grep -oP '(?<=\[!\[Dependabot compatibility score]\().+?(?=\))')
echo "badge_url=$badge_url" >> $GITHUB_ENV
- name: Download and Parse SVG
id: parse_svg
run: |
echo "Downloading SVG from: ${{ env.badge_url }}"
svg_content=$(curl -s "${{ env.badge_url }}")
compatibility_score=$(echo "$svg_content" | grep -oP '(?<=<title>compatibility: )\d+(?=%</title>)')
echo "compatibility_score=$compatibility_score" >> $GITHUB_ENV
- name: Validate Compatibility Score
id: validate_score
run: |
if [[ "${{ env.compatibility_score }}" -ge 70 ]]; then
echo "Score is sufficient: ${{ env.compatibility_score }}%"
echo "should_merge=true" >> $GITHUB_ENV
else
echo "Score is too low: ${{ env.compatibility_score }}%"
echo "should_merge=false" >> $GITHUB_ENV
fi
- name: Attest Build Provenance
if: ${{ env.should_merge == 'true' }}
uses: actions/[email protected]
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
subject-name: "Auto Merge Depandabot PR"
subject-path: ".github/workflows/auto_merge_depandabot.yml"

- name: Merge PR
uses: peter-evans/enable-pull-request-automerge@v3
with:
token: ${{ secrets.GITHUB_TOKEN }}
pull-request-number: ${{ github.event.pull_request.number }}
merge-method: squash

0 comments on commit 6d2ffc0

Please sign in to comment.