Skip to content

Commit a97a1e0

Browse files
committed
github: workflow: First version of compliance
Adding content to workflow for running compliance on PRs. Signed-off-by: Tommi Rantanen <tommi.rantanen@nordicsemi.no>
1 parent aecaf13 commit a97a1e0

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

.checkpatch.conf

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--emacs
2+
--summary-file
3+
--show-types
4+
--max-line-length=100
5+
--min-conf-desc-length=1
6+
7+
--ignore BRACES
8+
--ignore PRINTK_WITHOUT_KERN_LEVEL
9+
--ignore SPLIT_STRING
10+
--ignore VOLATILE
11+
--ignore CONFIG_EXPERIMENTAL
12+
--ignore PREFER_KERNEL_TYPES
13+
--ignore PREFER_SECTION
14+
--ignore AVOID_EXTERNS
15+
--ignore NETWORKING_BLOCK_COMMENT_STYLE
16+
--ignore DATE_TIME
17+
--ignore MINMAX
18+
--ignore CONST_STRUCT
19+
--ignore FILE_PATH_CHANGES
20+
--ignore SPDX_LICENSE_TAG
21+
--ignore C99_COMMENT_TOLERANCE
22+
--ignore REPEATED_WORD
23+
--ignore UNDOCUMENTED_DT_STRING
24+
--ignore DT_SPLIT_BINDING_PATCH
25+
--ignore DT_SCHEMA_BINDING_PATCH
26+
--ignore TRAILING_SEMICOLON
27+
--ignore COMPLEX_MACRO
28+
--ignore MULTISTATEMENT_MACRO_USE_DO_WHILE
29+
--ignore ENOSYS
30+
--ignore IS_ENABLED_CONFIG
31+
--ignore EMBEDDED_FUNCTION_NAME
32+
--ignore MACRO_WITH_FLOW_CONTROL

.github/workflows/compliance.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Compliance
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
compliance_job:
8+
runs-on: ubuntu-24.04
9+
name: Run compliance checks on patch series (PR)
10+
11+
# Skip job if it was triggered by Renovate Bot
12+
if: ${{ !contains(github.actor, 'renovate') }}
13+
14+
steps:
15+
- name: Installation
16+
run: |
17+
apt-get update && apt-get install --no-install-recommends -y libmagic1 git
18+
pip install west gitlint
19+
20+
- name: Checkout the code
21+
uses: actions/checkout@v4
22+
with:
23+
path: serial_modem
24+
ref: ${{ github.event.pull_request.head.sha }}
25+
fetch-depth: 0
26+
27+
- name: Initialize
28+
working-directory: serial_modem
29+
run: |
30+
if [ ! -d "../.west" ]; then
31+
west init -l .
32+
else
33+
echo ".west folder already exists, skipping west init."
34+
fi
35+
west update -o=--depth=1 -n
36+
37+
- name: Install zephyr requirements
38+
run: |
39+
pip install -r zephyr/scripts/requirements-actions.txt
40+
# Junitparser v3 and 4 don't work with check_compliance.py
41+
pip install --upgrade junitparser==2.8.0
42+
43+
- name: Run Compliance Tests
44+
id: compliance
45+
shell: bash
46+
env:
47+
BASE_REF: ${{ github.base_ref }}
48+
working-directory: serial_modem
49+
run: |
50+
export ZEPHYR_BASE="../zephyr"
51+
$ZEPHYR_BASE/scripts/ci/check_compliance.py \
52+
--annotate \
53+
-m Codeowners \
54+
-m Devicetree \
55+
-m Gitlint \
56+
-m Identity \
57+
-m Nits \
58+
-m pylint \
59+
-m checkpatch \
60+
-c origin/${BASE_REF}.. || \
61+
echo "COMPLIANCE_FAILED=true" >> $GITHUB_ENV
62+
63+
- name: Process Compliance Results
64+
working-directory: serial_modem
65+
shell: bash
66+
run: |
67+
# Check for compliance.xml existence
68+
if [[ ! -s "compliance.xml" ]]; then
69+
echo "::error::compliance.xml file is missing or empty"
70+
exit 1
71+
fi
72+
73+
# Initialize exit code
74+
exit_code=0
75+
76+
# Define error files to check
77+
error_files=(
78+
"Nits.txt"
79+
"checkpatch.txt"
80+
"Identity.txt"
81+
"Gitlint.txt"
82+
"pylint.txt"
83+
"Devicetree.txt"
84+
"Kconfig.txt"
85+
"KconfigBasic.txt"
86+
"Codeowners.txt"
87+
)
88+
89+
# Process each error file
90+
for file in "${error_files[@]}"; do
91+
if [[ -s $file ]]; then
92+
errors=$(cat $file)
93+
errors="${errors//'%'/'%25'}"
94+
errors="${errors//$'\n'/'%0A'}"
95+
errors="${errors//$'\r'/'%0D'}"
96+
echo "::error file=${file}::$errors"
97+
exit_code=1
98+
fi
99+
done
100+
101+
# Check if compliance test failed
102+
if [[ "$COMPLIANCE_FAILED" == "true" ]]; then
103+
echo "::error::Compliance tests failed. Please check the logs for details."
104+
exit_code=1
105+
fi
106+
107+
exit $exit_code

0 commit comments

Comments
 (0)