name: typecheck

on:
  push:
    branches:
      - main
  pull_request:
  workflow_dispatch:

jobs:
  typecheck-js:
    name: typecheck-js
    runs-on: blacksmith-4vcpu-ubuntu-2404
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6 # kilocode_change

      - name: Setup Bun
        uses: ./.github/actions/setup-bun

      # kilocode_change start
      - name: Run TypeScript typecheck
        run: bun turbo typecheck --filter='!@kilocode/kilo-jetbrains'

      - name: Build Kilo Console
        run: bun turbo build --filter=@kilocode/kilo-console
      # kilocode_change end

  # kilocode_change start
  typecheck-jetbrains:
    name: typecheck-jetbrains
    runs-on: blacksmith-4vcpu-ubuntu-2404
    steps:
      - name: Checkout repository
        uses: actions/checkout@v6

      - name: Setup Bun
        uses: ./.github/actions/setup-bun

      - name: Setup Java
        uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: "21"

      - name: Setup Gradle
        uses: gradle/actions/setup-gradle@v4
        with:
          cache-read-only: ${{ github.ref != 'refs/heads/main' }}

      - name: Run JetBrains typecheck
        run: ./gradlew typecheck
        working-directory: packages/kilo-jetbrains

  required:
    name: typecheck
    runs-on: blacksmith-4vcpu-ubuntu-2404
    needs:
      - typecheck-js
      - typecheck-jetbrains
    if: always()
    steps:
      - name: Verify typecheck jobs passed
        run: |
          echo "typecheck-js=${{ needs.typecheck-js.result }}"
          echo "typecheck-jetbrains=${{ needs.typecheck-jetbrains.result }}"
          test "${{ needs.typecheck-js.result }}" = "success"
          test "${{ needs.typecheck-jetbrains.result }}" = "success"
  # kilocode_change end
