Dependabot Auto-Merge #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Dependabot Auto-Merge | |
| on: | |
| workflow_run: | |
| workflows: ["PR Checks"] | |
| types: [completed] | |
| permissions: | |
| actions: write | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| merge: | |
| name: Merge Green Weekly Update | |
| if: github.event.workflow_run.conclusion == 'success' | |
| runs-on: blacksmith-4vcpu-ubuntu-2404 | |
| steps: | |
| - name: Validate weekly Dependabot pull request | |
| id: pull-request | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| HEAD_SHA: ${{ github.event.workflow_run.head_sha }} | |
| PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }} | |
| run: | | |
| set -euo pipefail | |
| if [[ -z "${PR_NUMBER}" ]]; then | |
| PR_NUMBER=$(gh api \ | |
| --method GET \ | |
| -H "Accept: application/vnd.github+json" \ | |
| "/repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}/pulls" \ | |
| --jq '[.[] | select(.state == "open")][0].number // empty') | |
| fi | |
| if [[ -z "${PR_NUMBER}" ]]; then | |
| echo "eligible=false" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| pr=$(gh pr view "${PR_NUMBER}" \ | |
| --repo "${GITHUB_REPOSITORY}" \ | |
| --json author,isDraft,labels,state,url) | |
| author=$(jq -r '.author.login' <<< "${pr}") | |
| state=$(jq -r '.state' <<< "${pr}") | |
| draft=$(jq -r '.isDraft' <<< "${pr}") | |
| weekly=$(jq -r '[.labels[].name] | contains(["weekly-release"])' <<< "${pr}") | |
| if [[ "${author}" != "app/dependabot" || "${state}" != "OPEN" || "${draft}" != "false" || "${weekly}" != "true" ]]; then | |
| echo "eligible=false" >> "${GITHUB_OUTPUT}" | |
| exit 0 | |
| fi | |
| url=$(jq -r '.url' <<< "${pr}") | |
| echo "eligible=true" >> "${GITHUB_OUTPUT}" | |
| echo "url=${url}" >> "${GITHUB_OUTPUT}" | |
| - name: Approve update | |
| if: steps.pull-request.outputs.eligible == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PR_URL: ${{ steps.pull-request.outputs.url }} | |
| run: gh pr review "${PR_URL}" --approve --body "Required checks passed; approved for the weekly dependency batch." | |
| - name: Squash and merge update | |
| if: steps.pull-request.outputs.eligible == 'true' | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| PR_URL: ${{ steps.pull-request.outputs.url }} | |
| run: gh pr merge "${PR_URL}" --squash --delete-branch |