-
Notifications
You must be signed in to change notification settings - Fork 276
CI: Check versioned release notes exist before releasing #1907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cpcloud
wants to merge
5
commits into
NVIDIA:main
Choose a base branch
from
cpcloud:issue-1326
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+313
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0c97f40
ci: check versioned release notes exist before releasing
cpcloud 8b9c911
fix: checkout release tag ref in check-release-notes job
cpcloud 90fcc08
style: fix ruff lint and format issues
cpcloud b5cb9b2
ci: move release-notes checker to ci/tools and drop component=all
cpcloud b9696c8
ci: tighten release-notes tag parser
cpcloud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| """Check that versioned release-notes files exist before releasing. | ||
|
|
||
| Usage: | ||
| python check_release_notes.py --git-tag <tag> --component <component> | ||
|
|
||
| Exit codes: | ||
| 0 — release notes present and non-empty (or .post version, skipped) | ||
| 1 — release notes missing or empty | ||
| 2 — invalid arguments (including unparsable tag, or component/tag-prefix mismatch) | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import os | ||
| import re | ||
| import sys | ||
|
|
||
| COMPONENT_TO_PACKAGE: dict[str, str] = { | ||
| "cuda-core": "cuda_core", | ||
| "cuda-bindings": "cuda_bindings", | ||
| "cuda-pathfinder": "cuda_pathfinder", | ||
| "cuda-python": "cuda_python", | ||
| } | ||
|
|
||
| # Version characters are restricted to digit-prefixed word chars and dots, so | ||
| # malformed inputs like "v../evil" or "v1/2/3" cannot flow into the notes path. | ||
| _VERSION_PATTERN = r"\d[\w.]*" | ||
|
|
||
| # Each component has exactly one valid tag-prefix form. cuda-bindings and | ||
| # cuda-python share the bare "v<version>" namespace (setuptools-scm lookup). | ||
| COMPONENT_TO_TAG_RE: dict[str, re.Pattern[str]] = { | ||
| "cuda-bindings": re.compile(rf"^v(?P<version>{_VERSION_PATTERN})$"), | ||
| "cuda-python": re.compile(rf"^v(?P<version>{_VERSION_PATTERN})$"), | ||
| "cuda-core": re.compile(rf"^cuda-core-v(?P<version>{_VERSION_PATTERN})$"), | ||
| "cuda-pathfinder": re.compile(rf"^cuda-pathfinder-v(?P<version>{_VERSION_PATTERN})$"), | ||
| } | ||
|
|
||
|
|
||
| def parse_version_from_tag(git_tag: str, component: str) -> str | None: | ||
| """Extract the version string from a tag, given the target component. | ||
|
|
||
| Returns None if the tag does not match the component's expected prefix | ||
| or contains characters outside the allowed version set. | ||
| """ | ||
| pattern = COMPONENT_TO_TAG_RE.get(component) | ||
| if pattern is None: | ||
| return None | ||
| m = pattern.match(git_tag) | ||
| return m.group("version") if m else None | ||
|
|
||
|
|
||
| def is_post_release(version: str) -> bool: | ||
| return ".post" in version | ||
|
|
||
|
|
||
| def notes_path(package: str, version: str) -> str: | ||
| return os.path.join(package, "docs", "source", "release", f"{version}-notes.rst") | ||
|
|
||
|
|
||
| def check_release_notes(git_tag: str, component: str, repo_root: str = ".") -> list[tuple[str, str]]: | ||
| """Return a list of (path, reason) for missing or empty release notes. | ||
|
|
||
| Returns an empty list when notes are present and non-empty, or when the | ||
| tag is a .post release (no new notes required). | ||
| """ | ||
| if component not in COMPONENT_TO_PACKAGE: | ||
| return [("<component>", f"unknown component '{component}'")] | ||
|
|
||
| version = parse_version_from_tag(git_tag, component) | ||
| if version is None: | ||
| return [("<tag>", f"cannot parse version from tag '{git_tag}' for component '{component}'")] | ||
|
|
||
| if is_post_release(version): | ||
| return [] | ||
|
|
||
| path = notes_path(COMPONENT_TO_PACKAGE[component], version) | ||
| full = os.path.join(repo_root, path) | ||
| if not os.path.isfile(full): | ||
| return [(path, "missing")] | ||
| if os.path.getsize(full) == 0: | ||
| return [(path, "empty")] | ||
| return [] | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__) | ||
| parser.add_argument("--git-tag", required=True) | ||
| parser.add_argument("--component", required=True, choices=list(COMPONENT_TO_PACKAGE)) | ||
| parser.add_argument("--repo-root", default=".") | ||
| args = parser.parse_args(argv) | ||
|
|
||
| version = parse_version_from_tag(args.git_tag, args.component) | ||
| if version is None: | ||
| print( | ||
| f"ERROR: tag {args.git_tag!r} does not match the expected format for component {args.component!r}.", | ||
| file=sys.stderr, | ||
| ) | ||
| return 2 | ||
|
|
||
| if is_post_release(version): | ||
| print(f"Post-release tag ({args.git_tag}), skipping release-notes check.") | ||
| return 0 | ||
|
|
||
| problems = check_release_notes(args.git_tag, args.component, args.repo_root) | ||
| if not problems: | ||
| print(f"Release notes present for tag {args.git_tag}, component {args.component}.") | ||
| return 0 | ||
|
|
||
| print(f"ERROR: missing or empty release notes for tag {args.git_tag}:", file=sys.stderr) | ||
| for path, reason in problems: | ||
| print(f" - {path} ({reason})", file=sys.stderr) | ||
| print("Add versioned release notes before releasing.", file=sys.stderr) | ||
| return 1 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) |
|
leofang marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import sys | ||
|
|
||
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..")) | ||
| from check_release_notes import ( | ||
| check_release_notes, | ||
| is_post_release, | ||
| main, | ||
| parse_version_from_tag, | ||
| ) | ||
|
|
||
|
|
||
| class TestParseVersionFromTag: | ||
| def test_plain_tag_bindings(self): | ||
| assert parse_version_from_tag("v13.1.0", "cuda-bindings") == "13.1.0" | ||
|
|
||
| def test_plain_tag_python(self): | ||
| assert parse_version_from_tag("v13.1.0", "cuda-python") == "13.1.0" | ||
|
|
||
| def test_component_prefix_core(self): | ||
| assert parse_version_from_tag("cuda-core-v0.7.0", "cuda-core") == "0.7.0" | ||
|
|
||
| def test_component_prefix_pathfinder(self): | ||
| assert parse_version_from_tag("cuda-pathfinder-v1.5.2", "cuda-pathfinder") == "1.5.2" | ||
|
|
||
| def test_post_release(self): | ||
| assert parse_version_from_tag("v12.6.2.post1", "cuda-bindings") == "12.6.2.post1" | ||
|
|
||
| def test_invalid_tag(self): | ||
| assert parse_version_from_tag("not-a-tag", "cuda-core") is None | ||
|
|
||
| def test_no_v_prefix(self): | ||
| assert parse_version_from_tag("13.1.0", "cuda-bindings") is None | ||
|
|
||
| def test_component_prefix_mismatch(self): | ||
| # cuda-core-v* must not be accepted for component=cuda-pathfinder | ||
| assert parse_version_from_tag("cuda-core-v0.7.0", "cuda-pathfinder") is None | ||
|
|
||
| def test_bare_v_rejected_for_core(self): | ||
| # bare v* belongs to cuda-bindings/cuda-python, not cuda-core | ||
| assert parse_version_from_tag("v0.7.0", "cuda-core") is None | ||
|
|
||
| def test_unknown_component(self): | ||
| assert parse_version_from_tag("v13.1.0", "bogus") is None | ||
|
|
||
| def test_path_traversal_rejected(self): | ||
| assert parse_version_from_tag("v1.0.0/../evil", "cuda-bindings") is None | ||
|
|
||
| def test_path_separator_rejected(self): | ||
| assert parse_version_from_tag("v1/2/3", "cuda-bindings") is None | ||
|
|
||
| def test_leading_dot_rejected(self): | ||
| assert parse_version_from_tag("v.1.0", "cuda-bindings") is None | ||
|
|
||
| def test_whitespace_rejected(self): | ||
| assert parse_version_from_tag("v1.0.0 ", "cuda-bindings") is None | ||
|
|
||
| def test_trailing_suffix_rejected(self): | ||
| # \w permits alphanumerics + underscore only; hyphens and shell meta-chars are out | ||
| assert parse_version_from_tag("v1.0.0-extra", "cuda-bindings") is None | ||
|
|
||
|
|
||
| class TestIsPostRelease: | ||
| def test_normal(self): | ||
| assert not is_post_release("13.1.0") | ||
|
|
||
| def test_post(self): | ||
| assert is_post_release("12.6.2.post1") | ||
|
|
||
| def test_post_no_number(self): | ||
| assert is_post_release("1.0.0.post") | ||
|
|
||
|
|
||
| class TestCheckReleaseNotes: | ||
| def _make_notes(self, tmp_path, pkg, version, content="Release notes."): | ||
| d = tmp_path / pkg / "docs" / "source" / "release" | ||
| d.mkdir(parents=True, exist_ok=True) | ||
| f = d / f"{version}-notes.rst" | ||
| f.write_text(content) | ||
| return f | ||
|
|
||
| def test_present_and_nonempty(self, tmp_path): | ||
| self._make_notes(tmp_path, "cuda_core", "0.7.0") | ||
| problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path)) | ||
| assert problems == [] | ||
|
|
||
| def test_missing(self, tmp_path): | ||
| problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path)) | ||
| assert len(problems) == 1 | ||
| assert problems[0][1] == "missing" | ||
|
|
||
| def test_empty(self, tmp_path): | ||
| self._make_notes(tmp_path, "cuda_core", "0.7.0", content="") | ||
| problems = check_release_notes("cuda-core-v0.7.0", "cuda-core", str(tmp_path)) | ||
| assert len(problems) == 1 | ||
| assert problems[0][1] == "empty" | ||
|
|
||
| def test_post_release_skipped(self, tmp_path): | ||
| problems = check_release_notes("v12.6.2.post1", "cuda-bindings", str(tmp_path)) | ||
| assert problems == [] | ||
|
|
||
| def test_invalid_tag(self, tmp_path): | ||
| problems = check_release_notes("not-a-tag", "cuda-core", str(tmp_path)) | ||
| assert len(problems) == 1 | ||
| assert "cannot parse" in problems[0][1] | ||
|
|
||
| def test_component_prefix_mismatch(self, tmp_path): | ||
| # Pass a cuda-core tag with component=cuda-pathfinder; must be rejected. | ||
| problems = check_release_notes("cuda-core-v0.7.0", "cuda-pathfinder", str(tmp_path)) | ||
| assert len(problems) == 1 | ||
| assert "cannot parse" in problems[0][1] | ||
|
|
||
| def test_unknown_component(self, tmp_path): | ||
| problems = check_release_notes("v13.1.0", "bogus", str(tmp_path)) | ||
| assert len(problems) == 1 | ||
| assert "unknown component" in problems[0][1] | ||
|
|
||
| def test_plain_v_tag(self, tmp_path): | ||
| self._make_notes(tmp_path, "cuda_python", "13.1.0") | ||
| problems = check_release_notes("v13.1.0", "cuda-python", str(tmp_path)) | ||
| assert problems == [] | ||
|
|
||
|
|
||
| class TestMain: | ||
| def test_success(self, tmp_path): | ||
| d = tmp_path / "cuda_core" / "docs" / "source" / "release" | ||
| d.mkdir(parents=True) | ||
| (d / "0.7.0-notes.rst").write_text("Notes here.") | ||
| rc = main(["--git-tag", "cuda-core-v0.7.0", "--component", "cuda-core", "--repo-root", str(tmp_path)]) | ||
| assert rc == 0 | ||
|
|
||
| def test_failure(self, tmp_path): | ||
| rc = main(["--git-tag", "cuda-core-v0.7.0", "--component", "cuda-core", "--repo-root", str(tmp_path)]) | ||
| assert rc == 1 | ||
|
|
||
| def test_post_skip(self, tmp_path): | ||
| rc = main(["--git-tag", "v12.6.2.post1", "--component", "cuda-bindings", "--repo-root", str(tmp_path)]) | ||
| assert rc == 0 | ||
|
|
||
| def test_unparsable_tag_returns_2(self, tmp_path): | ||
| rc = main(["--git-tag", "not-a-tag", "--component", "cuda-core", "--repo-root", str(tmp_path)]) | ||
| assert rc == 2 | ||
|
|
||
| def test_path_traversal_returns_2(self, tmp_path): | ||
| rc = main(["--git-tag", "v1.0.0/../evil", "--component", "cuda-bindings", "--repo-root", str(tmp_path)]) | ||
| assert rc == 2 | ||
|
|
||
| def test_component_prefix_mismatch_returns_2(self, tmp_path): | ||
| rc = main( | ||
| [ | ||
| "--git-tag", | ||
| "cuda-core-v0.7.0", | ||
| "--component", | ||
| "cuda-pathfinder", | ||
| "--repo-root", | ||
| str(tmp_path), | ||
| ] | ||
| ) | ||
| assert rc == 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.