-
Notifications
You must be signed in to change notification settings - Fork 6
201 lines (173 loc) · 7.83 KB
/
CheckCodeQuality.yml
File metadata and controls
201 lines (173 loc) · 7.83 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# ==================================================================================================================== #
# Authors: #
# Patrick Lehmann #
# #
# ==================================================================================================================== #
# Copyright 2025-2026 The pyTooling Authors #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
# #
# SPDX-License-Identifier: Apache-2.0 #
# ==================================================================================================================== #
name: Code Quality Checking
on:
workflow_call:
inputs:
ubuntu_image_version:
description: 'Ubuntu image version.'
required: false
default: '24.04'
type: string
python_version:
description: 'Python version.'
required: false
default: '3.14'
type: string
package_directory:
description: 'The package''s directory'
required: true
type: string
requirements:
description: 'Python dependencies to be installed through pip.'
required: false
default: '-r requirements.txt'
type: string
bandit:
description: 'Run bandit checks.'
required: false
default: 'true'
type: string
radon:
description: 'Run radon checks.'
required: false
default: 'true'
type: string
pylint:
description: 'Run pylint checks.'
required: false
default: 'true'
type: string
artifact:
description: 'Name of the package artifact.'
required: true
type: string
jobs:
Bandit:
name: 🚨 Security Scanning (Bandit)
runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}"
if: inputs.bandit == 'true'
steps:
- name: ⏬ Checkout repository
uses: actions/checkout@v6
with:
lfs: true
submodules: true
- name: 🐍 Setup Python ${{ inputs.python_version }}
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python_version }}
- name: ⚙ Install dependencies for running bandit
run: python -m pip install --disable-pip-version-check bandit
- name: 👮 Bandit
id: bandit
if: inputs.artifact != ''
run: |
set +e
ANSI_LIGHT_RED=$'\x1b[91m'
ANSI_LIGHT_GREEN=$'\x1b[92m'
ANSI_LIGHT_BLUE=$'\x1b[94m'
ANSI_NOCOLOR=$'\x1b[0m'
bandit_directory=report/bandit
bandit_fullpath=report/bandit/report.xml
tee "${GITHUB_OUTPUT}" <<EOF
bandit_directory=${bandit_directory}
bandit_fullpath=${bandit_fullpath}
EOF
mkdir -p ${bandit_directory}
printf "\nRun bandit ...\n"
bandit -c pyproject.toml -r ${{ inputs.package_directory }} -f xml -o ${bandit_fullpath}
if [[ $? -eq 0 ]]; then
printf "Bandit result: ${ANSI_LIGHT_GREEN}[PASSED]${ANSI_NOCOLOR}\n"
printf "bandit_passed=true\n" >> "${GITHUB_OUTPUT}"
else
faults=$(grep -Poh '(?<=<testsuite\sname="bandit"\stests=")(\d+)(?=">)' ${bandit_fullpath})
printf "Bandit result: ${ANSI_LIGHT_RED}[FAILED]${ANSI_NOCOLOR}\n"
printf " ${ANSI_LIGHT_RED}Bandit found %s issues.${ANSI_NOCOLOR}\n" "${faults}"
printf "::error title=%s::%s\n" "🚨 Security Scanning (Bandit)" "Bandi found ${faults} issues."
printf "bandit_passed=false\n" >> "${GITHUB_OUTPUT}"
printf "::group::${ANSI_LIGHT_BLUE}JUnit XML report created by Bandit ...${ANSI_NOCOLOR}\n"
cat ${bandit_fullpath}
printf "\n::endgroup::\n"
fi
- name: 📊 Publish Bandit Results
uses: dorny/test-reporter@v2
if: steps.bandit.outputs.bandit_passed == 'false'
continue-on-error: true
with:
name: 'Bandit Results'
path: ${{ steps.bandit.outputs.bandit_fullpath }}
reporter: java-junit
Radon:
name: ☢️ Metrics and Complexity
runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}"
if: inputs.radon == 'true'
steps:
- name: ⏬ Checkout repository
uses: actions/checkout@v6
with:
lfs: true
submodules: true
- name: 🐍 Setup Python ${{ inputs.python_version }}
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python_version }}
- name: ⚙ Install dependencies for running radon
run: python -m pip install --disable-pip-version-check radon
- name: Code Metrics
# if: inputs.artifact != ''
run: |
radon raw ${{ inputs.package_directory }} -s
- name: Code Complexity
# if: inputs.artifact != ''
run: |
radon cc ${{ inputs.package_directory }} --total-average
- name: Halstead Complexity Metrics
# if: inputs.artifact != ''
run: |
radon hal ${{ inputs.package_directory }}
- name: Maintainability Index
# if: inputs.artifact != ''
run: |
radon mi ${{ inputs.package_directory }} -s
PyLint:
name: 🩺 Linting
runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}"
if: inputs.pylint == 'true'
steps:
- name: ⏬ Checkout repository
uses: actions/checkout@v6
with:
lfs: true
submodules: true
- name: 🐍 Setup Python ${{ inputs.python_version }}
uses: actions/setup-python@v6
with:
python-version: ${{ inputs.python_version }}
- name: ⚙ Install dependencies for running PyLint
run: |
python -m pip install --disable-pip-version-check pylint
python -m pip install --disable-pip-version-check ${{ inputs.requirements }}
- name: 🩺 PyLint
# if: inputs.artifact != ''
run: |
pylint ${{ inputs.package_directory }}