Skip to content

Commit

Permalink
feat: close previous update PRs when a new one is generated (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
rriski authored Sep 25, 2024
1 parent d10ff38 commit d6428a5
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/updater.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ on:
- cron: 0 3 * * 1
workflow_dispatch: {}

permissions: read-all

jobs:
updater:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
with:
Expand All @@ -22,13 +27,28 @@ jobs:
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 <noreply@github.com>
body: >
automated changes by
[updater](https://github.com/aiven/go-api-schemas/blob/main/.github/workflows/updater.yml)
GitHub Actions workflow
branch: updater/${{ steps.date.outputs.date }}
branch: updater/${{ steps.date.outputs.date }}-${{ github.run_id }}
commit-message: "chore(updater): bump pkg/dist/*.yml (${{ steps.date.outputs.date }})"
title: "chore(updater): bump pkg/dist/*.yml (${{ 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("updater/")) | .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 }}

0 comments on commit d6428a5

Please sign in to comment.