Skip to content
Open
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
17 changes: 17 additions & 0 deletions .github/workflows/update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: update

on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: license-audit
run: python scripts/audit_license.py data/repos.json
6 changes: 6 additions & 0 deletions data/repos.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"full_name": "example/repo",
"license": {"spdx_id": "MIT"}
}
]
47 changes: 47 additions & 0 deletions scripts/audit_license.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import json
import sys
import argparse
from pathlib import Path

ALLOWED_LICENSES = {"MIT", "Apache-2.0", "BSD-3-Clause", "ISC", "MPL-2.0"}

def audit(file_path: Path) -> bool:
with file_path.open() as f:
repos = json.load(f)

offending = []
for repo in repos:
license_info = repo.get("license")
spdx = None
if isinstance(license_info, dict):
spdx = license_info.get("spdx_id")
if spdx not in ALLOWED_LICENSES:
name = repo.get("full_name") or repo.get("name")
offending.append((name, spdx))

if offending:
print("Offending repositories with non-compliant licenses:")
for name, spdx in offending:
print(f"{name}: {spdx}")
return False
else:
print("All repositories have approved licenses.")
return True

def main():
parser = argparse.ArgumentParser(description="Audit repository licenses")
parser.add_argument("path", nargs="?", default="data/repos.json",
help="Path to JSON file with repository metadata")
args = parser.parse_args()

file_path = Path(args.path)
if not file_path.is_file():
print(f"File not found: {file_path}")
sys.exit(1)

ok = audit(file_path)
if not ok:
sys.exit(1)

if __name__ == "__main__":
main()