name: CI

on:
  push:
  pull_request:

jobs:
  lint:
    name: lint:ruff
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v9.0.0
        with:
          python-version: "3.11"
          enable-cache: true
      - run: uv sync --all-packages
      - name: ruff check gallery
        run: uv run ruff check gallery
      - name: ruff check plotstyle
        run: uv run ruff check plotstyle
      - name: ruff check tests
        run: uv run ruff check tests

  format:
    name: format:ruff
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v9.0.0
        with:
          python-version: "3.11"
          enable-cache: true
      - run: uv sync --all-packages
      - name: ruff format check gallery
        run: uv run ruff format --check gallery
      - name: ruff format check plotstyle
        run: uv run ruff format --check plotstyle
      - name: ruff format check tests
        run: uv run ruff format --check tests

  typecheck:
    name: typecheck:ty
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v9.0.0
        with:
          python-version: "3.11"
          enable-cache: true
      - run: uv sync --all-packages
      - name: ty check gallery
        run: uv run ty check gallery
      - name: ty check plotstyle
        run: uv run ty check plotstyle

  vulnerabilities:
    name: vulnerabilities:pip-audit
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v9.0.0
        with:
          python-version: "3.11"
          enable-cache: true
      - run: uv sync --all-packages
      - run: uv run pip-audit --skip-editable

  test:
    name: test:pytest
    runs-on: ubuntu-latest
    needs: [lint, format, typecheck, vulnerabilities]
    steps:
      - uses: actions/checkout@v4
      - uses: astral-sh/setup-uv@v9.0.0
        with:
          python-version: "3.11"
          enable-cache: true
      - run: uv sync --all-packages
      - run: uv run pytest tests/ -v
