Skip to content

Commit 99d98c4

Browse files
committed
Config tweak
1 parent 7e709f1 commit 99d98c4

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

.github/workflows/githubci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ on: [pull_request, push, repository_dispatch]
55
jobs:
66
spdx:
77
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/setup-python@v2
10+
with:
11+
python-version: "3.x"
812
- uses: actions/checkout@v2
913
with:
1014
repository: adafruit/ci-arduino

SPDX.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import os
2+
3+
# add user bin to path!
4+
BUILD_DIR = ''
5+
# add user bin to path!
6+
try:
7+
# If we're on actions
8+
BUILD_DIR = os.environ["GITHUB_WORKSPACE"]
9+
except KeyError:
10+
try:
11+
# If we're on travis
12+
BUILD_DIR = os.environ["TRAVIS_BUILD_DIR"]
13+
except KeyError:
14+
# If we're running on local machine
15+
BUILD_DIR = os.path.abspath(".")
16+
pass
17+
18+
files = []
19+
missing_file = []
20+
21+
fail = False
22+
23+
for r, d, f in os.walk(BUILD_DIR):
24+
for file in f:
25+
if file.split('.')[-1] in ("py", "cpp", "ino", "h"):
26+
files.append(os.path.join(r, file))
27+
28+
for file in files:
29+
with open(file, "r") as F:
30+
lines = []
31+
for line in F.readlines():
32+
if line[0] != "#" and line[:2] != "//":
33+
break
34+
lines.append(line)
35+
status = {"copyright": False,
36+
"license": False,
37+
"licensefile": False}
38+
for line in lines:
39+
if "SPDX-FileCopyrightText:" in line:
40+
status["copyright"] = True
41+
if "SPDX-License-Identifier:" in line:
42+
license_name = line.split("SPDX-License-Identifier: ")[1][:-1]
43+
status["license"] = True
44+
if os.path.isfile(BUILD_DIR+f"/LICENSES/{license_name}.txt"):
45+
status["licensefile"] = True
46+
elif license_name not in missing_file:
47+
missing_file.append(f"LICENSES/{license_name}.txt")
48+
49+
if not all(status.values()):
50+
fail = True
51+
print(f"{file} is missing SPDX")
52+
continue
53+
if not status["copyright"]:
54+
fail = True
55+
print(f"{file}: SPDX-FileCopyrightText line is missing")
56+
if not status["license"]:
57+
fail = True
58+
print(f"{file}: SPDX-License-Identifier line is missing")
59+
if not status["licensefile"] and status["license"]:
60+
fail = True
61+
print(f"{file}: {license_name}.txt is missing from LICENSES/")
62+
63+
if fail:
64+
if missing_file:
65+
print("Missing files:", missing_file)
66+
exit(-1)
67+
exit(0)
68+
69+
70+
"""
71+
print(
72+
f"{len(missing)} Missing SPDX\n{len(has)} Have SPDX ({100*len(has)/len(files):.2f}%)"
73+
)
74+
with open('../missing.txt', 'w') as F:
75+
for i in missing:
76+
F.write(i+'\n')
77+
78+
with open('../has.txt', 'w') as F:
79+
for i in has:
80+
F.write(i+'\n')
81+
82+
for file in missing:
83+
os.system(f"grep -irHn 'author' {file}")
84+
"""

0 commit comments

Comments
 (0)