diff --git a/README.md b/README.md index 25710171..8ff44241 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,5 @@ version, or a main-branch dispatch with `publish=true`, publishes after the Publishing uses GitHub OIDC and the repository's `release.yml` trusted publisher. No registry token is stored in GitHub. + +SDK patch releases can update packaging and publishing independently. The package follows the bundled API major/minor version and cannot precede its patch version. diff --git a/scripts/release-version.py b/scripts/release-version.py index a2b46c5f..c6b91ea1 100644 --- a/scripts/release-version.py +++ b/scripts/release-version.py @@ -15,8 +15,11 @@ raise SystemExit("release requires main or a tag equal to the package version") subprocess.run(["git", "fetch", "--quiet", "origin", "main"], check=True) subprocess.run(["git", "merge-base", "--is-ancestor", "HEAD", "origin/main"], check=True) -if json.loads(Path("openapi.public.json").read_text())["info"]["version"] != version: - raise SystemExit("package and bundled public API versions differ") +api = json.loads(Path("openapi.public.json").read_text())["info"]["version"] +package_parts = tuple(map(int, version.split("."))) +api_parts = tuple(map(int, api.split("."))) +if package_parts[:2] != api_parts[:2] or package_parts[2] < api_parts[2]: + raise SystemExit("SDK must follow the public API major/minor and not precede its patch") with Path(os.environ["GITHUB_OUTPUT"]).open("a") as output: output.write(f"version={version}\n") print(f"Release version: {version}") diff --git a/tests/test_release_version.py b/tests/test_release_version.py index 86034486..3721509e 100644 --- a/tests/test_release_version.py +++ b/tests/test_release_version.py @@ -48,6 +48,31 @@ def git(*arguments: str) -> None: self.assertEqual(output.read_text(), "version=1.2.3\n") else: self.assertFalse(output.exists()) + for api, admitted in ( + ("1.2.2", True), + ("1.2.4", False), + ("1.1.3", False), + ("2.2.3", False), + ): + with self.subTest(api=api): + (root / "openapi.public.json").write_text( + json.dumps({"info": {"version": api}}) + ) + output = root / "api-output" + output.unlink(missing_ok=True) + result = subprocess.run( + [sys.executable, str(SCRIPT)], + cwd=root, + env={ + **os.environ, + "GITHUB_REF": "refs/heads/main", + "GITHUB_OUTPUT": str(output), + }, + capture_output=True, + text=True, + ) + self.assertEqual(result.returncode == 0, admitted, result.stderr) + git("checkout", "--", "openapi.public.json") git("checkout", "--quiet", "-b", "feature") (root / "change").write_text("unmerged") git("add", ".")