name: "Build & Release"

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  RUST_VERSION: 1.91.0

jobs:
  run-ci:
    permissions:
      checks: write
    uses: ./.github/workflows/ci.yaml
    secrets: inherit

  release-plz:
    name: Release-plz
    needs: run-ci
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      contents: write
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Rust toolchain
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: ${{ env.RUST_VERSION }}
          cache: true

      # Required to compile rig-lancedb
      - name: Install Protoc
        run: sudo apt-get update && sudo apt-get install -y protobuf-compiler

      - name: Run release-plz
        uses: MarcoIeni/release-plz-action@v0.5
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
