name: Pull Request CI

permissions:
  contents: read

on:
  workflow_dispatch:
  pull_request:
    branches:
      - main
      - develop
      - v2
    types: [ready_for_review, synchronize, opened]

jobs:
  build:
    runs-on: ubuntu-latest
    env:
      PRCI: true
    if: github.event.pull_request.draft == false

    steps:
      - name: Check out Git repository
        uses: actions/checkout@v6

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

      - name: Install pnpm
        uses: pnpm/action-setup@v4

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

      - name: Cache pnpm dependencies
        uses: actions/cache@v4
        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: Lint Check
        run: pnpm test:lint

      - name: Format Check
        run: pnpm format:check

      - name: Type Check
        run: pnpm typecheck

      - name: i18n Check
        run: pnpm i18n:check

      - name: Test
        run: pnpm test
