name: prechecks

on:
  workflow_call:
    inputs:
      with_coverage:
        required: true
        type: string
      with_packages:
        required: true
        type: string

concurrency:
  group: style-${{github.ref}}-${{github.event.pull_request.number || github.run_number}}
  cancel-in-progress: true


jobs:
  # Validate that the code can be run on all the Python versions supported by Spack
  validate:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
    - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
      with:
        python-version: '3.13'
    - name: Install Python Packages
      run: |
        pip install -r .github/workflows/requirements/style/requirements.txt
    - name: vermin
      run: |
        vermin --backport importlib \
               --backport argparse \
               --violations \
               --backport typing \
               -t=3.6- \
               -vvv \
               --exclude-regex lib/spack/spack/vendor \
               lib/spack/spack/ lib/spack/llnl/ bin/ var/spack/test_repos

  # Run style checks on the files that have been changed
  style:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
      with:
        fetch-depth: 2
    - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b
      with:
        python-version: '3.13'
    - name: Install Python packages
      run: |
        pip install -r .github/workflows/requirements/style/requirements.txt
        echo "PYTHONPATH=$PWD/lib/spack" >> $GITHUB_ENV
    - name: Run style tests (code)
      run: |
        bin/spack style --base HEAD^1
        bin/spack license verify
        pylint -j $(nproc) --disable=all --enable=unspecified-encoding --ignore-paths=lib/spack/spack/vendor lib
    - name: Run style tests (docs)
      run: .github/workflows/bin/format-rst.py $(git ls-files 'lib/spack/docs/*.rst')
