name: Release Plugins

on:
  push:
    tags:
      - 'v*.*.*'
    paths-ignore:
      - 'README.md'
      - 'wiki/**'
      - 'public/**'
      - 'scripts/**'
      - '.vscode'
      - '.idea'
  pull_request:
    branches:
      - master
      - main
    paths-ignore:
      - 'README.md'
      - 'wiki/**'
      - 'public/**'
      - '.scripts/**'
      - '.vscode'
      - '.idea'

concurrency:
  group: release-ci-group
  cancel-in-progress: true

jobs:
  Plugins:
    permissions:
        contents: write
        pages: write
        id-token: write
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Install Node.js
        uses: actions/setup-node@v6
        with:
          node-version: lts/*

      - name: Setup pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9
          run_install: false

      - name: Get pnpm store directory
        id: pnpm-cache
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_OUTPUT

      - name: Cache dependencies
        uses: actions/cache@v5
        with:
          path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-

      - name: Install Dependencies
        run: pnpm install

      - name: Run Type Check
        run: pnpm run check

      - name: Lint Code
        run: pnpm run lint

      - name: Run tests
        run: pnpm run test

      - name: Build Plugins
        run: pnpm run build

      - name: Create Release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: |
            dist/*.json
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
