name: CI

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Configure Git to use HTTPS instead of SSH
        run: git config --global url."https://github.com/".insteadOf "git@github.com:"

      - name: Setup pnpm
        uses: pnpm/action-setup@v2
        with:
          version: 9

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install --no-frozen-lockfile

      - name: Run ESLint
        run: pnpm run lint

      - name: TypeScript check
        run: pnpm exec tsc --noEmit

  build:
    runs-on: ${{ matrix.os }}
    needs: lint
    
    strategy:
      matrix:
        os: [windows-latest, macos-latest, ubuntu-latest]
      fail-fast: false

    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Configure Git to use HTTPS instead of SSH
        run: git config --global url."https://github.com/".insteadOf "git@github.com:"

      - name: Setup pnpm
        uses: pnpm/action-setup@v2
        with:
          version: 9

      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'pnpm'

      - name: Install dependencies
        run: pnpm install --no-frozen-lockfile

      - name: Build application
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CSC_IDENTITY_AUTO_DISCOVERY: false
        run: pnpm run build

      - name: Run tests
        run: pnpm test

      - name: Package application
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          CSC_IDENTITY_AUTO_DISCOVERY: false
        run: pnpm run package
