pythonpackage.yml
1 name: Python package 2 3 on: 4 push: 5 branches: 6 - main 7 - dev 8 pull_request: 9 branches: 10 - main 11 - dev 12 13 jobs: 14 linting: 15 runs-on: ubuntu-latest 16 steps: 17 # Checkout repo and setup python 18 - uses: actions/checkout@v2 19 - uses: actions/setup-python@v2 20 # load pip cache if cache exists 21 - uses: actions/cache@v2 22 with: 23 path: ~/.cache/pip 24 key: ${{ runner.os }}-pip 25 restore-keys: ${{ runner.os }}-pip 26 # install linters 27 - name: Setup linters 28 run: python -m pip install black flake8 mypy 29 # run linters 30 - name: Lint 31 run: | 32 flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 33 flake8 . --count --exit-zero --max-complexity=5 --max-line-length=88 --ignore=E203 --statistics 34 black . --check 35 mypy . 36 build-and-test: 37 needs: linting 38 strategy: 39 fail-fast: true 40 matrix: 41 os: ["ubuntu-latest"] 42 python-version: [3.7, 3.8, 3.9] 43 runs-on: ${{ matrix.os }} 44 steps: 45 # Checkout repo and setup python 46 - uses: actions/checkout@v2 47 - uses: actions/setup-python@v2 48 with: 49 python-version: ${{ matrix.python-version }} 50 # Install and configure poetry 51 - name: Install Poetry 52 uses: snok/install-poetry@v1.1.1 53 with: 54 virtualenvs-create: true 55 virtualenvs-in-project: true 56 # Load cached venv if cache exists 57 - name: Load cached venv (poetry) 58 id: cached-poetry-dependencies 59 uses: actions/cache@v2 60 with: 61 path: .venv 62 key: venv-${{ runner.os }}-${{ hashFiles('**/poetry.lock') }} 63 # install dependencies if cache does not exist 64 - name: Install dependencies 65 run: poetry install 66 if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'