From 0eb82014087a3c8bac726ba6af1bcac1fe75a7c2 Mon Sep 17 00:00:00 2001 From: Jory Irving Date: Sun, 7 Jan 2024 08:37:39 -0700 Subject: [PATCH] feat: add bulk merge pr workflow --- .github/workflows/bulk-merge-prs.yaml | 54 +++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/bulk-merge-prs.yaml diff --git a/.github/workflows/bulk-merge-prs.yaml b/.github/workflows/bulk-merge-prs.yaml new file mode 100644 index 0000000000..c75632d976 --- /dev/null +++ b/.github/workflows/bulk-merge-prs.yaml @@ -0,0 +1,54 @@ +--- + # 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: Generate 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: 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 ${{ secrets.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 + done