You will find template of required files (requirements.txt
, requirements-test.txt
, project_package/base.py
, tests/base_test.py
, python-app.yml
) at the end of this gist.
- Add base functionality and test files:
project_package/base.py
tests/base_test.py
- Add test requirements
requirements-test.txt
- Check whether your folders and files structure looks like:
.
├── project_package
│ ├── base.py
│ └── __init__.py
├── .github
│ └── workflows
│ └── python-app.yml
├── requirements-test.txt
├── requirements.txt
└── tests
└── base_test.py
- [Optional] do a pytest and flake local run (from root project folder):
python -m pytest
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
- Add workflow definition:
.github/workflows/python-app.yml
- At a fresh push/pull request on main branch, you'll see this wokflow running!
flake8==3.9.0
pytest==6.0.1
% insert here project requirements
def runme():
return 1
from project_package import base
def test_base():
return 0
def test_run():
assert base.runme() == 1
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python application
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Install dependencies for testing
run: |
if [ -f requirements-test.txt ]; then pip install -r requirements-test.txt; 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
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
python -m pytest
Very helpful, cheers 👍