-
Notifications
You must be signed in to change notification settings - Fork 18
Derive release versions from tags #64
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ build/ | |
| dist/ | ||
| wheels/ | ||
| *.egg-info | ||
| server.json | ||
|
|
||
| # Virtual environments | ||
| .venv | ||
|
|
||
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
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,60 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import re | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| VERSION_RE = re.compile(r"^\d+\.\d+\.\d+$") | ||
| PACKAGE_IDENTIFIER = "mcp-server-appwrite" | ||
|
|
||
|
|
||
| def render_server_metadata( | ||
| version: str, | ||
| *, | ||
| template_path: Path = Path("server.template.json"), | ||
| output_path: Path = Path("server.json"), | ||
| ) -> None: | ||
| if not VERSION_RE.fullmatch(version): | ||
| raise ValueError(f"version must be MAJOR.MINOR.PATCH, got {version!r}") | ||
|
|
||
| data: dict[str, Any] = json.loads(template_path.read_text()) | ||
| data["version"] = version | ||
|
|
||
| for package in data.get("packages", []): | ||
| if package.get("identifier") == PACKAGE_IDENTIFIER: | ||
| package["version"] = version | ||
| break | ||
| else: | ||
| raise ValueError(f"{PACKAGE_IDENTIFIER!r} package entry not found") | ||
|
|
||
| output_path.write_text(json.dumps(data, indent=2) + "\n") | ||
|
|
||
|
|
||
| def main() -> None: | ||
| parser = argparse.ArgumentParser(description="Render MCP Registry metadata.") | ||
| parser.add_argument("version", help="Release version without leading v.") | ||
| parser.add_argument( | ||
| "--template", | ||
| type=Path, | ||
| default=Path("server.template.json"), | ||
| help="Path to the server metadata template.", | ||
| ) | ||
| parser.add_argument( | ||
| "--output", | ||
| type=Path, | ||
| default=Path("server.json"), | ||
| help="Path to write rendered metadata.", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| render_server_metadata( | ||
| args.version, | ||
| template_path=args.template, | ||
| output_path=args.output, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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,87 @@ | ||
| import importlib.util | ||
| import json | ||
| import tempfile | ||
| import unittest | ||
| from pathlib import Path | ||
| from unittest.mock import patch | ||
|
|
||
| from mcp_server_appwrite import constants | ||
|
|
||
|
|
||
| def _load_render_module(): | ||
| script_path = Path(__file__).parents[2] / "scripts" / "render_server_json.py" | ||
| spec = importlib.util.spec_from_file_location("render_server_json", script_path) | ||
| if spec is None or spec.loader is None: | ||
| raise RuntimeError("Unable to load render_server_json.py") | ||
| module = importlib.util.module_from_spec(spec) | ||
| spec.loader.exec_module(module) | ||
| return module | ||
|
|
||
|
|
||
| class ServerVersionTests(unittest.TestCase): | ||
| def test_resolve_server_version_uses_package_metadata(self): | ||
| with patch.object( | ||
| constants.importlib_metadata, "version", return_value="1.2.3" | ||
| ): | ||
| self.assertEqual(constants._resolve_server_version(), "1.2.3") | ||
|
|
||
| def test_resolve_server_version_falls_back_when_metadata_missing(self): | ||
| with patch.object( | ||
| constants.importlib_metadata, | ||
| "version", | ||
| side_effect=constants.importlib_metadata.PackageNotFoundError, | ||
| ): | ||
| self.assertEqual(constants._resolve_server_version(), "0.0.0+unknown") | ||
|
|
||
|
|
||
| class RenderServerMetadataTests(unittest.TestCase): | ||
| def test_render_server_metadata_sets_all_release_versions(self): | ||
| module = _load_render_module() | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| tmp_path = Path(tmpdir) | ||
| template_path = tmp_path / "server.template.json" | ||
| output_path = tmp_path / "server.json" | ||
| template_path.write_text( | ||
| json.dumps( | ||
| { | ||
| "version": "__VERSION__", | ||
| "packages": [ | ||
| { | ||
| "identifier": "mcp-server-appwrite", | ||
| "version": "__VERSION__", | ||
| } | ||
| ], | ||
| } | ||
| ) | ||
| ) | ||
|
|
||
| module.render_server_metadata( | ||
| "1.2.3", | ||
| template_path=template_path, | ||
| output_path=output_path, | ||
| ) | ||
|
|
||
| rendered = json.loads(output_path.read_text()) | ||
| self.assertEqual(rendered["version"], "1.2.3") | ||
| self.assertEqual(rendered["packages"][0]["version"], "1.2.3") | ||
|
|
||
| def test_render_server_metadata_rejects_non_release_version(self): | ||
| module = _load_render_module() | ||
|
|
||
| with tempfile.TemporaryDirectory() as tmpdir: | ||
| tmp_path = Path(tmpdir) | ||
| template_path = tmp_path / "server.template.json" | ||
| output_path = tmp_path / "server.json" | ||
| template_path.write_text('{"version": "__VERSION__", "packages": []}') | ||
|
|
||
| with self.assertRaises(ValueError): | ||
| module.render_server_metadata( | ||
| "1.2.3.dev1", | ||
| template_path=template_path, | ||
| output_path=output_path, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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.