From 0972a5628b127359cccd4079073701d6a8f406f5 Mon Sep 17 00:00:00 2001 From: Timo Riski Date: Wed, 25 Sep 2024 10:18:39 +0300 Subject: [PATCH] feat: close previous update PRs when a new one is generated --- .github/workflows/update.yml | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/update.yml b/.github/workflows/update.yml index 290e023..edc5759 100644 --- a/.github/workflows/update.yml +++ b/.github/workflows/update.yml @@ -22,14 +22,14 @@ jobs: go-version-file: go.mod - run: go install golang.org/x/tools/cmd/goimports@latest - uses: arduino/setup-task@v2 - - run: wget -O openapi.json https://api.aiven.io/doc/openapi.json - run: task generate env: AIVEN_TOKEN: ${{ secrets.AIVEN_TOKEN }} AIVEN_PROJECT_NAME: ${{ secrets.AIVEN_PROJECT_NAME }} - id: date run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT - - uses: peter-evans/create-pull-request@v7 + - id: create_pr + uses: peter-evans/create-pull-request@v7 with: author: GitHub body: > @@ -39,3 +39,17 @@ jobs: branch: update/${{ steps.date.outputs.date }} commit-message: "chore(update): bump openapi schema (${{ steps.date.outputs.date }})" title: "chore(update): bump openapi schema (${{ steps.date.outputs.date }})" + labels: | + schema bump + automated pr + - name: Close previous update PRs + run: | + new_pr_number=${{ steps.create_pr.outputs.pull-request-number }} + prs=$(gh pr list --state open --json number,headRefName --jq '.[] | select(.headRefName | startswith("update/")) | .number') + for pr in $prs; do + if [ "$pr" != "$new_pr_number" ]; then + gh pr close $pr --comment "Auto-closing pull request in favor of #$new_pr_number" --delete-branch + fi + done + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}