From 08494a95908b88968e7aa3c260dd4b198b6ff942 Mon Sep 17 00:00:00 2001 From: Kris Hicks Date: Wed, 2 Dec 2026 13:41:25 -0800 Subject: [PATCH] ci(license): require only the SPDX license identifier OpenShell has been donated to the CNCF, but the License Headers check still failed any file without the NVIDIA SPDX-FileCopyrightText line, and license:update wrote that line into every new file. CNCF guidance does not require or recommend per-contributor copyright notices, and asks that existing notices not be changed or removed without the holder's permission: https://github.com/cncf/foundation/blob/main/copyright-notices.md CI now runs the organization's shared spdx-check action, which requires only SPDX-License-Identifier: Apache-2.0 and, given the PR or merge-group base, fails when a file loses a copyright notice its header had there. license:check and license:update require and add only the license line. The style guide, docs template, and agent instructions say not to add or remove copyright lines. Signed-off-by: Kris Hicks --- .agents/skills/update-docs/SKILL.md | 2 +- .github/workflows/branch-checks.yml | 30 ++++++++----- AGENTS.md | 4 ++ STYLEGUIDE.md | 10 ++++- docs/CONTRIBUTING.mdx | 4 +- scripts/update_license_headers.py | 37 +++------------- scripts/update_license_headers_test.py | 60 ++++++++++++++++++++++++++ tasks/license.toml | 4 +- tasks/test.toml | 4 +- 9 files changed, 104 insertions(+), 51 deletions(-) create mode 100644 scripts/update_license_headers_test.py diff --git a/.agents/skills/update-docs/SKILL.md b/.agents/skills/update-docs/SKILL.md index 8ad24d7ccf..62dde17f4f 100644 --- a/.agents/skills/update-docs/SKILL.md +++ b/.agents/skills/update-docs/SKILL.md @@ -103,7 +103,7 @@ Write the smallest update that tells users exactly what changed and what they ne - **No superlatives.** Say what the feature does, not how great it is. - **Code examples use `shell` language** for copyable commands, with no `$` prompt prefix. - **Use `text` fences** for transcripts, logs, or shell sessions that should not be copied verbatim. -- **Include the SPDX header as YAML comments in frontmatter** if creating a new page. +- **Include the SPDX license identifier as a YAML comment in frontmatter** if creating a new page. Do not add an `SPDX-FileCopyrightText` line. - **Match existing Fern frontmatter format** if creating a new page, including `sidebar-title`, `keywords`, and `position` when they are relevant. Use frontmatter `slug` only for folder-discovered pages or absolute URL overrides. - **Use `sidebar-title` for short nav labels**. For explicit navigation entries, keep relative `slug` values in `docs/index.yml` instead of page frontmatter. - **Keep explicit `page:` entries in `docs/index.yml`**. Fern still requires them. If the page defines `sidebar-title`, set `page:` to that value. Otherwise set `page:` to the page frontmatter `title`. diff --git a/.github/workflows/branch-checks.yml b/.github/workflows/branch-checks.yml index 68d91615ec..411572ee33 100644 --- a/.github/workflows/branch-checks.yml +++ b/.github/workflows/branch-checks.yml @@ -201,20 +201,30 @@ jobs: license-headers: name: License Headers runs-on: ubuntu-24.04 - timeout-minutes: 30 - container: - image: ghcr.io/ai-openshell/openshell/ci:82e753ba3ffdfb40c118e7cb416ced7f350381d5@sha256:d816f3b4b2de675928e2ecfd26ec6b937be35fe9986542c87d440bc3de5a29de - credentials: - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} + timeout-minutes: 10 steps: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 + persist-credentials: false - - name: Install tools - run: mise install --locked - + # Keep include and exclude in step with scripts/update_license_headers.py. - name: Check license headers - run: mise run license:check + uses: ai-openshell/workflows/spdx-check@8f4d5a0f393e5c30ad4d09810357a062031c4fc4 + with: + include: >- + *.rs *.proto *.py *.sh *.toml *.yaml *.yml *.rego + *.ts *.tsx *.mts *.cts *.mjs *.css *.in *.service *.tpl + Dockerfile* */Dockerfile* scripts/bin/openshell + scripts/keycloak-realm.json + sdk/conformance/oauth-client-credentials.json + sdk/conformance/oidc-token-bundle.json + exclude: >- + target/* e2e/rust/target/* plans/* architecture/plans/* + .cache/* .venv/* python/openshell/_proto/* + .github/* .agents/* .claude/* :(glob)**/node_modules/** + .gitlab-ci.yml */.gitlab-ci.yml + base: ${{ github.event.merge_group.base_sha || github.event.pull_request.base.sha }} cargo-deny: name: Cargo Deny diff --git a/AGENTS.md b/AGENTS.md index 2387931089..0133dd3de3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -200,6 +200,10 @@ Follow `CONTRIBUTING.md` and `create-github-pr`. Authors without target-reposito Create PRs with `gh pr create`, which enables "Allow edits by maintainers" by default; never pass `--no-maintainer-edit`. Review Readiness fails a ready PR from a personal fork when that setting is off. Fix a PR that lacks it with `gh api -X PATCH repos/OWNER/REPO/pulls/NUMBER -F maintainer_can_modify=true`. +## License Headers + +- Start new source files with only `SPDX-License-Identifier: Apache-2.0`, even when neighboring files also carry an `SPDX-FileCopyrightText` line. Never add a copyright line, and never remove an existing one. + ## Commits - Always use [Conventional Commits](https://www.conventionalcommits.org/) format for commit messages diff --git a/STYLEGUIDE.md b/STYLEGUIDE.md index e7178f4555..107ab084e3 100644 --- a/STYLEGUIDE.md +++ b/STYLEGUIDE.md @@ -2,10 +2,16 @@ ## License Headers -All source files must include SPDX copyright headers. +All source files must include an SPDX license identifier: + +```text +# SPDX-License-Identifier: Apache-2.0 +``` + +Do not add an `SPDX-FileCopyrightText` line to new files, and do not remove one from an existing file. ```bash -# Add/update headers +# Add missing headers mise run license:update # Check headers diff --git a/docs/CONTRIBUTING.mdx b/docs/CONTRIBUTING.mdx index 8f80170d4c..59ea16d927 100644 --- a/docs/CONTRIBUTING.mdx +++ b/docs/CONTRIBUTING.mdx @@ -56,11 +56,10 @@ PRs that touch `docs/**` or `fern/**` are validated by `.github/workflows/branch - Published docs use Fern MDX under `docs/`. - Every page starts with YAML frontmatter. Use `title` and `description` on every page, then add page-level metadata like `sidebar-title`, `keywords`, and `position` when the page needs them. -- Include the SPDX license header as YAML comments inside frontmatter: +- Include the SPDX license identifier as a YAML comment inside frontmatter: ```text --- - # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 title: "Page Title" --- @@ -72,7 +71,6 @@ PRs that touch `docs/**` or `fern/**` are validated by `.github/workflows/branch ```yaml --- -# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: Apache-2.0 title: "Page Title" sidebar-title: "Short Nav Title" diff --git a/scripts/update_license_headers.py b/scripts/update_license_headers.py index 32827d0188..13dd6f2416 100755 --- a/scripts/update_license_headers.py +++ b/scripts/update_license_headers.py @@ -20,7 +20,6 @@ import argparse import os -import re import subprocess import sys from pathlib import Path @@ -29,9 +28,6 @@ # Configuration # --------------------------------------------------------------------------- -COPYRIGHT_TEXT = ( - "Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved." -) LICENSE_ID = "Apache-2.0" # Map file extensions to their line-comment prefix. @@ -102,18 +98,10 @@ def make_header(comment: str) -> str: - """Return the two-line SPDX header for a given comment prefix.""" + """Return the SPDX license header for a given comment prefix.""" if comment == "/*": - return ( - "/*\n" - f" * SPDX-FileCopyrightText: {COPYRIGHT_TEXT}\n" - f" * SPDX-License-Identifier: {LICENSE_ID}\n" - " */\n" - ) - return ( - f"{comment} SPDX-FileCopyrightText: {COPYRIGHT_TEXT}\n" - f"{comment} SPDX-License-Identifier: {LICENSE_ID}\n" - ) + return f"/*\n * SPDX-License-Identifier: {LICENSE_ID}\n */\n" + return f"{comment} SPDX-License-Identifier: {LICENSE_ID}\n" # --------------------------------------------------------------------------- @@ -251,20 +239,11 @@ def discover_files(root: Path) -> list[Path]: # --------------------------------------------------------------------------- SPDX_MARKER = "SPDX-License-Identifier" -SPDX_COPYRIGHT_RE = re.compile( - r"SPDX-FileCopyrightText: Copyright \(c\) \d{4}(?:-\d{4})? " - r"NVIDIA CORPORATION & AFFILIATES\. All rights reserved\." -) def has_header(lines: list[str]) -> bool: - """Check if the complete NVIDIA SPDX header is in the first 10 lines.""" - header_lines = lines[:10] - has_license = any( - f"{SPDX_MARKER}: {LICENSE_ID}" in line for line in header_lines - ) - has_copyright = any(SPDX_COPYRIGHT_RE.search(line) for line in header_lines) - return has_license and has_copyright + """Check if the SPDX license identifier is in the first 10 lines.""" + return any(f"{SPDX_MARKER}: {LICENSE_ID}" in line for line in lines[:10]) def find_insertion_point(lines: list[str], path: Path) -> int: @@ -335,11 +314,7 @@ def process_file(path: Path, root: Path, *, check: bool, verbose: bool) -> bool: if check: print(f" MISSING: {rel} ({sidecar.name})") return False - sidecar.write_text( - f"SPDX-FileCopyrightText: {COPYRIGHT_TEXT}\n" - f"SPDX-License-Identifier: {LICENSE_ID}\n", - encoding="utf-8", - ) + sidecar.write_text(f"{SPDX_MARKER}: {LICENSE_ID}\n", encoding="utf-8") if verbose: print(f" added: {rel} ({sidecar.name})") return True diff --git a/scripts/update_license_headers_test.py b/scripts/update_license_headers_test.py new file mode 100644 index 0000000000..e04a706219 --- /dev/null +++ b/scripts/update_license_headers_test.py @@ -0,0 +1,60 @@ +# SPDX-License-Identifier: Apache-2.0 + +"""Tests for scripts/update_license_headers.py.""" + +from __future__ import annotations + +import importlib.util +import sys +from pathlib import Path + +_SPEC = importlib.util.spec_from_file_location( + "update_license_headers", Path(__file__).with_name("update_license_headers.py") +) +assert _SPEC is not None and _SPEC.loader is not None +headers = importlib.util.module_from_spec(_SPEC) +sys.modules[_SPEC.name] = headers +_SPEC.loader.exec_module(headers) + +NVIDIA_COPYRIGHT = ( + "# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & " + "AFFILIATES. All rights reserved." +) + + +def test_license_identifier_alone_is_compliant() -> None: + assert headers.has_header(["# SPDX-License-Identifier: Apache-2.0", "x = 1"]) + + +def test_existing_copyright_header_stays_compliant() -> None: + assert headers.has_header( + [NVIDIA_COPYRIGHT, "# SPDX-License-Identifier: Apache-2.0"] + ) + + +def test_missing_license_identifier_is_not_compliant() -> None: + assert not headers.has_header([NVIDIA_COPYRIGHT, "x = 1"]) + + +def test_inserted_header_has_no_copyright() -> None: + result = headers.insert_header("x = 1\n", "#", Path("a.py")) + assert result == "# SPDX-License-Identifier: Apache-2.0\n\nx = 1\n" + + +def test_inserted_block_comment_header_has_no_copyright() -> None: + result = headers.insert_header("a {}\n", "/*", Path("a.css")) + assert result == "/*\n * SPDX-License-Identifier: Apache-2.0\n */\n\na {}\n" + + +def test_written_sidecar_has_no_copyright(tmp_path: Path) -> None: + target = tmp_path / "data.json" + target.write_text("{}\n", encoding="utf-8") + headers.SIDECAR_LICENSE_FILES.add("data.json") + try: + assert headers.process_file(target, tmp_path, check=False, verbose=False) + finally: + headers.SIDECAR_LICENSE_FILES.discard("data.json") + sidecar = tmp_path / "data.json.license" + assert ( + sidecar.read_text(encoding="utf-8") == "SPDX-License-Identifier: Apache-2.0\n" + ) diff --git a/tasks/license.toml b/tasks/license.toml index 09bd88c059..ac1a500397 100644 --- a/tasks/license.toml +++ b/tasks/license.toml @@ -4,11 +4,11 @@ # License header check and update tasks ["license:check"] -description = "Check that all source files have SPDX license headers" +description = "Check that all source files have SPDX license identifiers" run = "uv run python scripts/update_license_headers.py --check" hide = true ["license:update"] -description = "Add or update SPDX license headers on all source files" +description = "Add SPDX license identifiers to source files that lack one" run = "uv run python scripts/update_license_headers.py" hide = true diff --git a/tasks/test.toml b/tasks/test.toml index e215efb411..33c0ff5d43 100644 --- a/tasks/test.toml +++ b/tasks/test.toml @@ -186,8 +186,8 @@ run_windows = "echo Skipping test:postgres-runner: the Unix PostgreSQL test runn hide = true ["test:python-scripts"] -description = "Test the release, RPM, and E2E gateway config tooling" -run = "uv run --no-project --with pytest --with pyyaml pytest -o \"python_files=*_test.py\" tasks/scripts/release_formula_test.py tasks/scripts/release_tooling_test.py deploy/rpm/ e2e/configs/gateway/" +description = "Test the release, RPM, E2E gateway config, and license header tooling" +run = "uv run --no-project --with pytest --with pyyaml pytest -o \"python_files=*_test.py\" tasks/scripts/release_formula_test.py tasks/scripts/release_tooling_test.py deploy/rpm/ e2e/configs/gateway/ scripts/update_license_headers_test.py" hide = true ["test:python"]