Skip to content

CI: devicetree: Add compliance and formatting check #92334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/compliance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ jobs:
west config manifest.group-filter -- +ci,-optional
west update -o=--depth=1 -n 2>&1 1> west.update.log || west update -o=--depth=1 -n 2>&1 1> west.update2.log
- name: Setup Node.js
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
with:
node-version: "20"

- name: Install dependencies
run: npm i -g dts-linter@0.0.0-beta4

- name: Run Compliance Tests
continue-on-error: true
id: compliance
Expand Down
40 changes: 40 additions & 0 deletions scripts/ci/check_compliance.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,46 @@
"'required: false' is redundant, please remove"
)

class DevicetreeLintingCheck(ComplianceTest):
"""
Checks if we are introducing syntax or formatting issues to devicetree files.
"""
name = "DevicetreeLinting"
doc = "See https://docs.zephyrproject.org/latest/contribute/style/devicetree.html for more details."

def run(self):
# Check if node is installed
if not shutil.which("node"):
self.skip("Node.js is not installed or not in PATH")

# Check if dts-linter is installed
if not shutil.which("dts-linter"):
self.skip("dts-linter is not installed or not in PATH")

# Get changed DTS files
dts_files = []
for file in get_files(filter="d"):
if file.endswith((".dts", ".dtsi", ".overlay")):
dts_files.append(file)

if not dts_files:
self.skip('No DTS')
return # No DTS files to check

# Build command: dts-linter --outFile diff --format --files file1 --files file2 ...
cmd = ["dts-linter", "--format", "--diagnostics"]
for file in dts_files:
cmd.extend(["--files", file])

try:
result = subprocess.run(cmd, check=True, capture_output=True, cwd=GIT_TOP)

Check failure on line 515 in scripts/ci/check_compliance.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Python lint error (F841) see https://docs.astral.sh/ruff/rules/unused-variable

scripts/ci/check_compliance.py:515 Local variable `result` is assigned to but never used

Check warning on line 515 in scripts/ci/check_compliance.py

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

W0612

scripts/ci/check_compliance.py:515 Unused variable 'result' (unused-variable)
except subprocess.CalledProcessError as ex:
output = ex.output.decode("utf-8")
if output.strip():
self.failure(f"dts-linter found issues:\n{output}")
else:
self.failure("dts-linter failed with no output")

class KconfigCheck(ComplianceTest):
"""
Checks is we are introducing any new warnings/errors with Kconfig,
Expand Down
Loading