Skip to content

Bulk Merge PRs

Bulk Merge PRs #5

---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: "Bulk Merge PRs"
on:
workflow_dispatch:
inputs:
dryRun:
description: Dry Run
default: "false"
required: false
labels:
description: Labels
default: "any"
required: false
jobs:
bulk-merge-prs:
name: Bulk Merge PRs
runs-on: ubuntu-latest
steps:
- name: Get Secrets
uses: bitwarden/sm-action@v2
with:
access_token: ${{ secrets.BW_ACCESS_TOKEN }}
secrets: |
e062dcb9-8cd7-471e-b9be-b10100497102 > BOT_APP_ID
5856238d-3fae-4a0f-9847-b1010049f697 > BOT_APP_PRIVATE_KEY
33fe0505-5ef3-4d91-8053-b101004a4947 > BOT_USERNAME
- name: Generate Token
uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: "${{ env.BOT_APP_ID }}"
private-key: "${{ env.BOT_APP_PRIVATE_KEY }}"
- name: Checkout
uses: actions/checkout@v4
with:
token: "${{ steps.app-token.outputs.token }}"
- name: Merge
shell: bash
env:
GITHUB_TOKEN: "${{ steps.app-token.outputs.token }}"
run: |
args=()
args+=(--app $BOT_USERNAME)
args+=(--state open)
if [ "${{ github.event.inputs.labels }}" != "any" ]; then
IFS=',' read -ra labels <<< "${{ github.event.inputs.labels }}"
for label in "${labels[@]}"; do
args+=(--label "${label}")
done
fi
for id in $(gh pr list "${args[@]}" --jq '.[].number' --json number); do
if [ "${{ github.event.inputs.dryRun }}" = "true" ]; then
echo "Dry run: gh pr merge $id --squash"
continue
fi
gh pr merge "${id}" --squash
sleep 2
done