1+ name : Code Quality (Tests, Linting, Coverage)
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.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 Tests, Pylint and Coverage 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 : Report Test results
53+ uses : phoenix-actions/test-reporting@v12
54+ if : success() || failure()
55+ with :
56+ name : Tests report (${{ matrix.os }}, ${{ matrix.python-version }})
57+ path : artifacts/unittest/reports/TEST-*.xml
58+ reporter : java-junit
59+ output-to : step-summary
60+
61+ - name : Upload pylint artifact
62+ if : |
63+ steps.run_tox.outputs.pylint_report_exists == 'true'
64+ uses : actions/upload-artifact@v3
65+ with :
66+ name : pylint
67+ path : artifacts/pylint.txt
68+ retention-days : 1
69+
70+ - name : Upload coverage artifact
71+ if : |
72+ steps.run_tox.outputs.coverage_report_exists == 'true'
73+ uses : actions/upload-artifact@v3
74+ with :
75+ name : coverage
76+ path : artifacts/coverage.txt
77+ retention-days : 1
78+
79+ - name : Create Pylint badge
80+ if : |
81+ github.ref_name == env.deploy_badges_src_branch &&
82+ steps.run_tox.outputs.pylint_report_exists == 'true'
83+ run : |
84+ mkdir -p badges
85+ PYLINT_SCORE=$(sed -n 's/^Your code has been rated at \([-0-9.]*\)\/.*/\1/p' ./artifacts/pylint.txt)
86+ anybadge --label=Pylint --file=badges/pylint.svg --value=$PYLINT_SCORE 2=red 4=orange 8=yellow 10=green
87+
88+ - name : Create Coverage badge
89+ if : |
90+ github.ref_name == env.deploy_badges_src_branch &&
91+ steps.run_tox.outputs.coverage_report_exists == 'true'
92+ run : |
93+ mkdir -p badges
94+ COVERAGE_SCORE=$(sed -n '/TOTAL/,/%/p' artifacts/coverage.txt | rev | cut -d" " -f1 | rev | tr -d % )
95+ anybadge --label=Coverage --file=badges/coverage.svg --value=$COVERAGE_SCORE coverage
96+
97+ - name : Deploy badges
98+ uses : JamesIves/github-pages-deploy-action@v4
99+ if : github.ref_name == env.deploy_badges_src_branch &&
100+ (steps.run_tox.outputs.coverage_report_exists == 'true' || steps.run_tox.outputs.pylint_report_exists == 'true')
101+ with :
102+ branch : ${{ env.deploy_badges_dst_branch }}
103+ folder : ./badges
104+ clean : false
105+ commit-message : ${{ github.event.head_commit.message }}
0 commit comments