# Run code style checks on each pull request.
name: Code style checks

on:
  pull_request:
  push:
    branches:
      - main

jobs:
  linting:
    env:
      # Configure a constant location for the uv cache
      UV_CACHE_DIR: /tmp/.uv-cache
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - name: Install uv
        uses: astral-sh/setup-uv@v7

      - name: Setup Pixi Environment
        uses: prefix-dev/setup-pixi@v0.9.3
        with:
          pixi-version: latest
          cache: true
          cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }}

      - name: Cache pre-commit hooks
        uses: actions/cache@v5
        with:
          path: ~/.cache/pre-commit
          key: pre-commit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }}

      - name: Run pre-commit
        run: uvx pre-commit run --all-files
