name: Pre-commit check

on:
  push:
    branches-ignore:
    - renovate/**
  pull_request:

permissions:
  contents: read

jobs:
  pre-commit:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
      with:
        persist-credentials: false
    - name: Get cache tag
      id: get-date
      run: |
        echo "cache_tag=$(/bin/date --utc '+%Y%m')" >> "$GITHUB_OUTPUT"
        echo "previous_cache_tag=$(/bin/date --date='1 month ago' --utc '+%Y%m')" >> "$GITHUB_OUTPUT"
      shell: bash
    - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1
      id: pre-commit-cache
      with:
        path: ~/.cache/pre-commit
        key: ${{ runner.os }}-pre-commit-${{ steps.get-date.outputs.cache_tag }}-${{ hashFiles('.pre-commit-config.yaml') }}
        restore-keys: |
          ${{ runner.os }}-pre-commit-${{ steps.get-date.outputs.cache_tag }}
          ${{ runner.os }}-pre-commit-${{ steps.get-date.outputs.previous_cache_tag }}
          ${{ runner.os }}-pre-commit-
    - uses: astral-sh/setup-uv@61cb8a9741eeb8a550a1b8544337180c0fc8476b # v7.2.0
    - uses: actions/setup-python@83679a892e2d95755f2dac6acb0bfd1e9ac5d548 # v6.1.0
      with:
        python-version: 3.14
    - name: pre-commit
      run: uv run --no-sources --only-group pre-commit pre-commit run --all
      env:
        RUFF_OUTPUT_FORMAT: github
        REUSE_OUTPUT_FORMAT: github
