Skip to content

Commit b34498c

Browse files
authored
toolshed: fix copyright-year check to work outside staged-file workflows (#3352)
ci: harden fetch_ctk and add redist-base-url Verify the redistrib manifest and archives before use, key the cache on the full manifest hash, and add a redist-base-url input for alternate servers. Harden install_windows_deps against WSL bash on PATH.
1 parent 4010017 commit b34498c

25 files changed

Lines changed: 243 additions & 28 deletions

File tree

‎.github/actions/install_unix_deps/action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

‎.github/copy-pr-bot.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

44
# Configuration file for `copy-pr-bot` GitHub App

‎.github/workflows/ci-nightly.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ jobs:
6565

6666
- name: Run CI tools unit tests
6767
run: |
68-
python -m pip install pytest pyyaml==6.0.3
68+
python -m pip install pytest pyyaml==6.0.3 pathspec==0.12.1
6969
# Standalone CI tool tests; skip repo-root conftest.py (imports cuda.pathfinder).
7070
python -m pytest -v --noconftest ci/tools/tests
7171

‎.github/workflows/pre-commit.yml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,17 @@ jobs:
5858

5959
# PR workflows run from the merge revision; check out that same revision
6060
# so their helper scripts and configuration stay in sync.
61+
# check_spdx.py runs `git log -1 -- <file>` to find the year each file last
62+
# changed (copyright-year enforcement), so it needs the full commit history.
63+
# In a shallow clone every file looks like it was introduced by the tip
64+
# commit, so each would be judged against the tip commit's year.
65+
# blob:none keeps all commits and trees but skips historical file contents,
66+
# which a path-limited `git log` does not read.
6167
- name: Checkout repository
6268
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6369
with:
64-
fetch-depth: 1
70+
fetch-depth: 0
71+
filter: blob:none
6572
persist-credentials: false
6673

6774
- name: Set up Python

‎ci/tools/guess_latest.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
#
44
# SPDX-License-Identifier: Apache-2.0
55

‎ci/tools/tests/test_check_spdx.py‎

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
"""Tests for the copyright-year rule in toolshed/check_spdx.py.
5+
6+
The rule must give the same answer however the hook is invoked (``git commit``,
7+
``pre-commit run --all-files``, CI), so each test builds a throwaway git repository
8+
with controlled commit dates and runs the script against it. Years are derived from
9+
the current year so the tests do not expire.
10+
11+
python -m pytest ci/tools/tests/test_check_spdx.py -v --noconftest
12+
"""
13+
14+
from __future__ import annotations
15+
16+
import datetime
17+
import os
18+
import shutil
19+
import subprocess
20+
import sys
21+
from pathlib import Path
22+
23+
import pytest
24+
25+
pytest.importorskip("pathspec", reason="check_spdx.py requires pathspec")
26+
27+
REPO = Path(__file__).resolve().parents[3]
28+
CHECKER = REPO / "toolshed" / "check_spdx.py"
29+
LICENSE = REPO / "LICENSE"
30+
31+
CURRENT_YEAR = datetime.datetime.now(tz=datetime.UTC).year
32+
SAMPLE = "toolshed/sample.py"
33+
34+
CONTENT = (
35+
"# SPDX-FileCopyrightText: Copyright (c) {years} NVIDIA CORPORATION & AFFILIATES. All rights reserved.\n"
36+
"# SPDX-License-Identifier: Apache-2.0\n"
37+
"\n"
38+
"pass\n"
39+
)
40+
41+
42+
def git(repo, *args, year=None):
43+
env = dict(os.environ)
44+
env.update(
45+
GIT_AUTHOR_NAME="Test",
46+
GIT_AUTHOR_EMAIL="[email protected]",
47+
GIT_COMMITTER_NAME="Test",
48+
GIT_COMMITTER_EMAIL="[email protected]",
49+
)
50+
if year is not None:
51+
date = f"{year}-06-15T12:00:00+0000"
52+
env.update(GIT_AUTHOR_DATE=date, GIT_COMMITTER_DATE=date)
53+
subprocess.run( # noqa: S603
54+
["git", "-c", "commit.gpgsign=false", *args], # noqa: S607
55+
cwd=repo,
56+
env=env,
57+
check=True,
58+
capture_output=True,
59+
)
60+
61+
62+
def commit(repo, relpath, years, *, year):
63+
path = repo / relpath
64+
path.parent.mkdir(parents=True, exist_ok=True)
65+
path.write_text(CONTENT.format(years=years), encoding="utf-8")
66+
git(repo, "add", relpath)
67+
git(repo, "commit", "-m", f"add {relpath}", year=year)
68+
return path
69+
70+
71+
def run_checker(repo, *args):
72+
# The script reads LICENSE and runs git relative to the working directory,
73+
# as pre-commit does from the repository root.
74+
return subprocess.run( # noqa: S603
75+
[sys.executable, str(CHECKER), *args, SAMPLE],
76+
cwd=repo,
77+
capture_output=True,
78+
text=True,
79+
check=False,
80+
)
81+
82+
83+
@pytest.fixture
84+
def repo(tmp_path):
85+
git(tmp_path, "init")
86+
shutil.copy(LICENSE, tmp_path / "LICENSE")
87+
git(tmp_path, "add", "LICENSE")
88+
git(tmp_path, "commit", "-m", "init", year=CURRENT_YEAR - 5)
89+
return tmp_path
90+
91+
92+
@pytest.mark.agent_authored(model="claude-sonnet-5.5")
93+
@pytest.mark.parametrize(
94+
("commit_age", "copyright_age", "passes"),
95+
[
96+
# Not modified this year, so last year's copyright is still correct.
97+
pytest.param(1, 1, True, id="untouched-since-last-year"),
98+
# The bug in #2273: committed this year, nothing staged, stale copyright.
99+
pytest.param(0, 1, False, id="committed-this-year-stale-copyright"),
100+
],
101+
)
102+
def test_committed_file_is_checked_against_its_last_commit_year(repo, commit_age, copyright_age, passes):
103+
commit(repo, SAMPLE, str(CURRENT_YEAR - copyright_age), year=CURRENT_YEAR - commit_age)
104+
105+
result = run_checker(repo)
106+
107+
assert (result.returncode == 0) is passes, result.stdout + result.stderr
108+
assert ("OUTDATED" in result.stdout) is (not passes)
109+
110+
111+
@pytest.mark.agent_authored(model="claude-sonnet-5.5")
112+
def test_staged_edit_requires_current_year_and_fix_writes_it(repo):
113+
# The `git commit` path: the edited file is staged when the hook runs.
114+
path = commit(repo, SAMPLE, str(CURRENT_YEAR - 3), year=CURRENT_YEAR - 2)
115+
path.write_text(path.read_text(encoding="utf-8") + "# edited\n", encoding="utf-8")
116+
git(repo, "add", SAMPLE)
117+
118+
check = run_checker(repo)
119+
assert check.returncode == 1, check.stdout + check.stderr
120+
assert f"(expected '{CURRENT_YEAR}')" in check.stdout
121+
122+
# --fix reports that it changed something, as the hook always has.
123+
fix = run_checker(repo, "--fix")
124+
assert fix.returncode == 1, fix.stdout + fix.stderr
125+
assert f"Copyright (c) {CURRENT_YEAR - 3}-{CURRENT_YEAR} " in path.read_text(encoding="utf-8")
126+
127+
# The rewrite is stable: a second run accepts the file.
128+
assert run_checker(repo).returncode == 0
129+
130+
131+
@pytest.mark.agent_authored(model="claude-sonnet-5.5")
132+
def test_fix_of_clean_stale_file_survives_being_committed(repo):
133+
# Stale relative to an old commit, with nothing staged (for example a manual
134+
# `pre-commit run --all-files`).
135+
path = commit(repo, SAMPLE, str(CURRENT_YEAR - 3), year=CURRENT_YEAR - 2)
136+
137+
fix = run_checker(repo, "--fix")
138+
assert fix.returncode == 1, fix.stdout + fix.stderr
139+
# Not the older last-commit year: committing the fix is a change made this year.
140+
assert f"Copyright (c) {CURRENT_YEAR - 3}-{CURRENT_YEAR} " in path.read_text(encoding="utf-8")
141+
142+
git(repo, "add", SAMPLE)
143+
git(repo, "commit", "-m", "fix copyright", year=CURRENT_YEAR)
144+
145+
# The fix must not demand another fix once it is part of this year's history.
146+
assert run_checker(repo).returncode == 0
147+
148+
149+
@pytest.mark.parametrize(
150+
("date", "passes"),
151+
[
152+
pytest.param(f"{CURRENT_YEAR - 1}-12-31T23:30:00-0800", False, id="utc-year-after-recorded-year"),
153+
pytest.param(f"{CURRENT_YEAR}-01-01T00:30:00+1400", True, id="utc-year-before-recorded-year"),
154+
],
155+
)
156+
@pytest.mark.agent_authored(model="gpt-6")
157+
def test_committed_file_uses_utc_year_across_new_year(repo, monkeypatch, date, passes):
158+
monkeypatch.setenv("GIT_AUTHOR_DATE", date)
159+
monkeypatch.setenv("GIT_COMMITTER_DATE", date)
160+
commit(repo, SAMPLE, str(CURRENT_YEAR - 1), year=None)
161+
162+
result = run_checker(repo)
163+
164+
assert (result.returncode == 0) is passes, result.stdout + result.stderr
165+
assert ("OUTDATED" in result.stdout) is (not passes)
166+
167+
168+
@pytest.mark.agent_authored(model="gpt-6")
169+
def test_signed_last_commit_with_show_signature_enabled(repo):
170+
ssh_keygen = shutil.which("ssh-keygen")
171+
if ssh_keygen is None:
172+
pytest.skip("ssh-keygen is required to create a signed commit")
173+
174+
signing_key = repo / "signing_key"
175+
subprocess.run( # noqa: S603
176+
[ssh_keygen, "-q", "-t", "ed25519", "-N", "", "-f", str(signing_key)],
177+
check=True,
178+
capture_output=True,
179+
)
180+
allowed_signers = repo / "allowed_signers"
181+
allowed_signers.write_text(
182+
"[email protected] " + signing_key.with_suffix(".pub").read_text(encoding="utf-8"), encoding="utf-8"
183+
)
184+
git(repo, "config", "gpg.format", "ssh")
185+
git(repo, "config", "user.signingkey", str(signing_key))
186+
git(repo, "config", "gpg.ssh.allowedSignersFile", str(allowed_signers))
187+
git(repo, "config", "log.showSignature", "true")
188+
path = commit(repo, SAMPLE, str(CURRENT_YEAR), year=CURRENT_YEAR)
189+
path.write_text(path.read_text(encoding="utf-8") + "# signed edit\n", encoding="utf-8")
190+
git(repo, "add", SAMPLE)
191+
git(repo, "-c", "commit.gpgsign=true", "commit", "-m", "signed edit", year=CURRENT_YEAR)
192+
193+
result = run_checker(repo)
194+
195+
assert result.returncode == 0, result.stdout + result.stderr

‎cuda_core/DESCRIPTION.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
.. SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
.. SPDX-License-Identifier: Apache-2.0
33
44
*******************************************************

‎cuda_core/cuda/core/_memory/_graph_memory_resource.pxd‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# SPDX-License-Identifier: Apache-2.0
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
#
33
# SPDX-License-Identifier: Apache-2.0

‎cuda_core/docs/source/_templates/autosummary/cyclass.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.. SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
1+
.. SPDX-FileCopyrightText: Copyright (c) 2024-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
22
.. SPDX-License-Identifier: Apache-2.0
33
44
{{ fullname | escape | underline}}

0 commit comments

Comments
 (0)