Skip to content

Commit 017c7ca

Browse files
committed
refactor(ci)!: split workflow jobs into lint, test and coverage
1 parent fa3a773 commit 017c7ca

File tree

2 files changed

+101
-71
lines changed

2 files changed

+101
-71
lines changed

.flake8

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
11
[flake8]
2-
# The GitHub editor is 127 chars wide
2+
# Maximum line length allowed
33
max-line-length = 127
4+
5+
# Maximum allowed code complexity (10 is a reasonable threshold)
6+
max-complexity = 10
7+
8+
# Only check for specific error codes:
9+
# - E9 -> Syntax errors
10+
# - F63 -> Issues related to improper usage of `+=`, `-=`, etc.
11+
# - F7 -> Issues related to improper `break`, `continue`, etc.
12+
# - F82 -> Undefined names
13+
select = E9,F63,F7,F82
14+
15+
# Exclude `.venv` from linting (prevents checking dependencies)
16+
exclude = .venv
17+
18+
# Print the count of linting errors
19+
count = True
20+
21+
# Show the exact source of the error
22+
show-source = True
23+
24+
# Display statistics of errors at the end of the report
25+
statistics = True
26+
27+
# Enable verbose mode for more detailed output
28+
verbose = True

.github/workflows/python-app.yml

Lines changed: 75 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,82 +9,87 @@ on:
99
pull_request:
1010
branches: [ master ]
1111

12-
jobs:
12+
env:
13+
PYTHON_VERSION: 3.9
1314

14-
build:
15-
runs-on: ubuntu-latest
16-
steps:
17-
18-
- name: Checkout repository
19-
uses: actions/checkout@v4
20-
21-
- name: Set up Python 3.9
22-
uses: actions/setup-python@v5
23-
with:
24-
python-version: 3.9
25-
cache: 'pip'
26-
27-
- name: Install packages with pip
28-
run: |
29-
python -m pip install --upgrade pip
30-
pip install flake8 pytest pytest-cov
31-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
32-
33-
- name: Lint with Flake8
34-
run: |
35-
# stop the build if there are Python syntax errors or undefined names
36-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
39-
40-
- name: Run tests with pytest
41-
run: |
42-
pytest -v
43-
44-
- name: Generate coverage report with pytest-cov
45-
run: |
46-
pytest --cov=./ --cov-report=xml --cov-report=term
47-
48-
- name: Upload coverage report artifact
49-
uses: actions/upload-artifact@v4
50-
with:
51-
name: coverage.xml
52-
path: ./coverage.xml
53-
54-
coverage-codecov:
55-
needs: build
15+
jobs:
16+
lint:
5617
runs-on: ubuntu-latest
5718
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
5821

59-
- name: Checkout repository
60-
uses: actions/checkout@v4
22+
- name: Set up Python ${{ env.PYTHON_VERSION }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ env.PYTHON_VERSION }}
26+
cache: 'pip'
6127

62-
- name: Download coverage report artifact
63-
uses: actions/download-artifact@v4
64-
with:
65-
name: coverage.xml
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install -r requirements-lint.txt
6632
67-
- name: Upload coverage report to Codecov
68-
uses: codecov/codecov-action@v5
69-
with:
70-
token: ${{ secrets.CODECOV_TOKEN }}
71-
files: coverage.xml
33+
- name: Lint with Flake8
34+
run: |
35+
flake8 .
7236
73-
coverage-codacy:
74-
needs: build
37+
test:
7538
runs-on: ubuntu-latest
7639
steps:
77-
78-
- name: Checkout repository
79-
uses: actions/checkout@v4
80-
81-
- name: Download coverage report artifact
82-
uses: actions/download-artifact@v4
83-
with:
84-
name: coverage.xml
85-
86-
- name: Upload coverage report to Codacy
87-
uses: codacy/codacy-coverage-reporter-action@v1
88-
with:
89-
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
90-
coverage-reports: coverage.xml
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
43+
- name: Set up Python ${{ env.PYTHON_VERSION }}
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: ${{ env.PYTHON_VERSION }}
47+
cache: 'pip'
48+
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
pip install -r requirements-test.txt
53+
54+
- name: Run tests with pytest
55+
run: |
56+
pytest -v
57+
58+
- name: Generate coverage report
59+
run: |
60+
pytest --cov=./ --cov-report=xml --cov-report=term
61+
62+
- name: Upload coverage report artifact
63+
uses: actions/upload-artifact@v4
64+
with:
65+
name: coverage.xml
66+
path: ./coverage.xml
67+
68+
coverage:
69+
needs: test
70+
runs-on: ubuntu-latest
71+
strategy:
72+
matrix:
73+
service: [codecov, codacy]
74+
steps:
75+
- name: Checkout repository
76+
uses: actions/checkout@v4
77+
78+
- name: Download coverage report artifact
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: coverage.xml
82+
83+
- name: Upload coverage report to ${{ matrix.service }}
84+
if: ${{ matrix.service == 'codecov' }}
85+
uses: codecov/codecov-action@v5
86+
with:
87+
token: ${{ secrets.CODECOV_TOKEN }}
88+
files: coverage.xml
89+
90+
- name: Upload coverage report to ${{ matrix.service }}
91+
if: ${{ matrix.service == 'codacy' }}
92+
uses: codacy/codacy-coverage-reporter-action@v1
93+
with:
94+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
95+
coverage-reports: coverage.xml

0 commit comments

Comments
 (0)