Skip to content

Commit a981aeb

Browse files
authored
Merge pull request #2067 from adafruit/spdx-test
Testing CI check
2 parents d4184d3 + f73cd50 commit a981aeb

File tree

10 files changed

+119
-0
lines changed

10 files changed

+119
-0
lines changed

.github/workflows/githubci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@ name: Arduino Library CI
33
on: [pull_request, push, repository_dispatch]
44

55
jobs:
6+
spdx:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/setup-python@v2
10+
with:
11+
python-version: "3.x"
12+
- name: Checkout Current Repo
13+
uses: actions/checkout@v2
14+
15+
- name: check SPDX licensing
16+
run: python ./SPDX.py
17+
618
arduino:
719
strategy:
820
fail-fast: false
@@ -40,6 +52,7 @@ jobs:
4052
- name: test platforms
4153
run: python3 ci/build_platform.py ${{ matrix.arduino-platform }}
4254

55+
4356
- name: Upload build artifacts
4457
uses: actions/upload-artifact@v2
4558
with:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
// SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
15
#define SECRET_SSID "ssid"
26
#define SECRET_PASS "password"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
// SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
15
#define SECRET_SSID "ssid"
26
#define SECRET_PASS "pass"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
// SPDX-FileCopyrightText: 2019 Limor Fried for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
15
#define SECRET_SSID "ssid"
26
#define SECRET_PASS "password"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
# SPDX-FileCopyrightText: 2018 Jerry Needell for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15
print('Hello, World!')
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15
"""Example of assigning a variable."""
26
user_name = input("What is your name? ")
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
# SPDX-FileCopyrightText: 2019 Anne Barela for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
15
__version__ = "1.1"

SPDX.py

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

0 commit comments

Comments
 (0)