Repository navigation
Changelog entries for client generation #121
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
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/env python3 | ||
| """Write a codegen sync changelog fragment for every generated client. | ||
|
|
||
| Usage: python codegen/gen_fragments.py | ||
| Only for a smithy-python pointer move; the text comes from CODEGEN_SYNC_CHANGELOG.md | ||
| in the repo root. | ||
| """ | ||
|
|
||
| import json | ||
| import re | ||
| import sys | ||
| import time | ||
| import tomllib | ||
| from pathlib import Path | ||
|
|
||
| CODEGEN_DIR = Path(__file__).resolve().parent | ||
| REPO = CODEGEN_DIR.parent | ||
| CLIENTS = REPO / "clients" | ||
| MODELS = CODEGEN_DIR / "aws-models" | ||
| POINTER = CODEGEN_DIR / "smithy-python.toml" | ||
| SYNC_CHANGELOG = REPO / "CODEGEN_SYNC_CHANGELOG.md" | ||
| SMITHY_PYTHON_COMMITS = "https://github.com/smithy-lang/smithy-python/commits" | ||
| # An older file is assumed to be left over from a previous sync. | ||
| SYNC_CHANGELOG_MAX_AGE_SECONDS = 8 * 60 * 60 | ||
|
|
||
|
|
||
| def main() -> None: | ||
| previous, commit = _pointer_commits() | ||
| description = _description(previous, commit) | ||
| for name in _generated_clients(): | ||
| _write_fragment(name, commit, description) | ||
|
|
||
|
|
||
| def _pointer_commits() -> tuple[str, str]: | ||
| with POINTER.open("rb") as f: | ||
| pointer = tomllib.load(f) | ||
| commits = [] | ||
| for key in ("previous_commit", "commit"): | ||
| value = pointer.get(key) | ||
| if not isinstance(value, str) or not re.fullmatch(r"[0-9a-f]{40}", value): | ||
| sys.exit( | ||
| f"{POINTER}: {key} must be a full 40-character hash, got {value!r}" | ||
| ) | ||
| commits.append(value) | ||
| previous, commit = commits | ||
| if previous == commit: | ||
| sys.exit(f"{POINTER}: previous_commit and commit must differ") | ||
| return previous, commit | ||
|
|
||
|
|
||
| def _description(previous: str, commit: str) -> str: | ||
| changes = f"{SMITHY_PYTHON_COMMITS}/{previous}..{commit}" | ||
| reminder = f"write the changelog text for this codegen sync of {changes}" | ||
| if not SYNC_CHANGELOG.exists(): | ||
| SYNC_CHANGELOG.touch() | ||
| sys.exit(f"created empty {SYNC_CHANGELOG}; {reminder}") | ||
| age = time.time() - SYNC_CHANGELOG.stat().st_mtime | ||
| if age > SYNC_CHANGELOG_MAX_AGE_SECONDS: | ||
| sys.exit(f"{SYNC_CHANGELOG} is {age / 3600:.1f} hours old; {reminder}") | ||
| text = SYNC_CHANGELOG.read_text().strip() | ||
| if not text: | ||
| sys.exit(f"{SYNC_CHANGELOG} is empty; {reminder}") | ||
| link = f"[smithy-python {previous[:7]}..{commit[:7]}]({changes})" | ||
| return f"Codegen sync for {link}: {text}" | ||
|
|
||
|
|
||
| def _generated_clients() -> list[str]: | ||
| return [f"aws-sdk-{model.stem}" for model in sorted(MODELS.glob("*.json"))] | ||
|
|
||
|
|
||
| def _write_fragment(name: str, commit: str, description: str) -> None: | ||
| # Keyed by target commit: a rerun for the same pin overwrites, a later sync adds. | ||
| fragment = ( | ||
| CLIENTS | ||
| / name | ||
| / ".changes" | ||
| / "next-release" | ||
| / f"{name}-enhancement-codegen-sync-{commit}.json" | ||
| ) | ||
| fragment.parent.mkdir(parents=True, exist_ok=True) | ||
| entry = {"type": "enhancement", "description": description} | ||
| fragment.write_text(json.dumps(entry, indent=2) + "\n") | ||
| print(f"wrote {fragment}") | ||
|
|
||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # The smithy-python commit `make clients` builds codegen from. May be any commit | ||
| # reachable from the colocated smithy-python checkout, including a local one. | ||
| commit = "b8eceadb0573bd0c757def9a2b26fe7bf938b239" | ||
| # The commit this pointer moved from; with `commit` it bounds the range linked | ||
| # in codegen sync changelog entries. | ||
| previous_commit = "505312562bf78d45265145ae3ae9f874c00464d1" |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could
fragmentsdepend onclients? That keeps normalmake clientsunchanged, but makes sure fragments only get written after generation succeedsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is a manual invocation so the developer could have run
make clientsand paused.A small typo or error in fragments should not require rerunning client generation, which is time-consuming.