name: Check
on:
  workflow_dispatch:
  pull_request:
    branches: [main]
  push:
    branches: [main]

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    timeout-minutes: 20
    steps:
      - uses: actions/checkout@v4

      - name: Install Nix
        uses: DeterminateSystems/nix-installer-action@main

      - name: Cache Nix Store
        uses: nix-community/cache-nix-action@main
        with:
          primary-key: ${{ runner.os }}-nix-${{ hashFiles('flake.lock') }}

      - name: Load devShell environment
        uses: nicknovitski/nix-develop@main
        with:
          arguments: .#default

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

      - uses: actions/cache@v3
        name: Setup pnpm cache
        with:
          path: ${{ env.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

      - name: Cache Turbo
        uses: actions/cache@v4
        with:
          path: .turbo
          key:
            ${{ runner.os }}-turbo-${{ github.ref_name }}-${{ github.job }}-${{
            github.sha }}
          restore-keys: |
            ${{ runner.os }}-turbo-${{ github.ref_name }}-${{ github.job }}-
            ${{ runner.os }}-turbo-${{ github.ref_name }}-
            ${{ runner.os }}-turbo-

      - run: pnpm install

      - run: pnpm exec turbo lint:check

  # test:
  #   name: Test
  #   runs-on: ubuntu-latest
  #   timeout-minutes: 10
  #   steps:
  #     - uses: actions/checkout@v4
  #     - name: Install dependencies
  #       uses: ./.github/actions/setup
  #     - run: pnpm vitest
  #       env:
  #         NODE_OPTIONS: --max_old_space_size=8192
