name: release-please

on:
  push:
    branches:
      - main
  workflow_dispatch:

permissions:
  contents: write
  pull-requests: write

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - id: release
        uses: googleapis/release-please-action@v4
        with:
          token: ${{ secrets.GITHUB_TOKEN }}
          command: manifest
          config-file: .release-please-config.json
      - uses: actions/checkout@v4
        if: ${{ steps.release.outputs.release_created }}
        with:
          ref: ${{ steps.release.outputs.tag_name }}
      - name: Install Rust
        if: ${{ steps.release.outputs.release_created }}
        uses: dtolnay/rust-toolchain@stable
      - name: Cache Cargo registry
        if: ${{ steps.release.outputs.release_created }}
        uses: swatinem/rust-cache@v2
      - name: Publish crate
        if: ${{ steps.release.outputs.release_created }}
        run: cargo publish --locked --token "$CARGO_REGISTRY_TOKEN"
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}