name: Update release version

permissions:
   contents: write
   pull-requests: write

on:
  release:
    types: [published]


jobs:
  update-version:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: Run release-tagger
        uses: tj-actions/release-tagger@v4
      - name: Sync release version.
        uses: tj-actions/sync-release-version@v13
        id: sync-release-version
        with:
          pattern: '${{ github.repository }}@'
          only_major: true
          paths: |
            README.md
      - name: Sync release package version.
        uses: tj-actions/sync-release-version@v13
        id: sync-release-package-version
        with:
          pattern: '"version": "'
          strip_prefix: "v"
          paths: |
            package.json
      - name: Run git-cliff
        uses: tj-actions/git-cliff@v1
      - name: Create Pull Request
        uses: peter-evans/create-pull-request@v7.0.2
        with:
          base: "main"
          labels: "merge when passing"
          title: "Upgraded to ${{ steps.sync-release-version.outputs.new_version }}"
          branch: "upgrade-to-${{ steps.sync-release-version.outputs.new_version }}"
          commit-message: "Upgraded from ${{ steps.sync-release-version.outputs.old_version }} -> ${{ steps.sync-release-version.outputs.new_version }}"
          body: "View [CHANGES](https://github.com/${{ github.repository }}/compare/${{ steps.sync-release-version.outputs.old_version }}...${{ steps.sync-release-version.outputs.new_version }})"
          token: ${{ secrets.PAT_TOKEN }}