name: CI

on:
  pull_request:
    branches:
      - main
  workflow_call:
    inputs:
      build:
        type: boolean
        default: true
        description: 'Whether to run a build as part of testing'

jobs:
  lint:
    name: Lint 💅
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/workflows/actions/prepare
      - run: pnpm run lint

  type-check:
    name: Type check 🧮
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/workflows/actions/prepare
      - run: pnpm run type-check

  unit-tests:
    name: Unit tests 🧪
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/workflows/actions/prepare
      - run: pnpm run test

  build:
    name: Build 🏗
    if: ${{ inputs.build || github.event_name == 'pull_request' }}
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/workflows/actions/prepare
      - run: pnpm run build
