Skip to content

Commit 038c803

Browse files
committed
CI: devicetree: linting to check_compliance.py
Use dts-linter to check each touched file in PR Signed-off-by: Kyle Micallef Bonnici <kylebonnici@hotmail.com>
1 parent 322da1d commit 038c803

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

.github/workflows/compliance.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ jobs:
6060
west config manifest.group-filter -- +ci,-optional
6161
west update -o=--depth=1 -n 2>&1 1> west.update.log || west update -o=--depth=1 -n 2>&1 1> west.update2.log
6262
63+
- name: Setup Node.js
64+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
65+
with:
66+
node-version: "20"
67+
68+
- name: Install dependencies
69+
run: npm i -g dts-linter@0.0.0-beta4
70+
6371
- name: Run Compliance Tests
6472
continue-on-error: true
6573
id: compliance

scripts/ci/check_compliance.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,46 @@ def required_false_check(self, binding):
480480
"'required: false' is redundant, please remove"
481481
)
482482

483+
class DevicetreeLintingCheck(ComplianceTest):
484+
"""
485+
Checks if we are introducing syntax or formatting issues to devicetree files.
486+
"""
487+
name = "DevicetreeLinting"
488+
doc = "See https://docs.zephyrproject.org/latest/contribute/style/devicetree.html for more details."
489+
490+
def run(self):
491+
# Check if node is installed
492+
if not shutil.which("node"):
493+
self.skip("Node.js is not installed or not in PATH")
494+
495+
# Check if dts-linter is installed
496+
if not shutil.which("dts-linter"):
497+
self.skip("dts-linter is not installed or not in PATH")
498+
499+
# Get changed DTS files
500+
dts_files = []
501+
for file in get_files(filter="d"):
502+
if file.endswith((".dts", ".dtsi", ".overlay")):
503+
dts_files.append(file)
504+
505+
if not dts_files:
506+
self.skip('No DTS')
507+
return # No DTS files to check
508+
509+
# Build command: dts-linter --outFile diff --format --files file1 --files file2 ...
510+
cmd = ["dts-linter", "--format", "--diagnostics"]
511+
for file in dts_files:
512+
cmd.extend(["--files", file])
513+
514+
try:
515+
result = subprocess.run(cmd, check=True, capture_output=True, cwd=GIT_TOP)
516+
except subprocess.CalledProcessError as ex:
517+
output = ex.output.decode("utf-8")
518+
if output.strip():
519+
self.failure(f"dts-linter found issues:\n{output}")
520+
else:
521+
self.failure("dts-linter failed with no output")
522+
483523
class KconfigCheck(ComplianceTest):
484524
"""
485525
Checks is we are introducing any new warnings/errors with Kconfig,

0 commit comments

Comments
 (0)