-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (70 loc) · 2.57 KB
/
python-run-tests.yml
File metadata and controls
77 lines (70 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: "Run tests and lint (Python 3.12)"
on:
push:
branches: [ "main" , "feature/**", "fix/**"]
pull_request:
branches: [ "main" ]
workflow_dispatch:
permissions:
contents: read
env:
POETRY_VERSION: 1.8.3
POETRY_HOME: /opt/poetry
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Cache pip dependencies
id: cache-pip
uses: actions/cache@v3
env:
cache-name: cache-pip-dependencies
with:
path: ~/.local
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pyproject.toml') }}
- if: ${{ steps.cache-pip.outputs.cache-hit != 'true' }}
name: List the state of pip dependencies
continue-on-error: true
run: pip freeze
- name: Install pip dependencies
# see https://python-poetry.org/docs/#ci-recommendations
run: |
python -m pip install --upgrade pip setuptools
pip install flake8
python -m venv $POETRY_HOME
$POETRY_HOME/bin/pip install poetry==$POETRY_VERSION
$POETRY_HOME/bin/poetry --version
- name: Cache poetry dependencies
id: cache-poetry
uses: actions/cache@v3
env:
cache-name: cache-poetry-dependencies
with:
path: ${{ env.POETRY_HOME}}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/poetry.lock') }}
- if: ${{ steps.cache-poetry.outputs.cache-hit != 'true' }}
name: List the state of poetry dependencies
continue-on-error: true
run: $POETRY_HOME/bin/poetry show --tree
- name: Install poetry dependencies
run: |
$POETRY_HOME/bin/poetry install --no-root --no-interaction
- 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: |
export PYTHONPATH=$PYTHONPATH:.
# make sure pytest will use color in terminal output
export FORCE_COLOR="true"
$POETRY_HOME/bin/poetry run pytest