name: CI

permissions:
  contents: read

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

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

env:
  # Many color libraries just need this to be set to any value, but at least
  # one distinguishes color depth, where "3" -> "256-bit color".
  FORCE_COLOR: 3

jobs:
  lint:
    name: Lint
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          fetch-depth: 0

      - uses: prefix-dev/setup-pixi@28eb668aafebd9dede9d97c4ba1cd9989a4d0004 # v0.9.2
        with:
          pixi-version: v0.58.0
          cache: true
          environments: lint

      - name: Lint (if this step fails, please 'pixi run lint' locally and push the changes)
        run: pixi run -e lint lint

  checks:
    name: Test ${{ matrix.environment }}
    runs-on: ${{ matrix.runs-on }}
    strategy:
      fail-fast: false
      matrix:
        environment:
          - tests-py310
          - tests-py313
          - tests-numpy1
          - tests-backends
          - tests-backends-py310
          - tests-nogil
        runs-on: [ubuntu-latest]

    steps:
      - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
        with:
          fetch-depth: 0

      - uses: prefix-dev/setup-pixi@28eb668aafebd9dede9d97c4ba1cd9989a4d0004 # v0.9.2
        with:
          pixi-version: v0.58.0
          cache: true
          environments: ${{ matrix.environment }}

      - name: Test package
        # Save some time; also at the moment of writing coverage crashes on python 3.13t
        if: ${{ matrix.environment != 'tests-nogil' }}
        run: pixi run -e ${{ matrix.environment }} tests-ci

      - name: Test free-threading
        if: ${{ matrix.environment == 'tests-nogil' }}
        run: pixi run -e tests-nogil tests --parallel-threads=4

      - name: Upload coverage report
        if: ${{ matrix.environment != 'tests-nogil' }}
        uses: codecov/codecov-action@5a1091511ad55cbe89839c7260b706298ca349f7 # v5.5.1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
