-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GH workflow for spdx header check
Signed-off-by: Michael Engel <[email protected]>
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Lint | ||
|
||
on: | ||
pull_request: | ||
branches: [main] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
common: | ||
name: Common | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: "true" | ||
|
||
- name: Check SPDX headers | ||
run: | | ||
./scripts/spdx-header-check.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#!/usr/bin/bash -e | ||
# | ||
# Copyright Contributors to the Eclipse BlueChi project | ||
# | ||
# SPDX-License-Identifier: MIT-0 | ||
|
||
# | ||
# Checked files regex | ||
# | ||
CHECKED_FILES=".*\(\.c\|\.h\|\.go\|\.py\|\.rs\|\.sh\|\.xml\)" | ||
|
||
# | ||
# License which is OK when found in the project | ||
# | ||
LICENSE="MIT-0" | ||
|
||
# | ||
# List of files to check using the project license | ||
# | ||
FILES="$(find -type f \ | ||
-regex ${CHECKED_FILES})" | ||
|
||
# | ||
# Iterate over files within a path and check the allowed licenses | ||
# | ||
# Parameters: | ||
# files - a list of files to check the license | ||
# licences - a list of approved licenses | ||
# | ||
# Result: | ||
# cl_result - 0 if all files contain valid license, otherwise 1 | ||
# | ||
check_licenses() { | ||
local files=$1 | ||
local licenses=$2 | ||
cl_result=0 | ||
|
||
for f in ${files} ; do | ||
# scan for license only within the 1st 5 lines of each file | ||
license_found=$(head -n 5 ${f} | grep -Po '.*SPDX-License-Identifier\: \K\S+' || echo "-1") | ||
if [ "${license_found}" == "-1" ]; then | ||
cl_result=1 | ||
echo "File '${f}' does not contain SPDX header!" | ||
else | ||
valid_license=1 | ||
for l in ${licenses} ; do | ||
if [ "${license_found}" == "$l" ] ; then | ||
valid_license=0 | ||
fi | ||
done | ||
if [ "${valid_license}" == "1" ] ; then | ||
cl_result=1 | ||
echo "File '${f}' contains unapproved license '${license_found}'" | ||
fi | ||
fi | ||
done | ||
} | ||
|
||
|
||
check_licenses "${FILES}" "${LICENSE}" | ||
result=$cl_result | ||
|
||
exit $((${result})) |