Skip to content

Commit 6edc5bb

Browse files
committed
Update tox and github actions
- Convert .coverage file into a folder for parallel mode. You may will need to delete the file if it exists before running tox tests. - Enable parallel coverage mode. - Test python versions 3.7 - 3.11 - Work around the removal of 3.7 from Ubuntu in github actions - Attach coverage data to the github action report
1 parent 8514a07 commit 6edc5bb

File tree

3 files changed

+156
-10
lines changed

3 files changed

+156
-10
lines changed

.coveragerc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ skip_empty = true
99
source = preditor
1010
omit =
1111
*/site-packages/*
12+
tests/*
13+
# This file is automatically generated by setuptools_scm
14+
preditor/version.py
15+
parallel=True
1216
relative_files=True
17+
data_file=.coverage/.coverage

.github/workflows/static-analysis-and-test.yml

Lines changed: 131 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ on: [push, pull_request]
55
jobs:
66

77
static-analysis:
8+
# We want to run on external PRs, but not on our own internal PRs as they'll
9+
# be run by the push to the branch. Without this if check, checks are
10+
# duplicated since internal PRs match both the push and pull_request events.
11+
# https://github.com/psf/black/blob/f51e53726b39a177355a7917c91c56f390dda7ef/.github/workflows/lint.yml#L7-L12
12+
if:
13+
github.event_name == 'push' ||
14+
github.event.pull_request.head.repo.full_name != github.repository
15+
816
runs-on: ubuntu-latest
917

1018
steps:
@@ -32,15 +40,22 @@ jobs:
3240

3341

3442
test:
43+
# We want to run on external PRs, but not on our own internal PRs as they'll
44+
# be run by the push to the branch. Without this if check, checks are
45+
# duplicated since internal PRs match both the push and pull_request events.
46+
if:
47+
github.event_name == 'push' ||
48+
github.event.pull_request.head.repo.full_name != github.repository
49+
3550
strategy:
3651
matrix:
3752
os: ['ubuntu-latest']
38-
python: [3.7, 3.8, 3.9]
39-
# Works around the depreciation of python 3.6 for ubuntu
53+
python: ['3.8', '3.9', '3.10', '3.11']
54+
# Works around the depreciation of python 3.6, 3.7 for ubuntu
4055
# https://github.com/actions/setup-python/issues/544
4156
include:
42-
- os: 'ubuntu-20.04'
43-
python: 3.6
57+
- os: 'ubuntu-22.04'
58+
python: '3.7'
4459

4560
runs-on: ${{ matrix.os }}
4661

@@ -60,4 +75,115 @@ jobs:
6075
6176
- name: Run Tox
6277
run: |
63-
tox -e py
78+
tox -e begin,py -- --tb short
79+
80+
- name: Upload coverage
81+
uses: actions/upload-artifact@v4
82+
with:
83+
name: coverage-${{ matrix.os }}-${{ matrix.python }}
84+
path: .coverage/*
85+
include-hidden-files: true
86+
retention-days: 1
87+
88+
89+
coverage:
90+
# We want to run on external PRs, but not on our own internal PRs as they'll
91+
# be run by the push to the branch. Without this if check, checks are
92+
# duplicated since internal PRs match both the push and pull_request events.
93+
if:
94+
github.event_name == 'push' ||
95+
github.event.pull_request.head.repo.full_name != github.repository
96+
97+
needs: test
98+
99+
runs-on: ubuntu-latest
100+
steps:
101+
- name: Checkout code
102+
uses: actions/checkout@v4
103+
104+
- name: Setup Python
105+
uses: actions/setup-python@v5
106+
with:
107+
python-version: "3.x"
108+
109+
- name: Install dependencies
110+
run: |
111+
python -m pip install --upgrade pip
112+
python -m pip install tox coverage[toml]
113+
114+
# Ensure version.py is created so coverage can read it's source
115+
- name: Run begin
116+
run: |
117+
tox -e begin
118+
119+
- name: Download coverage artifacts
120+
uses: actions/download-artifact@v4
121+
with:
122+
path: .coverage/
123+
pattern: coverage-*
124+
merge-multiple: true
125+
126+
# Tox runs `coverage combine` and `coverage xml`
127+
- name: Combine coverage and report
128+
run: |
129+
tox -e end
130+
131+
# Report and write to summary.
132+
python -m coverage report --format=markdown >> $GITHUB_STEP_SUMMARY
133+
134+
# Write html coverage report to upload as an artifact
135+
python -m coverage html
136+
137+
# # Report again and fail if under 100%.
138+
# python -m coverage report --fail-under=100
139+
140+
- name: Upload HTML report if check failed.
141+
uses: actions/upload-artifact@v4
142+
with:
143+
name: html-report
144+
path: htmlcov
145+
# # TODO: If we get 100% coverage we can re-enable this and the
146+
# # `--fail-under` check so pull requests fail if the dev doesn't
147+
# # add tests for new code.
148+
# if: ${{ failure() }}
149+
150+
151+
pip-package:
152+
# We want to run on external PRs, but not on our own internal PRs as they'll
153+
# be run by the push to the branch. Without this if check, checks are
154+
# duplicated since internal PRs match both the push and pull_request events.
155+
if:
156+
github.event_name == 'push' ||
157+
github.event.pull_request.head.repo.full_name != github.repository
158+
159+
# Build and upload pip packages as artifacts so we can inspect them and
160+
# ensure they are correct for actual release
161+
runs-on: ubuntu-latest
162+
163+
steps:
164+
- name: Checkout code
165+
uses: actions/checkout@v4
166+
with:
167+
fetch-depth: 0
168+
169+
- name: Setup Python
170+
uses: actions/setup-python@v5
171+
with:
172+
python-version: "3.x"
173+
174+
- name: Install dependencies
175+
run: |
176+
python -m pip install --upgrade pip
177+
python -m pip install --upgrade build setuptools wheel twine
178+
179+
- name: Build wheel
180+
run: |
181+
python -m build --wheel --sdist
182+
183+
- name: Upload packages.
184+
uses: actions/upload-artifact@v4
185+
with:
186+
name: pip-packages
187+
path: |
188+
dist/preditor-*.whl
189+
dist/preditor-*.tar.gz

tox.ini

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[tox]
2-
envlist = begin,py{27,36,37,38,39},modernize,black,flake8
2+
envlist = modernize,begin,py{27,36,37,38,39,310,311},end,black,flake8
33
skip_missing_interpreters = True
44
skipsdist = True
55

@@ -23,8 +23,7 @@ commands =
2323
# Ensure the version.py file is created
2424
python setup.py egg_info
2525

26-
python -m coverage run -m pytest {posargs:tests/}
27-
python -m coverage report
26+
coverage run -m pytest {tty:--color=yes} {posargs:tests/}
2827

2928
[testenv:modernize]
3029
# Test compatibility with python 2 and 3
@@ -37,12 +36,28 @@ commands =
3736
# in this test.
3837
python -m modernize -f print -f import -f basestring -f unicode_type --enforce ./preditor
3938

40-
4139
[testenv:begin]
4240
basepython = python3
41+
deps =
42+
coverage[toml]
43+
build
44+
commands =
45+
coverage erase
46+
47+
[testenv:py{27,36,37,38,39,310,311}]
48+
depends = begin
49+
50+
[testenv:end]
51+
basepython = python3
52+
depends =
53+
begin
54+
py{27,36,37,38,39,310,311}
55+
parallel_show_output = True
4356
deps =
4457
coverage
45-
commands = coverage erase
58+
commands =
59+
coverage combine
60+
coverage report
4661

4762
[testenv:black]
4863
basepython = python3

0 commit comments

Comments
 (0)