name: Release-plz

permissions:
  pull-requests: write
  contents: write

on:
  push:
    branches:
      - main

jobs:
  # Release unpublished packages.
  release-plz-release:
    name: Release-plz release
    runs-on: ubuntu-latest
    if: ${{ github.repository_owner == 'DanNixon' }}

    permissions:
      contents: write

    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
          fetch-depth: 0
      - uses: DeterminateSystems/nix-installer-action@v22

      - name: Run release-plz
        run: nix develop --command release-plz release --forge=github
        env:
          GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  # Create a PR with the new versions and changelog, preparing the next release.
  release-plz-pr:
    name: Release-plz PR
    runs-on: ubuntu-latest
    if: ${{ github.repository_owner == 'DanNixon' }}

    permissions:
      contents: write
      pull-requests: write

    concurrency:
      group: release-plz-${{ github.ref }}
      cancel-in-progress: false

    steps:
      - uses: actions/checkout@v6
        with:
          persist-credentials: false
          fetch-depth: 0
      - uses: DeterminateSystems/nix-installer-action@v22

      - name: Run release-plz
        run: nix develop --command release-plz release-pr --forge=github
        env:
          GIT_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
