name: CI

on:
  pull_request:
    branches: [main]

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: install pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: 'pnpm'
      - name: install plugin
        run: pnpm install
      - name: install e2e
        run: pnpm install
        working-directory: e2e
      - name: lint plugin and e2e
        run: pnpm run lint:all
      # lint the e2e repos
      # e2e repos need the plugin to be built
      - run: pnpm run build
      - name: install tailwindv3
        run: pnpm install
        working-directory: e2e/test_repos/repos/tailwindv3/repo
      - name: lint tailwindv3
        run: pnpm run lint
        working-directory: e2e/test_repos/repos/tailwindv3/repo
  type_check:
    name: type check
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: install pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: 'pnpm'
      - name: install plugin
        run: pnpm install
      - name: type-check plugin
        run: pnpm run type-check
      # type check the e2e repos
      # e2e repos need the plugin to be built
      - run: pnpm run build
      - name: install tailwindv3
        run: pnpm install
        working-directory: e2e/test_repos/repos/tailwindv3/repo
      - name: type-check tailwindv3
        run: pnpm run type-check
        working-directory: e2e/test_repos/repos/tailwindv3/repo
  test:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v4
      - name: install pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: 'pnpm'
      - run: pnpm install
      - run: pnpm run test
      - name: report coverage
        if: always()
        uses: davelosert/vitest-coverage-report-action@v2
  e2e:
    timeout-minutes: 15
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: install pnpm
        uses: pnpm/action-setup@v4
        with:
          version: 9
      - uses: actions/setup-node@v4
        with:
          node-version: 22
          cache: 'pnpm'
      - run: pnpm install
      - run: pnpm run build
      - run: pnpm install
        working-directory: e2e
      - run: pnpm run e2e
        working-directory: e2e
      - name: upload playwright report
        uses: actions/upload-artifact@v4
        with:
          name: playwright-report
          path: e2e/playwright-report/
          retention-days: 30