name: release-fig
on:
  push:
    tags:
      - "v*.0" ## Only run the action on new versions once per month, this prevents useless runs of the action
  workflow_dispatch:

jobs:
  push-to-fig-autocomplete:
    ## 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: rui314/setup-mold@v1
      - uses: Swatinem/rust-cache@v2
        with:
          shared-key: build
          save-if: false
      - 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 install
      - run: mise x -- bun i
      - run: mise run render:fig
      - name: Create Autocomplete PR ## Create the autocomplete PR using this action
        uses: withfig/push-to-fig-autocomplete-action@v2
        with:
          token: ${{ secrets.MY_RELEASE_PLEASE_TOKEN }}
          autocomplete-spec-name: mise
          spec-path: tasks/fig/src/mise.ts
          pr-body: "Automated PR for latest mise release by https://github.com/jdx/mise"
