name: Release-plz

# release-plz drives two things:
#   1. release-plz-pr: opens/updates a single "chore(release): ..." PR that
#      bumps the [package].version and regenerates CHANGELOG.md from
#      conventional commits. Runs on every push to master.
#   2. release-plz-release: when the release PR is merged, publishes the
#      crate to crates.io, then creates the git tag + GitHub Release.
#
# Secrets required:
#   * CARGO_REGISTRY_TOKEN — a crates.io API token with publish permission
#     for this crate.
#   * RELEASE_PLZ_TOKEN (optional) — a PAT with repo + workflow scope, if
#     you want the tag push to trigger any downstream workflows.

on:
  push:
    branches:
      - master

permissions:
  contents: write
  pull-requests: write

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

jobs:
  release-plz-pr:
    name: release-plz PR
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.RELEASE_PLZ_TOKEN || secrets.GITHUB_TOKEN }}

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Run release-plz (open/refresh release PR)
        uses: release-plz/action@v0.5
        with:
          command: release-pr
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN || secrets.GITHUB_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

  release-plz-release:
    name: release-plz release
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.RELEASE_PLZ_TOKEN || secrets.GITHUB_TOKEN }}

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable

      - name: Run release-plz (publish + tag + GH release)
        uses: release-plz/action@v0.5
        with:
          command: release
        env:
          GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN || secrets.GITHUB_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
