-
Notifications
You must be signed in to change notification settings - Fork 3
138 lines (134 loc) · 5.72 KB
/
pull_request.yml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: QMI Python CI runner on pull request
# This runner runs on a pull request to main.
on:
pull_request:
branches: [ "main" ]
paths-ignore:
- README.md
- CHANGELOG.md
- .gitignore
- ACKNOWLEDGEMENTS.md
- LICENSE.md
- CONTRIBUTING.md
- TESTING.md
env:
# minimum pylint code quality score (max. 10)
PYLINT_MIN_SCORE: "9.00"
# minimum code coverage (goal: 80%; max. 100%)
COVERAGE_MIN_PERC: "68"
# maximum code complexity (goal: <= 15; unbounded)
COMPLEXITY_MAX_SCORE: "38"
# minimum maintainability index (goal: >=20; max. 100)
MAINTAINABILITY_MIN_INDEX: "10.62"
SOURCE_DIRS: "qmi/"
BADGES_DIR: ".github/badges"
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 3
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
sudo apt-get update -qy
sudo apt-get install -y bc
pip install --upgrade pip
pip install -e '.[dev]'
pip install anybadge
- name: setup git config
run: |
git config user.name "Badge Bot"
git config user.mail "<>"
chmod u+w $BADGES_DIR
- name: pylint
run: |
pip install pylint
chmod a+x scripts/run_analysis_pylint.sh
SCORE=$( scripts/run_analysis_pylint.sh )
echo $SCORE > pylint_score
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l pylint -v $SCORE -f $BADGES_DIR/pylint.svg 2=red 4=orange 8=yellow 10=green; fi
# bc evaluates to `1` if relation is true
exit $( echo "$SCORE < $PYLINT_MIN_SCORE" | bc )
SCORE=$( cat pylint_score )
- name: upload pylint test results
uses: actions/upload-artifact@v3
with:
name: pylint-results
path: pylint.log
if: ${{ always() }}
- name: mypy
run: |
pip install mypy
mypy --namespace-packages $SOURCE_DIRS | tee mypy.log
if [ -n "$( tail -n 1 mypy.log | grep -e '^Succes' )" ]; then RESULT="pass"; else RESULT="fail"; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l mypy -v $RESULT -f $BADGES_DIR/mypy.svg fail=red pass=green; fi
- name: upload mypy test results
uses: actions/upload-artifact@v3
with:
name: mypy-results
path: mypy.log
if: ${{ always() }}
- name: radon-cc
run: |
pip install radon
chmod a+x scripts/run_analysis_cc.sh
MAX_SCORE=$( scripts/run_analysis_cc.sh $SOURCE_DIRS )
echo $MAX_SCORE > cc_max_score
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l radon-cc -v $MAX_SCORE -f $BADGES_DIR/radon-cc.svg 11=green 21=yellow 31=orange 100=red; fi
# bc evaluates to `1` if relation is true
exit $( echo "$MAX_SCORE > $COMPLEXITY_MAX_SCORE" | bc )
MAX_SCORE=$( cat cc_max_score )
- name: upload radon-cc results
uses: actions/upload-artifact@v3
with:
name: radon-cc-results
path: radon-cc.log
if: ${{ always() }}
- name: radon-mi
run: |
pip install radon
chmod a+x scripts/run_analysis_mi.sh
MIN_INDEX=$( scripts/run_analysis_mi.sh $SOURCE_DIRS )
echo $MIN_INDEX > mi_min_index
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l radon-mi -v $MIN_INDEX -f $BADGES_DIR/radon-mi.svg 10=red 20=orange 100=green; fi
exit $( echo "$MIN_INDEX < $MAINTAINABILITY_MIN_INDEX" | bc ) # bc evaluates to `1` if relation is true
MIN_INDEX=$( cat mi_min_index )
- name: upload radon-mi results
uses: actions/upload-artifact@v3
with:
name: radon-mi-results
path: radon-mi.log
if: ${{ always() }}
- name: coverage
run: |
pip install coverage
if coverage run --branch --source=$SOURCE_DIRS -m unittest discover --start-directory=tests --pattern="test_*.py"; then RESULT="pass"; else RESULT="fail"; fi
coverage report --show-missing --fail-under=$COVERAGE_MIN_PERC | tee coverage.log
COVERAGE_PERC=$(tail -1 coverage.log | grep -o '....$')
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l coverage -v $COVERAGE_PERC -f $BADGES_DIR/coverage.svg 60=red 80=orange 100=green; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then anybadge -o -l tests -v $RESULT -f $BADGES_DIR/tests.svg fail=red pass=green; fi
# coverage: '/^TOTAL.+?(\d+\%)$/'
- name: upload coverage results
uses: actions/upload-artifact@v3
with:
name: coverage-results
path: coverage.log
if: ${{ always() }}
- name: push all internal commits
run: |
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/pylint.svg; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/mypy.svg; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/radon-cc.svg; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/radon-mi.svg; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/coverage.svg; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then git add $BADGES_DIR/tests.svg; fi
if [ "${{ matrix.python-version }}" = "3.10" ]; then if git commit -m "commit badges" 2>/dev/null; then git push; fi; fi