Skip to content

Commit 6d41a8f

Browse files
authored
#320: Add Python "linter" to CI/CD (#345)
* #320: add .pylintrc file for pylint configuration and add new gihub action to run pylint * #320: fix bad pylint option * #320: github workflow continue-on-error set on the `Run pylint` step level * #320: set pylint message format to the github actions warning message format * #320: test multiline strings for github messages * #320: test multiline strings for github messages using python call * #320: test multiline strings for github messages using python call update 1 * #320: test multiline strings for github messages using python call update 2 * #320: test multiline strings for github messages using python call update 3 * #320: test multiline strings for github messages using python call update 4 * #320: test multiline strings for github messages using python call update 5 * #320: test multiline strings for github messages using python call update 6 * #320: test multiline strings for github messages using python call update 7 * #320: test multiline strings for github messages using python call update 8 * #320: test multiline strings for github messages using python call update 9 * #320: test add actions_toolkit from pip to report messages * #320: test add actions_toolkit from pip to report messages update 1 * #320: test add actions_toolkit from pip to report messages update 2 * #320: test add actions_toolkit from pip to report messages update 3 * #320: test add actions_toolkit from pip to report messages update 4 * #320: test add actions_toolkit from pip to report messages update 5 * #320: test add actions_toolkit from pip to report messages update 6 * #320: test add actions_toolkit from pip to report messages update 7 * #320: test add actions_toolkit from pip to report messages update 8 * #320: test add actions_toolkit from pip to report messages update 9 * #320: test add actions_toolkit from pip to report messages update 10 * #320: test change base image for code analysis action * #320: back to basic pylint call * #320: back to basic pylint call update * #320: add pylint matcher for actions * #320: add pylint matcher from other existing source * #320: add pylint matcher from other existing source * #320: add pylint matcher split into warning and error matchers * #320: add pylint matchers update * #320: add pylint matchers update * #320: add pylint report as upload artifact * #320: report as text and badget as upload artifacts * #320: update command * #320: update command * #320: try to understand problem with pylint output path * #320: try to use absolute path for artifact * #320: create output directory for artifacts files * #320: create output directory for artifacts files correction in yaml * #320: split artifacts report and badge * #320: finally group artifacts under pylint-report name * #320: try to restore commented code on old step calling pylint inside tox environments * #320: try to restore commented code on old step calling pylint inside tox environments * #320: use pylintrc file as pylint configuration file in tox & fix badge conditions * #320: fix workflow step condition * #320: add ignore_errors to the pylint run to enable CI to continue * #320: add ignore_outcome to the pylint run to enable CI to continue * #320: publish pylint and coverage badges on gh-pages branch & integrate display in README * #320: refactor unit-tests.yml add environment variable * #320: fix issue with python 3.9 no badges causing clear of generated badges * #320: rename unit-test workflow to code-quality bor better undestanding - means unit tests & pylint & coverage * #320: create and publish badges if we push on develop branch * #320: uppercase first letter for badge labels * #320: pylint set max-line-length to 120 and add vtk to ignored modules to prevent E1101 errors * #320: merge problemMatcher files for pylint into a single file * #320: try to add notice pylint matcher event if not available as doc says * #320: try to fix CI error with ubuntu * #320: try to fix CI error with ubuntu - 2nd attempt * #320: try to fix CI error with ubuntu - 3rd attempt * #320: try to fix CI error with ubuntu - 3rd attempt * #320: try to fix CI error with ubuntu - 4th attempt use ubuntu 20.04 * #320: try to fix CI error with ubuntu - 4th attempt use ubuntu 20.04 * #320: try to fix CI error with ubuntu - 5th attempt use ubuntu 23.04 * #320: try to fix CI error with ubuntu - 6th attemp use Ubuntu latest but remove apt upgrade * #320: try to fix CI error with ubuntu - 7th attemp use Ubuntu latest and apt upgrade but mark problematic packages * #320: try to fix CI error with ubuntu - 7th attemp use Ubuntu latest and apt upgrade but hold problematic packages * #320: fix finally CI error with ubuntu latest * #320: remove trailing white space * #320: remove another trailing white space * #320: test: use same action to deploy badge and same deployment branch than for docs * #320: use finally specific deploy-badges branch for badges deployment * #320: update README fix links to badges and LBAF app path in doc * #320: upgrade some actions uses * #320: finally restore `develop` as source branch to deploy badges
1 parent 1b6b49a commit 6d41a8f

File tree

6 files changed

+717
-63
lines changed

6 files changed

+717
-63
lines changed

.github/workflows/code-quality.yml

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Code Quality (Unit tests, Coverage, PyLint)
2+
on: push
3+
concurrency:
4+
group: CI-${{ github.head_ref }}
5+
cancel-in-progress: true
6+
7+
jobs:
8+
code-quality:
9+
continue-on-error: false
10+
strategy:
11+
max-parallel: 10
12+
fail-fast: false
13+
matrix:
14+
os: [ubuntu-latest]
15+
python-version: ['3.8', '3.9']
16+
runs-on: ${{ matrix.os }}
17+
env:
18+
deploy_badges_src_branch: develop
19+
deploy_badges_dst_branch: deploy-badges
20+
steps:
21+
- uses: actions/checkout@v3
22+
23+
- name: Install packages
24+
run: |
25+
sudo apt-get update -y
26+
sudo apt-get install -y git xvfb
27+
28+
- name: Python Setup
29+
uses: actions/setup-python@v4
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
33+
- name: Install dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install -r requirements-${{ matrix.python-version }}.txt
37+
pip install tox-gh-actions
38+
39+
- name: Register Github Actions Problem matchers (pylint)
40+
run: |
41+
echo "::add-matcher::.github/workflows/matchers/pylint.json"
42+
43+
- name: Running Unit-tests, Coverage, Pylint using TOX
44+
id: run_tox
45+
run: |
46+
tox
47+
if [ -e "./artifacts/pylint.txt" ]; then PYLINT_REPORT_EXISTS="true"; else PYLINT_REPORT_EXISTS="false"; fi
48+
echo "pylint_report_exists=$PYLINT_REPORT_EXISTS" >> $GITHUB_OUTPUT
49+
if [ -e "./artifacts/coverage.txt" ]; then COVERAGE_REPORT_EXISTS="true"; else COVERAGE_REPORT_EXISTS="false"; fi
50+
echo "coverage_report_exists=$COVERAGE_REPORT_EXISTS" >> $GITHUB_OUTPUT
51+
52+
- name: Upload pylint artifact
53+
if: |
54+
steps.run_tox.outputs.pylint_report_exists == 'true'
55+
uses: actions/upload-artifact@v3
56+
with:
57+
name: pylint
58+
path: artifacts/pylint.txt
59+
retention-days: 1
60+
61+
- name: Upload coverage artifact
62+
if: |
63+
steps.run_tox.outputs.coverage_report_exists == 'true'
64+
uses: actions/upload-artifact@v3
65+
with:
66+
name: coverage
67+
path: artifacts/coverage.txt
68+
retention-days: 1
69+
70+
- name: Create Pylint badge
71+
if: |
72+
github.ref_name == env.deploy_badges_src_branch &&
73+
steps.run_tox.outputs.pylint_report_exists == 'true'
74+
run: |
75+
mkdir -p badges
76+
PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./artifacts/pylint.txt)
77+
anybadge --label=Pylint --file=badges/pylint.svg --value=$PYLINT_SCORE 2=red 4=orange 8=yellow 10=green
78+
79+
- name: Create Coverage badge
80+
if: |
81+
github.ref_name == env.deploy_badges_src_branch &&
82+
steps.run_tox.outputs.coverage_report_exists == 'true'
83+
run: |
84+
mkdir -p badges
85+
COVERAGE_SCORE=$(sed -n '/TOTAL/,/%/p' artifacts/coverage.txt | rev | cut -d" " -f1 | rev | tr -d % )
86+
anybadge --label=Coverage --file=badges/coverage.svg --value=$COVERAGE_SCORE coverage
87+
88+
- name: Deploy badges
89+
uses: JamesIves/github-pages-deploy-action@v4
90+
if: github.ref_name == env.deploy_badges_src_branch &&
91+
(steps.run_tox.outputs.coverage_report_exists == 'true' || steps.run_tox.outputs.pylint_report_exists == 'true')
92+
with:
93+
branch: ${{ env.deploy_badges_dst_branch }}
94+
folder: ./badges
95+
clean: false
96+
commit-message: ${{ github.event.head_commit.message }}
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
{
2+
"problemMatcher": [
3+
{
4+
"owner": "pylint-error",
5+
"severity": "error",
6+
"pattern": [
7+
{
8+
"regexp": "^(.+):(\\d+):(\\d+):\\s([FE]\\d{4}):\\s(.+)$",
9+
"file": 1,
10+
"line": 2,
11+
"column": 3,
12+
"message": 5,
13+
"code": 4
14+
}
15+
]
16+
},
17+
{
18+
"owner": "pylint-warning",
19+
"severity": "warning",
20+
"pattern": [
21+
{
22+
"regexp": "^(.+):(\\d+):(\\d+):\\s([W]\\d{4}):\\s(.+)$",
23+
"file": 1,
24+
"line": 2,
25+
"column": 3,
26+
"message": 5,
27+
"code": 4
28+
}
29+
]
30+
},
31+
{
32+
"owner": "pylint-notice",
33+
"severity": "notice",
34+
"pattern": [
35+
{
36+
"regexp": "^(.+):(\\d+):(\\d+):\\s([CR]\\d{4}):\\s(.+)$",
37+
"file": 1,
38+
"line": 2,
39+
"column": 3,
40+
"message": 5,
41+
"code": 4
42+
}
43+
]
44+
}
45+
]
46+
}

.github/workflows/unit-tests.yml

-60
This file was deleted.

0 commit comments

Comments
 (0)