Skip to content

Commit 6c70621

Browse files
committed
Add lint job with GitHub-hosted runner for external PRs
Signed-off-by: cdunning <cdunning@nvidia.com>
1 parent 7b81407 commit 6c70621

3 files changed

Lines changed: 131 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: CI
6+
7+
on:
8+
push:
9+
branches: [main]
10+
pull_request:
11+
branches: [main]
12+
workflow_dispatch:
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
lint:
20+
name: Lint
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 10
23+
container:
24+
image: python:3.10-slim
25+
steps:
26+
- name: Checkout repository
27+
uses: actions/checkout@v6
28+
29+
- name: Install lint dependencies
30+
env:
31+
PIP_BREAK_SYSTEM_PACKAGES: 1
32+
run: pip install --no-cache-dir flake8==7.3.0 reuse==5.1.0
33+
34+
- name: Run flake8
35+
run: flake8
36+
37+
- name: Run cpplint
38+
run: python ci/cpplint.py
39+
40+
- name: Check license headers (REUSE)
41+
run: ci/scripts/check_license.sh
42+
43+
- name: Check inline samples are up to date
44+
run: python test/tools/inline_samples.py --check

ci/cpplint.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env python3
2+
# SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
import os
7+
import sys
8+
9+
file_extensions = [
10+
".h",
11+
".hpp",
12+
".hh",
13+
".c",
14+
".C",
15+
".cpp",
16+
".cxx",
17+
".cc",
18+
".pyx",
19+
".pxd",
20+
]
21+
max_line_len = 100
22+
23+
24+
def should_lint(filename: str):
25+
return any(filename.endswith(x) for x in file_extensions)
26+
27+
28+
def lint(paths):
29+
num_errors = 0
30+
num_files = 0
31+
32+
def report_error(message: str):
33+
nonlocal num_errors
34+
print(f"{full_name[len(path) + 1:]}:{i + 1}: {message}", file=sys.stderr)
35+
num_errors += 1
36+
37+
for path in paths:
38+
for root, dirs, files in os.walk(path):
39+
for filename in files:
40+
if not should_lint(filename):
41+
continue
42+
full_name = os.path.join(root, filename)
43+
with open(full_name, "r") as f:
44+
for i, line in enumerate(f):
45+
if "noqa" in line:
46+
continue
47+
if "SPDX" in line:
48+
continue
49+
50+
length = len(line)
51+
if line.endswith("\n"):
52+
length -= 1
53+
if length > max_line_len:
54+
report_error(
55+
f"Line is longer than {max_line_len} characters"
56+
)
57+
if length > 0 and line[length - 1].isspace():
58+
report_error("Trailing whitespace at the end of the line")
59+
num_files += 1
60+
61+
if num_errors > 0:
62+
print(f"Found {num_errors} errors", file=sys.stderr)
63+
sys.exit(1)
64+
elif num_files == 0:
65+
print("No input files found!", file=sys.stderr)
66+
sys.exit(2)
67+
else:
68+
print(f"Checked {num_files} files, all OK")
69+
70+
71+
if __name__ == "__main__":
72+
script_dir = os.path.dirname(__file__)
73+
project_root = os.getcwd()
74+
dirs = ["cext", "src"]
75+
paths = [os.path.join(project_root, d) for d in dirs]
76+
lint(paths)

ci/scripts/check_license.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# SPDX-FileCopyrightText: Copyright (c) <2025> NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
ignore_files=("src/cuda/tile/VERSION")
7+
outputs=$(reuse lint --lines | grep -v ${ignore_files[@]/#/-e })
8+
if [ -n "$outputs" ]; then
9+
echo -e "License check failed\n${outputs}"
10+
exit 1
11+
fi

0 commit comments

Comments
 (0)