Skip to content

[PD1-242] Add automated license compliance check #5

[PD1-242] Add automated license compliance check

[PD1-242] Add automated license compliance check #5

Workflow file for this run

name: License Check
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
license-check:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- name: Install licensecheck
run: pip install licensecheck
# - name: Set up uv
# uses: astral-sh/setup-uv@5a7eac68fb9809dea845d802897dc5c723910fa3 # v7.1.3
# - name: Set up Python 3.14
# uses: actions/setup-python@v5
# with:
# python-version: 3.14
# - name: Install Poetry
# uses: snok/install-poetry@v1
# with:
# virtualenvs-create: true
# virtualenvs-in-project: true
# installer-parallel: true
# - name: Load cached venv
# id: cached-poetry-dependencies
# uses: actions/cache@v4
# with:
# path: .venv
# key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
# - name: Install dependencies
# if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
# run: poetry install --no-interaction --no-root
# - name: Install project
# run: poetry install --no-interaction
- name: Run license check
run: |
echo "Running license check..."
pwd
ls
licensecheck --format json > license-report.json
cat license-report.json
- name: Parse and validate licenses
shell: python
run: |
import json
import sys
# Read the license report
with open('license-report.json', 'r') as f:
report = json.load(f)
# Print header
print("\n" + "="*80)
print("LICENSE REPORT")
print("="*80)
print(f"Project License: {report.get('project_license', 'UNKNOWN')}")
print("="*80)
# Track incompatible licenses
incompatible_packages = []
# Print package licenses
packages = report.get('packages', [])
print(f"\nFound {len(packages)} packages:\n")
for pkg in packages:
name = pkg.get('name', 'UNKNOWN')
version = pkg.get('version', 'UNKNOWN')
license_type = pkg.get('license', 'UNKNOWN')
compat = pkg.get('licenseCompat', True)
compat_str = "✓ COMPATIBLE" if compat else "✗ INCOMPATIBLE"
print(f" {name:30s} {version:15s} {license_type:40s} {compat_str}")
if not compat:
incompatible_packages.append({
'name': name,
'version': version,
'license': license_type
})
# Print summary
print("\n" + "="*80)
print("SUMMARY")
print("="*80)
print(f"Total packages: {len(packages)}")
print(f"Compatible: {len(packages) - len(incompatible_packages)}")
print(f"Incompatible: {len(incompatible_packages)}")
# If there are incompatible packages, fail the build
if incompatible_packages:
print("\n" + "="*80)
print("ERROR: INCOMPATIBLE LICENSES FOUND")
print("="*80)
for pkg in incompatible_packages:
print(f" ✗ {pkg['name']} {pkg['version']}: {pkg['license']}")
print("="*80)
sys.exit(1)
else:
print("\n✓ All licenses are compatible!")
print("="*80)