-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (85 loc) · 3.93 KB
/
pytest.yaml
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# **************************************************************************************************************** #
# This workflow will install Python dependencies, and run `pytest --cov` on all files recursively from the `pytest-root-dir`
# The workflow is also configured to exit with error if minimum individual file or total pytest coverage minimum not met
# If the workflow exits with error, an informative issue is created for the repo alerting the user
# If the workflow succeeds, a commit message is generated with the `pytest --cov` markdown table
#
# Variables to set:
# * pytester action:
# * pytest-root-dir: top-level directory to recursively check all .py files for `pytest --cov`
# * cov-omit-list: comma separated str of all files and/or dirs to ignore
# * env:
# * COVERAGE_SINGLE: minimum individual file coverage required
# * COVERAGE_TOTAL: minimum total coverage required
#
# Action outputs:
# * output-table: `pytest --cov` markdown output table
# * cov-threshold-single-fail: `false` if any single file coverage less than `cov-threshold-single`, else `true`
# * cov-threshold-total-fail: `false` if total coverage less than `cov-threshold-total`, else `true`
#
# Workflows used:
# * actions/checkout@v2: checkout files to perform additional actions on
# * alexanderdamiani/[email protected]: runs `pytest --cov` and associated functions
# * nashmaniac/[email protected]: creates issue for repo
# * peter-evans/commit-comment@v1: adds message to commit
# **************************************************************************************************************** #
# ------NOTE need to steadily increase Test Coverage as i add more test cases
name: pytester-cov workflow
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
env:
COVERAGE_SINGLE: 80
COVERAGE_TOTAL: 80
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: pytest
id: pytest
uses: alexanderdamiani/[email protected]
with:
pytest-root-dir: '.'
cov-omit-list: 'initial_data/, gen/, .github/, venv/'
cov-threshold-single: ${{ env.COVERAGE_TOTAL }}
cov-threshold-total: ${{ env.COVERAGE_SINGLE }}
- name: Coverage single fail - new issue
if: ${{ steps.pytest.outputs.cov-threshold-single-fail == 'true' }}
uses: nashmaniac/[email protected]
with:
title: Pytest coverage single falls below minimum ${{ env.COVERAGE_SINGLE }}
token: ${{secrets.PYTEST_GITHUB_TOKEN}}
assignees: ${{github.actor}}
labels: coverage-below-minimum
body: ${{ steps.pytest.outputs.output-table }}
- name: Coverage single fail - exit
if: ${{ steps.pytest.outputs.cov-threshold-single-fail == 'true' }}
run: |
echo "cov single fail ${{ steps.pytest.outputs.cov-threshold-single-fail }}"
exit 0
- name: Coverage total fail - new issue
if: ${{ steps.pytest.outputs.cov-threshold-total-fail == 'true' }}
uses: nashmaniac/[email protected]
with:
title: Pytest coverage total falls below minimum ${{ env.COVERAGE_TOTAL }}
token: ${{secrets.PYTEST_GITHUB_TOKEN}}
assignees: ${{github.actor}}
labels: worflow-coverage-below-minimum
body: ${{ steps.pytest.outputs.output-table }}
- name: Coverage total fail - exit
if: ${{ steps.pytest.outputs.cov-threshold-total-fail == 'true' }}
run: |
echo "cov single fail ${{ steps.pytest.outputs.cov-threshold-total-fail }}"
exit 0
- name: Commit pytest coverage table
uses: peter-evans/commit-comment@v1
with:
body: ${{ steps.pytest.outputs.output-table }}