name: CI Lint

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

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

permissions:
  contents: read

jobs:
  lint:
    name: Lint
    if: github.repository == 'kreuzberg-dev/kreuzberg' && github.actor != 'dependabot[bot]'
    runs-on: ubuntu-24.04-arm
    timeout-minutes: 60
    env:
      CARGO_TERM_COLOR: always
      FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"
    steps:
      - uses: actions/checkout@v6
        with:
          submodules: recursive

      - name: Setup Rust
        uses: kreuzberg-dev/actions/setup-rust@v1
        with:
          cache-key-prefix: lint

      - name: Setup Python
        uses: kreuzberg-dev/actions/setup-python-env@v1
        with:
          python-version: "3.13"
          cache-prefix: lint-py
          install-command: "uv sync --group dev --no-install-project --no-install-workspace --frozen"

      - name: Setup Node
        uses: kreuzberg-dev/actions/setup-node-workspace@v1

      - name: Setup Go
        uses: actions/setup-go@v6
        with:
          go-version: "1.26"

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

      - name: Setup Elixir
        uses: kreuzberg-dev/actions/setup-elixir@v1

      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: "3.4"
          bundler-cache: true
          working-directory: packages/ruby

      - name: Setup PHP
        uses: kreuzberg-dev/actions/setup-php@v1

      - name: Setup .NET
        uses: actions/setup-dotnet@v5
        with:
          dotnet-version: "10.0.x"

      - name: Setup R
        uses: kreuzberg-dev/actions/setup-r@v1
        with:
          r-version: "release"
          install-deps: "false"

      - name: Install Task
        uses: kreuzberg-dev/actions/install-task@v1

      - name: Setup Helm
        uses: azure/setup-helm@v5

      - name: Setup kubeconform
        uses: bmuschko/setup-kubeconform@v1

      - name: Install alef CLI
        uses: kreuzberg-dev/actions/install-alef@v1

      - name: Run all prek hooks
        uses: j178/prek-action@v2
        with:
          cache: false
          extra-args: --all-files

      - name: Validate C header
        shell: bash
        run: |
          HEADER="crates/kreuzberg-ffi/include/kreuzberg.h"
          if [ ! -f "$HEADER" ]; then
            echo "::error::C header not found at $HEADER — run 'task alef:generate'"
            exit 1
          fi
          echo "C header verified at $HEADER"
