# kilocode_change - new file
name: "CodeQL Kotlin"

on:
  push:
    branches: ["main"]
    paths:
      - "packages/kilo-jetbrains/**"
      - ".github/workflows/codeql-kotlin.yml"
  pull_request:
    branches: ["main"]
    paths:
      - "packages/kilo-jetbrains/**"
      - ".github/workflows/codeql-kotlin.yml"
  schedule:
    - cron: "29 10 * * 5"
  workflow_dispatch:

jobs:
  analyze:
    name: Analyze (java-kotlin)
    runs-on: ubuntu-latest
    permissions:
      security-events: write
      packages: read
      actions: read
      contents: read

    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: Initialize CodeQL
        uses: github/codeql-action/init@v4
        with:
          languages: java-kotlin
          build-mode: manual
          config-file: ./.github/codeql/codeql-config.yml

      - name: Build Java/Kotlin
        shell: bash
        run: ./gradlew typecheck --rerun-tasks --no-build-cache
        working-directory: packages/kilo-jetbrains

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@v4
        with:
          category: "/language:java-kotlin"
