name: Release-plz

on:
  push:
    branches:
      - main

jobs:
  release-plz-release:
    name: Release-plz release
    runs-on: amd64-bookworm
    if: ${{ github.repository_owner == 'spotpilot' }}
    permissions:
      contents: write
      id-token: write
    env:
      CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
    steps:
      - &checkout
        name: Checkout repository
        uses: actions/checkout@v5
        with:
          fetch-depth: 0
      - name: Configure git
        run: |
          git config --global user.name "spotpilot-bot"
          git config --global user.email "bot@spotpilot.io"
      - name: Install release-plz
        run: |
          curl -sL https://github.com/release-plz/release-plz/releases/latest/download/release-plz-x86_64-unknown-linux-gnu.tar.gz | tar xz
          sudo mv release-plz /usr/local/bin/
      - name: Run release-plz
        run: |
          release-plz release \
            --git-token "${{ secrets.GITHUB_TOKEN }}" \
            --forge gitea \
            --repo-url "${{ github.server_url }}/${{ github.repository }}"

  release-plz-pr:
    name: Release-plz PR
    runs-on: amd64-bookworm
    if: ${{ github.repository_owner == 'spotpilot' }}
    permissions:
      pull-requests: write
      contents: write
    concurrency:
      group: release-plz-${{ github.ref }}
      cancel-in-progress: false
    steps:
      - *checkout
      - name: Configure git
        run: |
          git config --global user.name "spotpilot-bot"
          git config --global user.email "bot@spotpilot.io"
      - name: Install release-plz
        run: |
          curl -sL https://github.com/release-plz/release-plz/releases/latest/download/release-plz-x86_64-unknown-linux-gnu.tar.gz | tar xz
          sudo mv release-plz /usr/local/bin/
      - name: Run release-plz
        run: |
          release-plz release-pr \
            --git-token "${{ secrets.GITHUB_TOKEN }}" \
            --forge gitea \
            --repo-url "${{ github.server_url }}/${{ github.repository }}"
