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

jobs:
  release-plz:
    if: github.repository == 'jdx/mise'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
      - 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: actions-rust-lang/setup-rust-toolchain@v1
        with: { toolchain: nightly, components: rustfmt }
      - uses: actions-rust-lang/setup-rust-toolchain@v1
      - run: mkdir -p "$HOME/bin" && echo "$HOME/bin" >> "$GITHUB_PATH"
      - run: npm i
      - run: cargo build --all-features && cp target/debug/mise "$HOME"/bin
      - uses: actions/cache/restore@v4
        with:
          path: |
            ~/.local/share/mise/installs
            ~/.local/share/mise/plugins
          key: mise-tools-ubuntu-latest-${{ hashFiles('.mise.toml') }}
          restore-keys: mise-tools-ubuntu-latest
      - run: mise install
      - run: |
          set -euxo pipefail
          rm -rf registry
          git clone https://github.com/mise-plugins/registry
          rm -rf registry/.git
          git add registry
      - run: mise run release-plz
        env:
          GITHUB_TOKEN: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
