name: Release for new tag

on:
  push:
    tags:
      - 'v*.*.*'
  workflow_dispatch:

jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v7
        with:
          fetch-depth: 0 # Fetch all history for generating release notes

      - uses: pnpm/action-setup@v6
      - name: Setup Node.js
        uses: actions/setup-node@v7
        with:
          node-version-file: .nvmrc
          cache: pnpm

      - name: Install fixit-cli
        run: pnpm install -g fixit-cli
      - name: Split theme configuration
        run: |
          fixit split
          tar -zcvf config_toml.tar.gz config
          rm -rf config
          fixit split -y
          tar -zcvf config_yaml.tar.gz config
          rm -rf config

      - name: Generate release notes
        run: |
          pnpm install --frozen-lockfile
          pnpm changelog --starting-version ${{ github.ref_name }}
          sed -i '1,4d' CHANGELOG.md

      - name: GitHub Release
        uses: softprops/action-gh-release@v3
        with:
          draft: true
          body_path: CHANGELOG.md
          files: |
            config_toml.tar.gz
            config_yaml.tar.gz
