Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Refactoring SPDX check #551

Merged
merged 1 commit into from
May 9, 2023
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
8 changes: 8 additions & 0 deletions .github/actions/spdx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ that files modified in a Pull Request has an SPDX license identifier.
It shall be possible to use this action from other repositories by referencing:

`- uses: eclipse/kuksa.val/.github/actions/spdx@master`

If you accept multiple licenses it can be specified like:

```
- name: Set license
run: |
echo "licenses=Apache-2.0, MIT" >> $GITHUB_ENV
```
5 changes: 2 additions & 3 deletions .github/actions/spdx/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ inputs:
default: ''
licenses:
description: >
A space-separated list of all accepted licenses. For example:

Apache-2.0 MIT
A comma-separated list of all accepted licenses. For example:
Apache-2.0,MIT
required: true
default: ''
runs:
Expand Down
34 changes: 19 additions & 15 deletions .github/actions/spdx/verify-spdx-headers
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,15 @@ class Index:
}

def __init__(self):
"""
This can be relaxed as needed
"""
self.__languages = {
'python': Language('#+', shebang=True),
'python': Language('#+.*', shebang=True),
'ruby': Language('#+', shebang=True),
'c': Language('//+', ('/\\*', '\\*/')),
'c++': Language('//+', ('/\\*', '\\*/')),
'rust': Language('//+', '//!', ('/\\*', '\\*/')),
'c': Language('//+', '.*', ('/\\*', '\\*/')),
'c++': Language('//+', '.*', ('/\\*', '\\*/')),
'rust': Language('//+', '.*', '//!', ('/\\*', '\\*/')),
'protobuf': Language('//+', '//!', ('/\\*', '\\*/')),
}

Expand Down Expand Up @@ -113,31 +116,32 @@ class Index:

if __name__ == '__main__':
import sys
import json

# Validate the arguments
licenses = os.getenv('INPUT_LICENSES')
if licenses is None:
licenses = sys.argv[1:]
else:
licenses = json.loads(licenses)
license_arg = os.getenv('licenses')
if license_arg is None:
license_arg = sys.argv[1:]

licenses = [x.strip() for x in license_arg.split(',')]
print(f"{len(licenses)} will be accepted!")
for license in licenses:
if not SLUG.match(license):
print("Invalid license '%s'!" % license)
raise SystemExit(1)
print(f"Allowed license: {license}")

rv = 0
index = Index()
failed = False
for (path, license) in index.scan():
if license not in licenses:
failed = True
if license == None:
failed = True
print(f"NO SPDX {path}")
else:
print(f"{license:16} {path}")
rv = 1
print(f"WRONG LICENSE: {license:16} {path}")
else:
print(f"OK: {license:16} {path}")
if failed:
raise Exception("Check the output, some files have not the right licenses!")

raise SystemExit(rv)
raise SystemExit(0)
erikbosch marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 5 additions & 1 deletion .github/workflows/check_license.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ jobs:
- name: Get changed files
run: |
echo "files=$(git diff --name-only ${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }} | tr '\n' ',')" >> $GITHUB_ENV

- name: Set license
run: |
echo "licenses=Apache-2.0" >> $GITHUB_ENV

- uses: ./.github/actions/spdx
with:
files: "${{ env.files }}"
licenses: Apache-2.0
licenses: "${{ env.licenses }}"