Skip to content
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

Add license #3

Merged
merged 2 commits into from
Oct 9, 2024
Merged
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
21 changes: 21 additions & 0 deletions .github/workflows/lint.yml
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
18 changes: 18 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
The MIT-Zero License

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
63 changes: 63 additions & 0 deletions scripts/spdx-header-check.sh
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}))