Skip to content

Commit

Permalink
CI: improving ORT script to log unkown / not pre-approved licenses
Browse files Browse the repository at this point in the history
  • Loading branch information
barshaul committed Feb 11, 2024
1 parent f01901a commit 2c7bd03
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ort.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
paths:
- .github/workflows/ort.yml
- .github/workflows/run-ort-tools/action.yml
- utils/get_licenses_from_ort.py
workflow_dispatch:
inputs:
branch:
Expand Down Expand Up @@ -172,9 +173,11 @@ jobs:
if: ${{ env.FOUND_DIFF == 'true'}}
working-directory: ./utils
run: |
list_result=`python3 get_licenses_from_ort.py`
echo $list_result
{
echo 'LICENSES_LIST<<EOF'
python3 get_licenses_from_ort.py
echo ${list_result}
echo EOF
} >> "$GITHUB_ENV"
Expand Down
41 changes: 29 additions & 12 deletions utils/get_licenses_from_ort.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
from typing import List, Set

"""
This script should be used after all specific langauge folders were scanned by the analyzer of the OSS review tool (ORT).
Expand Down Expand Up @@ -49,13 +50,24 @@ def __init__(self, name: str, ort_results_folder: str) -> None:
self.name = name


class PackageLicense:
def __init__(self, package_name: str, language: str, license: str) -> None:
self.package_name = package_name
self.language = language
self.license = license

def __str__(self):
return f"Package_name: {self.package_name}, Language: {self.language}, License: {self.license}"


ort_results_per_lang = [
OrtResults("Python", "python/ort_results"),
OrtResults("Node", "node/ort_results"),
OrtResults("Rust", "glide-core/ort_results"),
]

licenses_set = set()
all_licenses_set: Set = set()
unkown_licenses: List[PackageLicense] = []

for ort_result in ort_results_per_lang:
with open(ort_result.analyzer_result_file, "r") as ort_results, open(
Expand All @@ -72,25 +84,30 @@ def __init__(self, name: str, ort_results_folder: str) -> None:
try:
for license in package["declared_licenses_processed"].values():
if isinstance(license, list) or isinstance(license, dict):
license = (
license.values() if isinstance(license, dict) else license
final_licenses = (
list(license.values())
if isinstance(license, dict)
else license
)
for inner_license in license:
licenses_set.add(inner_license)
else:
licenses_set.add(license)
final_licenses = [license]
for license in final_licenses:
if license not in APPROVED_LICENSES:
unkown_licenses.append(
PackageLicense(package["id"], ort_result.name, license)
)
all_licenses_set.add(license)
except Exception:
print(
f"Received error for package {package} used by {ort_result.name}\n Found license={license}"
)
raise

print("\n\n#### Found Licenses #####\n")
licenses_set = set(sorted(licenses_set))
for license in licenses_set:
all_licenses_set = set(sorted(all_licenses_set))
for license in all_licenses_set:
print(f"{license}")

print("\n\n#### New / Not Approved Licenses #####\n")
for license in licenses_set:
if license not in APPROVED_LICENSES:
print(f"{license}")
print("\n\n#### Unkown / Not Pre-Approved Licenses #####\n")
for package in unkown_licenses:
print(str(package))

0 comments on commit 2c7bd03

Please sign in to comment.