name: release-plz

permissions:
  pull-requests: write
  contents: write

on:
  workflow_dispatch:
  push:
    branches:
      - main
  schedule:
    - cron: "0 0 * * *"

concurrency:
  group: release-plz

env:
  MISE_EXPERIMENTAL: 1
  NPM_CONFIG_FUND: false
  RUST_BACKTRACE: 1
  CARGO_TERM_COLOR: always
  GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN || secrets.GITHUB_TOKEN }}

jobs:
  release-plz:
    if: github.repository == 'jdx/mise'
    timeout-minutes: 20
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
          submodules: true
      - uses: crazy-max/ghaction-import-gpg@v6
        with:
          gpg_private_key: ${{ secrets.MISE_GPG_KEY }}
          git_user_signingkey: true
          git_commit_gpgsign: true
          git_tag_gpgsign: true
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: build
      - run: mkdir -p "$HOME/bin" && echo "$HOME/bin" >> "$GITHUB_PATH"
      - run: cargo build --all-features && cp target/debug/mise "$HOME"/bin
      - uses: actions/cache@v4
        with:
          key: ${{ runner.os }}-mise-tools-${{ hashFiles('mise.lock') }}
          path: |
            ~/.local/share/mise
            ~/.cache/mise
      - run: mise x wait-for-gh-rate-limit -- wait-for-gh-rate-limit
      - run: mise install
      - run: mise x -- bun i
      - run: mise run release-plz
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
