name: Go

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

env:
  FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

permissions:
  contents: read

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

jobs:
  checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod

      - name: Install golangci-lint
        run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1

      - name: Install gocyclo
        run: go install github.com/fzipp/gocyclo/cmd/gocyclo@v0.6.0

      - name: Install ineffassign
        run: go install github.com/gordonklaus/ineffassign@latest

      - name: Install misspell
        run: go install github.com/client9/misspell/cmd/misspell@v0.3.4

      - name: Add Go bin to PATH
        run: echo "$(go env GOPATH)/bin" >> "$GITHUB_PATH"

      - name: Check
        run: make check

  conformance:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod

      - name: Run conformance tests
        run: make conformance

  inspector-smoke:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod

      - name: Set up Node.js
        uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Run inspector smoke test
        run: make inspector-smoke

  # Named, fast-failing coverage for the docling adapter contract and the
  # provider-selection / fallback decision matrix (#145). These cases also run
  # under `make check` (the `checks` job); this job runs them in isolation so an
  # adapter-protocol regression or a broken fallback path is surfaced as its own
  # red check rather than buried in the full suite. It needs no docling binary,
  # no docling-serve container, and no network (deterministic fakes/seams only).
  docling-contract:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: true

      - name: Set up Go
        uses: actions/setup-go@v5
        with:
          go-version-file: go.mod

      - name: Docling adapter contract + provider-selection matrix
        run: >-
          go test -v ./tests/ingest/
          -run 'Docling|DescribeDocumentExtractor|DocumentExtractorFromConfig|DescribeAndBuild'
