name: Release-plz

on:
  push:
    branches: [main]
  workflow_dispatch:

jobs:
  release:
    name: Release-plz release
    if: ${{ github.repository_owner == 'ratatui' }}
    runs-on: ubuntu-latest
    environment: release
    permissions:
      contents: write
      id-token: write
    steps:
      - name: Checkout repository
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          fetch-depth: 0
          persist-credentials: false
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # master
        with:
          toolchain: stable
      - name: Run release-plz (release)
        uses: release-plz/action@e8792575c7f2366cf6ff3ccc33ead9ace5b691c7 # v0.5.130
        with:
          command: release
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  release_pr:
    name: Release-plz PR
    if: ${{ github.repository_owner == 'ratatui' }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        package:
          - tui-widgets
          - tui-bar-graph
          - tui-big-text
          - tui-box-text
          - tui-cards
          - tui-popup
          - tui-prompts
          - tui-qrcode
          - tui-scrollbar
          - tui-scrollview
    permissions:
      contents: write
      pull-requests: write
    concurrency:
      group: release-plz-${{ github.ref }}-${{ matrix.package }}
      cancel-in-progress: false
    steps:
      - name: Checkout repository
        uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
        with:
          fetch-depth: 0
          persist-credentials: false
      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 # master
        with:
          toolchain: stable
      - name: Install release-plz
        uses: taiki-e/install-action@7a79fe8c3a13344501c80d99cae481c1c9085912 # v2.81.10
        with:
          tool: release-plz@0.3.150,cargo-semver-checks@0.45
      - name: Run release-plz (release-pr)
        run: >
          release-plz release-pr
          --git-token "${{ secrets.GITHUB_TOKEN }}"
          --repo-url "https://github.com/${{ github.repository }}"
          --package "${{ matrix.package }}"
          --config ".github/release-plz/${{ matrix.package }}.toml"
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
