chore(ci/pre-commit): Add flexible pytest script for cross-environmen… #17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Python Tests | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
jobs: | |
test: | |
runs-on: ubuntu-20.04 | |
strategy: | |
matrix: | |
python-version: ["3.8"] # Reduced to just 3.8 since that's your target version | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache pip packages | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
# Install PyTorch first | |
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu | |
pip install -r requirements.txt | |
pip install pytest pytest-cov coverage-badge mypy flake8 black isort pre-commit | |
# Create symlink to ensure pytest is in PATH | |
sudo ln -s $(which pytest) /usr/local/bin/pytest | |
- name: Run pre-commit | |
run: | | |
pre-commit install | |
pre-commit run --all-files | |
# - name: Type checking with mypy | |
# run: mypy . | |
# - name: Lint with flake8 | |
# run: flake8 . --count --max-line-length=120 --statistics | |
# - name: Check formatting with black | |
# run: black --check . --line-length=120 | |
# - name: Check import sorting with isort | |
# run: isort --check-only --diff . | |
- name: Run tests with coverage | |
run: | | |
pytest tests/ -v --cov=./ --cov-report=xml | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
file: ./coverage.xml | |
fail_ci_if_error: true |