Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SMITHY_PYTHON ?= ../smithy-python
# Clients per gradle build in `make clients`; lower it if the build runs out of heap.
BATCH_SIZE ?= 25

.PHONY: docs docs-serve docs-clean docs-install docs-lock venv gen clients fragments publish-codegen aio-check meta-package-check static-analysis test-unit test-functional test-integration \
.PHONY: docs docs-serve docs-clean docs-install docs-lock venv gen clients fragments alignment-fragments what-will-release wwr wwr-json publish-codegen aio-check meta-package-check static-analysis test-unit test-functional test-integration \
check-imports check-conventions check-api check-dependencies check-packaging check-import-stability verify-venv api-snapshot \
canonical-imports dunder-all source-order dynamic-imports banned-imports docstrings declared-deps import-cycles \
dep-specifiers package-metadata package-metadata-fix version-consistency export-names exception-hierarchy secret-repr import-hygiene \
Expand All @@ -32,6 +32,7 @@ INTEGRATION_SKIP := clients/aws-sdk-qbusiness

static-analysis:
$(MAKE) meta-package-check
$(MAKE) wwr
uv run --no-project --python $(PYTHON_VERSION) python scripts/project-checks/project_checks.py \
$(RUFF_VERSION) $(PYRIGHT_VERSION) $(PYTHON_VERSION) $(PROJECTS)
$(MAKE) aio-check
Expand Down Expand Up @@ -93,6 +94,26 @@ clients:
fragments:
uv run --no-project --python $(PYTHON_VERSION) python codegen/gen_fragments.py

what-will-release: ## Catches a repo that cannot release, and shows what a release would publish and why.
uv run --no-project --python $(PYTHON_VERSION) python scripts/release/plan.py $(WWR_ARGS)

wwr: what-will-release ## Short alias for what-will-release.

wwr-json: ## Gives release tooling the release plan as JSON on stdout, with no table or make echo to strip.
@uv run --no-project --python $(PYTHON_VERSION) python scripts/release/plan.py --json -

# Lets a lockstep minor release when clients have no change of their own, since the
# planner rejects a lockstep release in which a client has no fragment.
alignment-fragments: ## Writes the alignment fragment that lets clients without changes join a lockstep release.
@set -e; \
minor=$$(uv run --no-project --python $(PYTHON_VERSION) python scripts/release/plan.py --next-minor); \
for p in clients/*; do \
[ $$(basename $$p) = aws-sdk-python ] && continue; \
ls $$p/.changes/next-release/*.json >/dev/null 2>&1 && continue; \
python3 scripts/changelog/new-entry.py -t alignment -p $$(basename $$p) \
-d "Aligned with the $$minor release of the AWS SDK clients."; \
done

########################## Granular targets below ##########################

# Publishes the smithy-python codegen jars to the local Maven cache so `gen`
Expand Down
88 changes: 76 additions & 12 deletions codegen/gen_fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@
"""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.
Only for a smithy-python pointer move, after `make clients`. The text comes from
CODEGEN_SYNC_CHANGELOG.md in the repo root. A client whose smithy dependencies moved
a major or minor since the merge-base with origin/develop gets a `feature` fragment
(minor bump), any other client an `enhancement` (patch). Diffing against develop
means committing the regenerated files first does not hide a move.
"""

import json
import re
import subprocess
import sys
import time
import tomllib
from pathlib import Path
from typing import Any

from gen_client import load_services

Expand All @@ -20,16 +25,23 @@
CLIENTS = REPO / "clients"
POINTER = CODEGEN_DIR / "smithy-python.toml"
SYNC_CHANGELOG = REPO / "CODEGEN_SYNC_CHANGELOG.md"
DEVELOP = "origin/develop"
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
_SMITHY_REQUIREMENT = re.compile(
r"^\s*(?P<name>smithy[-_][A-Za-z0-9_.-]*)\s*(?:\[[^\]]*\])?\s*"
r"(?:~=|==|>=)\s*(?P<major>\d+)\.(?P<minor>\d+)",
re.IGNORECASE,
)


def main() -> None:
previous, commit = _pointer_commits()
description = _description(previous, commit)
base = _base_commit()
for name in _generated_clients():
_write_fragment(name, commit, description)
_write_fragment(name, commit, _fragment_type(name, base), description)


def _pointer_commits() -> tuple[str, str]:
Expand Down Expand Up @@ -69,17 +81,69 @@ def _generated_clients() -> list[str]:
return [f"aws-sdk-{service.slug}" for service in load_services()]


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"
def _base_commit() -> str:
result = subprocess.run(
["git", "merge-base", "HEAD", DEVELOP],
cwd=REPO,
capture_output=True,
text=True,
)
if result.returncode != 0:
sys.exit(f"cannot diff client dependencies: no merge-base with {DEVELOP}")
return result.stdout.strip()


def _fragment_type(name: str, base: str) -> str:
head = _pyproject_at(name, base)
# A client absent from the base has no baseline to have moved from.
if head is None:
return "enhancement"
after = _read_pyproject(CLIENTS / name / "pyproject.toml")
return "feature" if _smithy_series(head) != _smithy_series(after) else "enhancement"


def _pyproject_at(name: str, base: str) -> dict[str, Any] | None:
result = subprocess.run(
["git", "show", f"{base}:clients/{name}/pyproject.toml"],
cwd=REPO,
capture_output=True,
text=True,
)
return tomllib.loads(result.stdout) if result.returncode == 0 else None


def _read_pyproject(path: Path) -> dict[str, Any]:
with path.open("rb") as f:
return tomllib.load(f)


def _smithy_series(pyproject: dict[str, Any]) -> dict[str, tuple[int, int]]:
"""Maps each smithy dependency to the highest major.minor it requires."""
project = pyproject.get("project", {})
requirements = list(project.get("dependencies", []))
for extra in project.get("optional-dependencies", {}).values():
requirements.extend(extra)

series: dict[str, tuple[int, int]] = {}
for requirement in requirements:
match = _SMITHY_REQUIREMENT.match(requirement)
if match:
name = match["name"].lower().replace("_", "-")
found = (int(match["major"]), int(match["minor"]))
series[name] = max(series.get(name, found), found)
return series


def _write_fragment(name: str, commit: str, kind: str, description: str) -> None:
changes = CLIENTS / name / ".changes" / "next-release"
# Keyed by target commit: a rerun for the same pin overwrites, a later sync adds.
fragment = changes / f"{name}-{kind}-codegen-sync-{commit}.json"
fragment.parent.mkdir(parents=True, exist_ok=True)
entry = {"type": "enhancement", "description": description}
# A rerun can change the type, which would otherwise leave both files behind.
for stale in changes.glob(f"{name}-*-codegen-sync-{commit}.json"):
if stale != fragment:
stale.unlink()
entry = {"type": kind, "description": description}
fragment.write_text(json.dumps(entry, indent=2) + "\n")
print(f"wrote {fragment}")

Expand Down
1 change: 1 addition & 0 deletions scripts/changelog/new-entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def main():
"breaking",
"dependency",
"api-change",
"alignment",
"summary",
),
required=True,
Expand Down
1 change: 1 addition & 0 deletions scripts/changelog/new-release.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"enhancement": 3,
"bugfix": 4,
"dependency": 5,
"alignment": 6,
}
CHANGE_TYPES = tuple(CHANGE_TYPES_ORDER.keys())

Expand Down
5 changes: 4 additions & 1 deletion scripts/changelog/templates/PACKAGE
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

{{ changes.summary }}
{%- endif %}
{%- for type_name in ['api-change', 'breaking', 'feature', 'enhancement', 'bugfix', 'dependency'] %}
{%- for type_name in ['api-change', 'breaking', 'feature', 'enhancement', 'bugfix', 'dependency', 'alignment'] %}
{%- for change in changes.changes if change.type == type_name %}
{%- if loop.first %}
{%- if type_name == 'api-change' %}
Expand All @@ -26,6 +26,9 @@
{%- elif type_name == 'dependency' %}

### Dependencies
{%- elif type_name == 'alignment' %}

### Alignment
{%- endif %}
{%- endif %}
* {{ change.description }}
Expand Down
Loading