VARsim-infer #105
Workflow file for this run
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 package CI | |
on: | |
push: | |
branches: [ master ] | |
pull_request: | |
branches: [ master ] | |
permissions: | |
contents: write | |
jobs: | |
update-requirements: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: "3.10" | |
- name: Install autopep8 | |
run: python -m pip install autopep8 | |
- name: Format code with autopep8 | |
run: autopep8 --in-place --aggressive --aggressive --recursive mimic/ | |
- name: Automatic requirements.txt for Python Project | |
uses: ryan-rozario/[email protected] | |
with: | |
PROJECT_PATH: mimic/ | |
REQUIREMENT_PATH: ./requirements.txt | |
- name: Commit changes | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "GitHub Action" | |
git add . | |
git commit -m "Update requirements.txt and format code" || true | |
git push origin HEAD:${{ github.head_ref }} || true | |
continue-on-error: true # In case there are no changes | |
- name: Upload updated requirements.txt | |
uses: actions/upload-artifact@v3 | |
with: | |
name: requirements | |
path: requirements.txt | |
build: | |
needs: update-requirements | |
runs-on: ${{ matrix.os }} | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, macos-latest, windows-latest] | |
python-version: ["3.10"] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Download updated requirements.txt | |
uses: actions/download-artifact@v3 | |
with: | |
name: requirements | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Cache Python dependencies | |
uses: actions/cache@v2 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} | |
restore-keys: | | |
${{ runner.os }}-pip- | |
- name: Install dependencies | |
shell: bash | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install flake8 mypy pytest | |
if [ -f requirements.txt ]; then | |
python -m pip install -r requirements.txt | |
else | |
echo "No requirements.txt found" | |
exit 1 | |
fi | |
- name: Lint with flake8 | |
run: | | |
# Stop the build if there are Python syntax errors or undefined names | |
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics | |
# You can also enforce a max line length if desired | |
# flake8 . --count --max-line-length=127 --statistics | |
- name: Type check with mypy | |
run: mypy --ignore-missing-imports --check-untyped-defs . | |
- name: Set PYTHONPATH (Unix) | |
run: echo "PYTHONPATH=$PWD" >> $GITHUB_ENV | |
if: runner.os != 'Windows' | |
- name: Set PYTHONPATH (Windows) | |
shell: cmd | |
run: | | |
setlocal enabledelayedexpansion | |
echo PYTHONPATH=!CD! >> %GITHUB_ENV% | |
if: runner.os == 'Windows' | |
- name: Run tests | |
run: pytest tests/ --disable-warnings |