microharness 0.2.0__tar.gz → 0.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (131) hide show
  1. {microharness-0.2.0 → microharness-0.2.2}/.github/pull_request_template.md +2 -2
  2. microharness-0.2.2/.github/scripts/release.py +302 -0
  3. microharness-0.2.2/.github/workflows/publish.yml +185 -0
  4. microharness-0.2.2/.github/workflows/release.yml +164 -0
  5. {microharness-0.2.0 → microharness-0.2.2}/AGENTS.md +7 -5
  6. {microharness-0.2.0 → microharness-0.2.2}/CHANGELOG.md +13 -0
  7. {microharness-0.2.0 → microharness-0.2.2}/PKG-INFO +3 -1
  8. {microharness-0.2.0 → microharness-0.2.2}/README.md +2 -0
  9. {microharness-0.2.0 → microharness-0.2.2}/benchmarks/experiments.py +142 -0
  10. {microharness-0.2.0 → microharness-0.2.2}/core/__init__.py +1 -1
  11. microharness-0.2.2/docs/benchmarks.md +124 -0
  12. {microharness-0.2.0 → microharness-0.2.2}/docs/changelog.md +13 -0
  13. {microharness-0.2.0 → microharness-0.2.2}/docs/index.md +1 -1
  14. {microharness-0.2.0 → microharness-0.2.2}/docs/presets.md +19 -2
  15. microharness-0.2.2/examples/presets/hy4-skilled/agent.md +24 -0
  16. microharness-0.2.2/examples/presets/hy4-skilled/skills/adversarial-tests/SKILL.md +23 -0
  17. microharness-0.2.2/examples/presets/hy4-skilled/skills/self-review/SKILL.md +26 -0
  18. microharness-0.2.2/examples/presets/hy4-skilled/skills/spec-contract/SKILL.md +23 -0
  19. microharness-0.2.2/examples/presets/hy4-solo/agent.md +14 -0
  20. microharness-0.2.2/examples/presets/main-explore/agent.md +23 -0
  21. microharness-0.2.2/examples/presets/main-explore/subagents/explore.md +18 -0
  22. microharness-0.2.2/examples/presets/main-reviewer/agent.md +22 -0
  23. microharness-0.2.2/examples/presets/main-reviewer/subagents/reviewer.md +19 -0
  24. microharness-0.2.2/examples/presets/plan-explore-workers/agent.md +24 -0
  25. microharness-0.2.2/examples/presets/plan-explore-workers/subagents/explore.md +18 -0
  26. microharness-0.2.2/examples/presets/plan-explore-workers/subagents/worker.md +22 -0
  27. microharness-0.2.2/examples/presets/single-agent/agent.md +20 -0
  28. {microharness-0.2.0 → microharness-0.2.2}/main.py +84 -2
  29. {microharness-0.2.0 → microharness-0.2.2}/microharness/__init__.py +1 -1
  30. {microharness-0.2.0 → microharness-0.2.2}/pyproject.toml +1 -1
  31. {microharness-0.2.0 → microharness-0.2.2}/tests/test_experiments.py +191 -0
  32. {microharness-0.2.0 → microharness-0.2.2}/tests/test_package.py +18 -7
  33. {microharness-0.2.0 → microharness-0.2.2}/tests/test_presets.py +22 -0
  34. microharness-0.2.2/tests/test_release.py +204 -0
  35. {microharness-0.2.0 → microharness-0.2.2}/uv.lock +6 -6
  36. microharness-0.2.0/.github/workflows/publish.yml +0 -102
  37. microharness-0.2.0/docs/benchmarks.md +0 -71
  38. {microharness-0.2.0 → microharness-0.2.2}/.env.example +0 -0
  39. {microharness-0.2.0 → microharness-0.2.2}/.github/workflows/ci.yml +0 -0
  40. {microharness-0.2.0 → microharness-0.2.2}/.github/workflows/codeql.yml +0 -0
  41. {microharness-0.2.0 → microharness-0.2.2}/.github/workflows/docs.yml +0 -0
  42. {microharness-0.2.0 → microharness-0.2.2}/.gitignore +0 -0
  43. {microharness-0.2.0 → microharness-0.2.2}/.pre-commit-config.yaml +0 -0
  44. {microharness-0.2.0 → microharness-0.2.2}/LICENSE +0 -0
  45. {microharness-0.2.0 → microharness-0.2.2}/PR_DESCRIPTION.md +0 -0
  46. {microharness-0.2.0 → microharness-0.2.2}/SPEC.md +0 -0
  47. {microharness-0.2.0 → microharness-0.2.2}/benchmarks/__init__.py +0 -0
  48. {microharness-0.2.0 → microharness-0.2.2}/benchmarks/harbor.py +0 -0
  49. {microharness-0.2.0 → microharness-0.2.2}/benchmarks/mini_swe.py +0 -0
  50. {microharness-0.2.0 → microharness-0.2.2}/benchmarks/pier_agent.py +0 -0
  51. {microharness-0.2.0 → microharness-0.2.2}/benchmarks/runner.py +0 -0
  52. {microharness-0.2.0 → microharness-0.2.2}/core/auth.py +0 -0
  53. {microharness-0.2.0 → microharness-0.2.2}/core/auth_sigv4.py +0 -0
  54. {microharness-0.2.0 → microharness-0.2.2}/core/auth_store.py +0 -0
  55. {microharness-0.2.0 → microharness-0.2.2}/core/checkpoints.py +0 -0
  56. {microharness-0.2.0 → microharness-0.2.2}/core/code_mode.py +0 -0
  57. {microharness-0.2.0 → microharness-0.2.2}/core/commands.py +0 -0
  58. {microharness-0.2.0 → microharness-0.2.2}/core/config.py +0 -0
  59. {microharness-0.2.0 → microharness-0.2.2}/core/defaults.json +0 -0
  60. {microharness-0.2.0 → microharness-0.2.2}/core/defaults.py +0 -0
  61. {microharness-0.2.0 → microharness-0.2.2}/core/discovery.py +0 -0
  62. {microharness-0.2.0 → microharness-0.2.2}/core/editing.py +0 -0
  63. {microharness-0.2.0 → microharness-0.2.2}/core/environment.py +0 -0
  64. {microharness-0.2.0 → microharness-0.2.2}/core/evaluator.py +0 -0
  65. {microharness-0.2.0 → microharness-0.2.2}/core/harness.py +0 -0
  66. {microharness-0.2.0 → microharness-0.2.2}/core/hooks.py +0 -0
  67. {microharness-0.2.0 → microharness-0.2.2}/core/interactive.py +0 -0
  68. {microharness-0.2.0 → microharness-0.2.2}/core/loop.py +0 -0
  69. {microharness-0.2.0 → microharness-0.2.2}/core/memory.py +0 -0
  70. {microharness-0.2.0 → microharness-0.2.2}/core/model.py +0 -0
  71. {microharness-0.2.0 → microharness-0.2.2}/core/presets.py +0 -0
  72. {microharness-0.2.0 → microharness-0.2.2}/core/prompts.py +0 -0
  73. {microharness-0.2.0 → microharness-0.2.2}/core/protocols.py +0 -0
  74. {microharness-0.2.0 → microharness-0.2.2}/core/providers.json +0 -0
  75. {microharness-0.2.0 → microharness-0.2.2}/core/providers.py +0 -0
  76. {microharness-0.2.0 → microharness-0.2.2}/core/session.py +0 -0
  77. {microharness-0.2.0 → microharness-0.2.2}/core/skills.py +0 -0
  78. {microharness-0.2.0 → microharness-0.2.2}/core/subagents.py +0 -0
  79. {microharness-0.2.0 → microharness-0.2.2}/core/tools.py +0 -0
  80. {microharness-0.2.0 → microharness-0.2.2}/core/tracer.py +0 -0
  81. {microharness-0.2.0 → microharness-0.2.2}/core/tui.py +0 -0
  82. {microharness-0.2.0 → microharness-0.2.2}/core/tui_session.py +0 -0
  83. {microharness-0.2.0 → microharness-0.2.2}/core/types.py +0 -0
  84. {microharness-0.2.0 → microharness-0.2.2}/core/usage.py +0 -0
  85. {microharness-0.2.0 → microharness-0.2.2}/docs/architecture.md +0 -0
  86. {microharness-0.2.0 → microharness-0.2.2}/docs/configuration.md +0 -0
  87. {microharness-0.2.0 → microharness-0.2.2}/docs/getting-started.md +0 -0
  88. {microharness-0.2.0 → microharness-0.2.2}/docs/interactive-tui.md +0 -0
  89. {microharness-0.2.0 → microharness-0.2.2}/docs/mcp.md +0 -0
  90. {microharness-0.2.0 → microharness-0.2.2}/docs/pluggability.md +0 -0
  91. {microharness-0.2.0 → microharness-0.2.2}/docs/subagents.md +0 -0
  92. {microharness-0.2.0 → microharness-0.2.2}/microharness/__main__.py +0 -0
  93. {microharness-0.2.0 → microharness-0.2.2}/mkdocs.yml +0 -0
  94. {microharness-0.2.0 → microharness-0.2.2}/plugins/__init__.py +0 -0
  95. {microharness-0.2.0 → microharness-0.2.2}/plugins/mcp.py +0 -0
  96. {microharness-0.2.0 → microharness-0.2.2}/tests/__init__.py +0 -0
  97. {microharness-0.2.0 → microharness-0.2.2}/tests/test_auth_aws.py +0 -0
  98. {microharness-0.2.0 → microharness-0.2.2}/tests/test_auth_plugins.py +0 -0
  99. {microharness-0.2.0 → microharness-0.2.2}/tests/test_auth_schemes.py +0 -0
  100. {microharness-0.2.0 → microharness-0.2.2}/tests/test_auth_sigv4.py +0 -0
  101. {microharness-0.2.0 → microharness-0.2.2}/tests/test_auth_store.py +0 -0
  102. {microharness-0.2.0 → microharness-0.2.2}/tests/test_benchmarks.py +0 -0
  103. {microharness-0.2.0 → microharness-0.2.2}/tests/test_checkpoints.py +0 -0
  104. {microharness-0.2.0 → microharness-0.2.2}/tests/test_code_mode.py +0 -0
  105. {microharness-0.2.0 → microharness-0.2.2}/tests/test_commands.py +0 -0
  106. {microharness-0.2.0 → microharness-0.2.2}/tests/test_config.py +0 -0
  107. {microharness-0.2.0 → microharness-0.2.2}/tests/test_discovery.py +0 -0
  108. {microharness-0.2.0 → microharness-0.2.2}/tests/test_doom_loop.py +0 -0
  109. {microharness-0.2.0 → microharness-0.2.2}/tests/test_environment.py +0 -0
  110. {microharness-0.2.0 → microharness-0.2.2}/tests/test_evaluator.py +0 -0
  111. {microharness-0.2.0 → microharness-0.2.2}/tests/test_harbor.py +0 -0
  112. {microharness-0.2.0 → microharness-0.2.2}/tests/test_harness.py +0 -0
  113. {microharness-0.2.0 → microharness-0.2.2}/tests/test_hooks.py +0 -0
  114. {microharness-0.2.0 → microharness-0.2.2}/tests/test_interactive.py +0 -0
  115. {microharness-0.2.0 → microharness-0.2.2}/tests/test_mcp.py +0 -0
  116. {microharness-0.2.0 → microharness-0.2.2}/tests/test_memory.py +0 -0
  117. {microharness-0.2.0 → microharness-0.2.2}/tests/test_model.py +0 -0
  118. {microharness-0.2.0 → microharness-0.2.2}/tests/test_model_cache.py +0 -0
  119. {microharness-0.2.0 → microharness-0.2.2}/tests/test_model_context.py +0 -0
  120. {microharness-0.2.0 → microharness-0.2.2}/tests/test_payload_reasoning.py +0 -0
  121. {microharness-0.2.0 → microharness-0.2.2}/tests/test_prompts.py +0 -0
  122. {microharness-0.2.0 → microharness-0.2.2}/tests/test_protocols.py +0 -0
  123. {microharness-0.2.0 → microharness-0.2.2}/tests/test_providers.py +0 -0
  124. {microharness-0.2.0 → microharness-0.2.2}/tests/test_session.py +0 -0
  125. {microharness-0.2.0 → microharness-0.2.2}/tests/test_skills.py +0 -0
  126. {microharness-0.2.0 → microharness-0.2.2}/tests/test_subagents.py +0 -0
  127. {microharness-0.2.0 → microharness-0.2.2}/tests/test_tools.py +0 -0
  128. {microharness-0.2.0 → microharness-0.2.2}/tests/test_tracer.py +0 -0
  129. {microharness-0.2.0 → microharness-0.2.2}/tests/test_tui.py +0 -0
  130. {microharness-0.2.0 → microharness-0.2.2}/tests/test_tui_session.py +0 -0
  131. {microharness-0.2.0 → microharness-0.2.2}/tests/test_usage.py +0 -0
@@ -2,7 +2,7 @@
2
2
  <!-- Briefly describe what this PR changes and why. -->
3
3
 
4
4
  ## Checklist
5
- - [ ] Updated `CHANGELOG.md` and `docs/changelog.md` for any user-facing or functional changes
6
- - [ ] Updated relevant docs in `docs/` / `README.md` / `SPEC.md` (and `docs/index.md` if version bumped)
5
+ - [ ] Updated `## [Unreleased]` in `CHANGELOG.md` and `docs/changelog.md` for any user-facing or functional changes (leave package versions untouched unless this is a Release PR)
6
+ - [ ] Updated relevant docs in `docs/` / `README.md` / `SPEC.md`
7
7
  - [ ] Added or updated unit tests in `tests/`
8
8
  - [ ] Verified `uv run pytest`, `uv run ruff check .`, `uv run ruff format --check .`, and `uv run ty check`
@@ -0,0 +1,302 @@
1
+ """Release preparation and changelog utilities for microharness."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import datetime as dt
7
+ import re
8
+ import subprocess
9
+ import sys
10
+ from pathlib import Path
11
+
12
+ import tomllib
13
+
14
+ _SEMVER_RE = re.compile(r"^(\d+)\.(\d+)\.(\d+)$")
15
+ _PYPROJECT_VERSION_RE = re.compile(r'^(version\s*=\s*")([^"]+)(")', re.MULTILINE)
16
+ _DUNDER_VERSION_RE = re.compile(r'^(__version__\s*=\s*")([^"]+)(")', re.MULTILINE)
17
+ _DOCS_INDEX_HEADING_RE = re.compile(r"^(# microharness \(`v)([^`]+)(`\))", re.MULTILINE)
18
+ _UNRELEASED_HEADING_RE = re.compile(r"^## \[Unreleased\][ \t]*$", re.MULTILINE)
19
+ _SECTION_HEADING_RE = re.compile(r"^## \[([^\]]+)\]", re.MULTILINE)
20
+
21
+
22
+ class ReleaseError(RuntimeError):
23
+ """Raised when release metadata or changelog validation fails."""
24
+
25
+
26
+ def parse_semver(version: str) -> tuple[int, int, int]:
27
+ """Parse a strict X.Y.Z semantic version string."""
28
+ match = _SEMVER_RE.fullmatch(version.strip())
29
+ if match is None:
30
+ raise ReleaseError(f"Invalid semantic version {version!r}; expected X.Y.Z.")
31
+ return int(match.group(1)), int(match.group(2)), int(match.group(3))
32
+
33
+
34
+ def compute_next_version(current: str, target: str) -> str:
35
+ """Compute the next semantic version from a bump kind or explicit X.Y.Z target."""
36
+ major, minor, patch = parse_semver(current)
37
+ normalized = target.strip()
38
+ if normalized == "patch":
39
+ return f"{major}.{minor}.{patch + 1}"
40
+ if normalized == "minor":
41
+ return f"{major}.{minor + 1}.0"
42
+ if normalized == "major":
43
+ return f"{major + 1}.0.0"
44
+
45
+ candidate = parse_semver(normalized)
46
+ if candidate <= (major, minor, patch):
47
+ raise ReleaseError(
48
+ f"Target version {normalized!r} must be greater than current version {current!r}."
49
+ )
50
+ return normalized
51
+
52
+
53
+ def read_package_version(repo_root: Path) -> str:
54
+ """Read [project].version from pyproject.toml."""
55
+ pyproject_path = repo_root / "pyproject.toml"
56
+ data = tomllib.loads(pyproject_path.read_text(encoding="utf-8"))
57
+ version = data.get("project", {}).get("version")
58
+ if not isinstance(version, str):
59
+ raise ReleaseError("Missing [project].version in pyproject.toml.")
60
+ parse_semver(version)
61
+ return version
62
+
63
+
64
+ def _replace_unique(
65
+ text: str,
66
+ pattern: re.Pattern[str],
67
+ new_version: str,
68
+ description: str,
69
+ ) -> str:
70
+ matches = list(pattern.finditer(text))
71
+ if len(matches) != 1:
72
+ raise ReleaseError(f"Expected exactly 1 {description} match, found {len(matches)}.")
73
+ match = matches[0]
74
+ return f"{text[: match.start(2)]}{new_version}{text[match.end(2) :]}"
75
+
76
+
77
+ def extract_unreleased_notes(text: str) -> str:
78
+ """Return the body of the ## [Unreleased] section, or empty string if absent."""
79
+ match = _UNRELEASED_HEADING_RE.search(text)
80
+ if match is None:
81
+ return ""
82
+ after_heading = text[match.end() :]
83
+ next_heading = _SECTION_HEADING_RE.search(after_heading)
84
+ body = after_heading[: next_heading.start()] if next_heading else after_heading
85
+ return body.strip()
86
+
87
+
88
+ def promote_changelog(
89
+ text: str,
90
+ version: str,
91
+ release_date: str,
92
+ fallback_notes: str = "",
93
+ allow_empty_unreleased: bool = False,
94
+ ) -> str:
95
+ """Promote ## [Unreleased] in a Keep a Changelog file into ## [version] - date."""
96
+ parse_semver(version)
97
+ existing_headings = {m.group(1) for m in _SECTION_HEADING_RE.finditer(text)}
98
+ if version in existing_headings:
99
+ raise ReleaseError(f"Changelog already contains version [{version}].")
100
+
101
+ unreleased_match = _UNRELEASED_HEADING_RE.search(text)
102
+ if unreleased_match is not None:
103
+ prefix = text[: unreleased_match.start()]
104
+ after_heading = text[unreleased_match.end() :]
105
+ next_heading = _SECTION_HEADING_RE.search(after_heading)
106
+ raw_body = after_heading[: next_heading.start()] if next_heading else after_heading
107
+ suffix = after_heading[next_heading.start() :] if next_heading else ""
108
+ body = raw_body.strip()
109
+ else:
110
+ first_heading = _SECTION_HEADING_RE.search(text)
111
+ prefix = text[: first_heading.start()] if first_heading else f"{text.rstrip()}\n\n"
112
+ suffix = text[first_heading.start() :] if first_heading else ""
113
+ body = ""
114
+
115
+ if not body:
116
+ if fallback_notes.strip():
117
+ body = fallback_notes.strip()
118
+ elif allow_empty_unreleased:
119
+ body = f"### Changed\n- Release `v{version}`."
120
+ else:
121
+ raise ReleaseError(
122
+ "No release notes found under '## [Unreleased]'. "
123
+ "Add entries or pass --allow-empty-unreleased."
124
+ )
125
+
126
+ promoted_block = f"## [Unreleased]\n\n## [{version}] - {release_date}\n\n{body}\n"
127
+ if suffix:
128
+ return f"{prefix}{promoted_block}\n{suffix.lstrip()}"
129
+ return f"{prefix}{promoted_block}"
130
+
131
+
132
+ def extract_release_notes(text: str, version: str) -> str:
133
+ """Extract the changelog section body for a given released version."""
134
+ parse_semver(version)
135
+ heading_re = re.compile(rf"^## \[{re.escape(version)}\][^\n]*$", re.MULTILINE)
136
+ match = heading_re.search(text)
137
+ if match is None:
138
+ raise ReleaseError(f"Version [{version}] not found in changelog.")
139
+ after_heading = text[match.end() :]
140
+ next_heading = _SECTION_HEADING_RE.search(after_heading)
141
+ body = after_heading[: next_heading.start()] if next_heading else after_heading
142
+ stripped = body.strip()
143
+ if not stripped:
144
+ raise ReleaseError(f"Release section [{version}] in changelog is empty.")
145
+ return stripped
146
+
147
+
148
+ def prepare_release(
149
+ repo_root: Path,
150
+ target: str,
151
+ release_date: str | None = None,
152
+ fallback_notes: str = "",
153
+ allow_empty_unreleased: bool = False,
154
+ dry_run: bool = False,
155
+ run_uv_lock: bool = False,
156
+ ) -> str:
157
+ """Bump package versions and promote changelogs atomically for a release."""
158
+ current_version = read_package_version(repo_root)
159
+ next_version = compute_next_version(current_version, target)
160
+ effective_date = release_date or dt.datetime.now(dt.timezone.utc).date().isoformat()
161
+
162
+ pyproject_path = repo_root / "pyproject.toml"
163
+ pkg_init_path = repo_root / "microharness" / "__init__.py"
164
+ core_init_path = repo_root / "core" / "__init__.py"
165
+ docs_index_path = repo_root / "docs" / "index.md"
166
+ changelog_path = repo_root / "CHANGELOG.md"
167
+ docs_changelog_path = repo_root / "docs" / "changelog.md"
168
+
169
+ changelog_text = changelog_path.read_text(encoding="utf-8")
170
+ docs_changelog_text = docs_changelog_path.read_text(encoding="utf-8")
171
+ primary_unreleased = extract_unreleased_notes(changelog_text)
172
+ docs_fallback = primary_unreleased or fallback_notes
173
+
174
+ updates: dict[Path, str] = {
175
+ pyproject_path: _replace_unique(
176
+ pyproject_path.read_text(encoding="utf-8"),
177
+ _PYPROJECT_VERSION_RE,
178
+ next_version,
179
+ "pyproject.toml version",
180
+ ),
181
+ pkg_init_path: _replace_unique(
182
+ pkg_init_path.read_text(encoding="utf-8"),
183
+ _DUNDER_VERSION_RE,
184
+ next_version,
185
+ "microharness/__init__.py __version__",
186
+ ),
187
+ core_init_path: _replace_unique(
188
+ core_init_path.read_text(encoding="utf-8"),
189
+ _DUNDER_VERSION_RE,
190
+ next_version,
191
+ "core/__init__.py __version__",
192
+ ),
193
+ docs_index_path: _replace_unique(
194
+ docs_index_path.read_text(encoding="utf-8"),
195
+ _DOCS_INDEX_HEADING_RE,
196
+ next_version,
197
+ "docs/index.md heading version",
198
+ ),
199
+ changelog_path: promote_changelog(
200
+ changelog_text,
201
+ next_version,
202
+ effective_date,
203
+ fallback_notes=fallback_notes,
204
+ allow_empty_unreleased=allow_empty_unreleased,
205
+ ),
206
+ docs_changelog_path: promote_changelog(
207
+ docs_changelog_text,
208
+ next_version,
209
+ effective_date,
210
+ fallback_notes=docs_fallback,
211
+ allow_empty_unreleased=allow_empty_unreleased,
212
+ ),
213
+ }
214
+
215
+ if not dry_run:
216
+ for path, content in updates.items():
217
+ path.write_text(content, encoding="utf-8")
218
+ if run_uv_lock:
219
+ subprocess.run(["uv", "lock"], cwd=repo_root, check=True)
220
+
221
+ return next_version
222
+
223
+
224
+ def _build_parser() -> argparse.ArgumentParser:
225
+ parser = argparse.ArgumentParser(description="microharness release helper")
226
+ subparsers = parser.add_subparsers(dest="command", required=True)
227
+
228
+ next_cmd = subparsers.add_parser("next-version", help="Compute next SemVer version")
229
+ next_cmd.add_argument("--target", required=True, help="patch, minor, major, or X.Y.Z")
230
+ next_cmd.add_argument("--repo-root", type=Path, default=Path("."))
231
+
232
+ prep_cmd = subparsers.add_parser("prepare", help="Prepare release version and changelog")
233
+ prep_cmd.add_argument("--target", required=True, help="patch, minor, major, or X.Y.Z")
234
+ prep_cmd.add_argument(
235
+ "--date", default=None, help="Release date YYYY-MM-DD (UTC today default)"
236
+ )
237
+ prep_cmd.add_argument(
238
+ "--fallback-notes", default="", help="Fallback notes if Unreleased is empty"
239
+ )
240
+ prep_cmd.add_argument("--allow-empty-unreleased", action="store_true")
241
+ prep_cmd.add_argument(
242
+ "--uv-lock", action="store_true", help="Run `uv lock` after updating files"
243
+ )
244
+ prep_cmd.add_argument("--dry-run", action="store_true")
245
+ prep_cmd.add_argument("--repo-root", type=Path, default=Path("."))
246
+
247
+ notes_cmd = subparsers.add_parser("extract-notes", help="Extract changelog notes for a version")
248
+ notes_cmd.add_argument(
249
+ "--version", default=None, help="Version X.Y.Z (defaults to pyproject.toml)"
250
+ )
251
+ notes_cmd.add_argument("--changelog", type=Path, default=None)
252
+ notes_cmd.add_argument("--output", type=Path, default=None)
253
+ notes_cmd.add_argument("--repo-root", type=Path, default=Path("."))
254
+
255
+ return parser
256
+
257
+
258
+ def main(argv: list[str] | None = None) -> int:
259
+ parser = _build_parser()
260
+ args = parser.parse_args(argv)
261
+ repo_root = args.repo_root.resolve()
262
+
263
+ try:
264
+ if args.command == "next-version":
265
+ current = read_package_version(repo_root)
266
+ print(compute_next_version(current, args.target))
267
+ return 0
268
+
269
+ if args.command == "prepare":
270
+ next_version = prepare_release(
271
+ repo_root=repo_root,
272
+ target=args.target,
273
+ release_date=args.date,
274
+ fallback_notes=args.fallback_notes,
275
+ allow_empty_unreleased=args.allow_empty_unreleased,
276
+ dry_run=args.dry_run,
277
+ run_uv_lock=args.uv_lock,
278
+ )
279
+ print(next_version)
280
+ return 0
281
+
282
+ if args.command == "extract-notes":
283
+ version = args.version or read_package_version(repo_root)
284
+ changelog_path = args.changelog or (repo_root / "CHANGELOG.md")
285
+ notes = extract_release_notes(
286
+ changelog_path.read_text(encoding="utf-8"),
287
+ version,
288
+ )
289
+ if args.output is not None:
290
+ args.output.write_text(f"{notes}\n", encoding="utf-8")
291
+ else:
292
+ print(notes)
293
+ return 0
294
+ except ReleaseError as exc:
295
+ print(f"error: {exc}", file=sys.stderr)
296
+ return 1
297
+
298
+ return 1
299
+
300
+
301
+ if __name__ == "__main__":
302
+ raise SystemExit(main())
@@ -0,0 +1,185 @@
1
+ name: Publish to PyPI
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+ pull_request:
7
+ branches: [main]
8
+ types: [closed]
9
+ workflow_dispatch:
10
+ inputs:
11
+ dry_run:
12
+ description: "Run checks and build distributions without publishing to PyPI"
13
+ type: boolean
14
+ required: false
15
+ default: true
16
+
17
+ concurrency:
18
+ group: >-
19
+ ${{
20
+ (github.event_name != 'pull_request' ||
21
+ (github.event.pull_request.merged == true &&
22
+ contains(github.event.pull_request.labels.*.name, 'release')))
23
+ && 'publish-pypi'
24
+ || format('publish-pypi-skip-{0}', github.run_id)
25
+ }}
26
+ cancel-in-progress: false
27
+
28
+ jobs:
29
+ test:
30
+ name: Run tests, checks, and release validation
31
+ if: >-
32
+ github.event_name != 'pull_request' ||
33
+ (github.event.pull_request.merged == true &&
34
+ contains(github.event.pull_request.labels.*.name, 'release'))
35
+ runs-on: ubuntu-latest
36
+ permissions:
37
+ contents: read
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+ with:
41
+ ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.ref }}
42
+ fetch-depth: 0
43
+
44
+ - name: Set up uv
45
+ uses: astral-sh/setup-uv@v5
46
+ with:
47
+ enable-cache: true
48
+
49
+ - name: Set up Python
50
+ run: uv python install 3.11
51
+
52
+ - name: Verify release tag matches package version
53
+ if: github.event_name == 'release'
54
+ env:
55
+ RELEASE_TAG: ${{ github.event.release.tag_name }}
56
+ run: |
57
+ uv run python -c '
58
+ import os, tomllib
59
+ from pathlib import Path
60
+ version = tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"]
61
+ expected = f"v{version}"
62
+ actual = os.environ["RELEASE_TAG"]
63
+ if actual != expected:
64
+ raise SystemExit(f"Release tag {actual!r} does not match pyproject.toml version {expected!r}")
65
+ print(f"Verified release tag {actual} matches package version {version}")
66
+ '
67
+
68
+ - name: Validate release PR state and changelog notes
69
+ if: github.event_name == 'pull_request'
70
+ env:
71
+ MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
72
+ run: |
73
+ version="$(uv run python -c 'import tomllib; from pathlib import Path; print(tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"])')"
74
+ tag="v${version}"
75
+ if git rev-parse "refs/tags/${tag}" >/dev/null 2>&1; then
76
+ tag_commit="$(git rev-parse "refs/tags/${tag}^{commit}")"
77
+ if [[ "$tag_commit" != "$MERGE_SHA" ]]; then
78
+ echo "Tag ${tag} already exists on ${tag_commit} (expected ${MERGE_SHA}). Bump the package version first." >&2
79
+ exit 1
80
+ fi
81
+ fi
82
+ uv run python .github/scripts/release.py extract-notes --version "$version" >/dev/null
83
+ echo "Validated release v${version} for commit ${MERGE_SHA}"
84
+
85
+ - name: Run lint and format check
86
+ run: |
87
+ uv run ruff check .
88
+ uv run ruff format --check .
89
+
90
+ - name: Run type check
91
+ run: uv run ty check
92
+
93
+ - name: Run test suite
94
+ run: uv run pytest
95
+
96
+ build:
97
+ name: Build distributions
98
+ needs: test
99
+ runs-on: ubuntu-latest
100
+ permissions:
101
+ contents: read
102
+ steps:
103
+ - uses: actions/checkout@v4
104
+ with:
105
+ ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.ref }}
106
+
107
+ - name: Set up uv
108
+ uses: astral-sh/setup-uv@v5
109
+ with:
110
+ enable-cache: true
111
+
112
+ - name: Build package
113
+ run: uv build
114
+
115
+ - name: Upload dist artifacts
116
+ uses: actions/upload-artifact@v4
117
+ with:
118
+ name: dist
119
+ path: dist/
120
+
121
+ create_release:
122
+ name: Create tag and GitHub Release
123
+ needs: [test, build]
124
+ if: >-
125
+ github.event_name == 'pull_request' &&
126
+ github.event.pull_request.merged == true &&
127
+ contains(github.event.pull_request.labels.*.name, 'release')
128
+ runs-on: ubuntu-latest
129
+ permissions:
130
+ contents: write
131
+ steps:
132
+ - uses: actions/checkout@v4
133
+ with:
134
+ ref: ${{ github.event.pull_request.merge_commit_sha }}
135
+ fetch-depth: 0
136
+
137
+ - name: Set up uv
138
+ uses: astral-sh/setup-uv@v5
139
+ with:
140
+ enable-cache: true
141
+
142
+ - name: Set up Python
143
+ run: uv python install 3.11
144
+
145
+ - name: Create GitHub Release for merged Release PR
146
+ env:
147
+ GH_TOKEN: ${{ github.token }}
148
+ MERGE_SHA: ${{ github.event.pull_request.merge_commit_sha }}
149
+ run: |
150
+ version="$(uv run python -c 'import tomllib; from pathlib import Path; print(tomllib.loads(Path("pyproject.toml").read_text())["project"]["version"])')"
151
+ tag="v${version}"
152
+ uv run python .github/scripts/release.py extract-notes --version "$version" --output /tmp/release-notes.md
153
+ if gh release view "$tag" >/dev/null 2>&1; then
154
+ echo "GitHub Release ${tag} already exists; skipping creation."
155
+ else
156
+ gh release create "$tag" \
157
+ --target "$MERGE_SHA" \
158
+ --title "$tag" \
159
+ --notes-file /tmp/release-notes.md
160
+ fi
161
+
162
+ publish:
163
+ name: Publish package to PyPI
164
+ needs: [test, build, create_release]
165
+ if: >-
166
+ always() &&
167
+ needs.test.result == 'success' &&
168
+ needs.build.result == 'success' &&
169
+ (needs.create_release.result == 'success' || needs.create_release.result == 'skipped') &&
170
+ (github.event_name != 'workflow_dispatch' || !inputs.dry_run)
171
+ runs-on: ubuntu-latest
172
+ permissions:
173
+ id-token: write # Required for PyPI Trusted Publishing (OIDC)
174
+ environment:
175
+ name: pypi
176
+ url: https://pypi.org/p/microharness
177
+ steps:
178
+ - name: Download dist artifacts
179
+ uses: actions/download-artifact@v4
180
+ with:
181
+ name: dist
182
+ path: dist/
183
+
184
+ - name: Publish to PyPI (with PEP 740 provenance attestations)
185
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,164 @@
1
+ name: Prepare Release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ bump:
7
+ description: "SemVer bump type (ignored if explicit version is provided)"
8
+ type: choice
9
+ required: true
10
+ default: patch
11
+ options:
12
+ - patch
13
+ - minor
14
+ - major
15
+ version:
16
+ description: "Optional explicit X.Y.Z version (overrides bump)"
17
+ type: string
18
+ required: false
19
+ default: ""
20
+ allow_empty_unreleased:
21
+ description: "Allow cutting a release from commit history if ## [Unreleased] is empty"
22
+ type: boolean
23
+ required: false
24
+ default: false
25
+
26
+ permissions:
27
+ contents: write
28
+ pull-requests: write
29
+
30
+ concurrency:
31
+ group: prepare-release
32
+ cancel-in-progress: false
33
+
34
+ jobs:
35
+ prepare-release:
36
+ name: Prepare release PR
37
+ runs-on: ubuntu-latest
38
+ steps:
39
+ - uses: actions/checkout@v4
40
+ with:
41
+ fetch-depth: 0
42
+ token: ${{ secrets.RELEASE_TOKEN || github.token }}
43
+
44
+ - name: Set up uv
45
+ uses: astral-sh/setup-uv@v5
46
+ with:
47
+ enable-cache: true
48
+
49
+ - name: Set up Python
50
+ run: uv python install 3.11
51
+
52
+ - name: Compute next release version and commit summary
53
+ id: meta
54
+ env:
55
+ INPUT_BUMP: ${{ inputs.bump }}
56
+ INPUT_VERSION: ${{ inputs.version }}
57
+ run: |
58
+ target="${INPUT_VERSION:-$INPUT_BUMP}"
59
+ version="$(uv run python .github/scripts/release.py next-version --target "$target")"
60
+ if git rev-parse "refs/tags/v${version}" >/dev/null 2>&1; then
61
+ echo "Error: tag v${version} already exists." >&2
62
+ exit 1
63
+ fi
64
+
65
+ prev_tag="$(git describe --tags --abbrev=0 --match 'v*' 2>/dev/null || true)"
66
+ if [[ -n "$prev_tag" ]]; then
67
+ git log "${prev_tag}..HEAD" --pretty=format:"- %s (%h)" > /tmp/commits.txt
68
+ else
69
+ git log -n 30 --pretty=format:"- %s (%h)" > /tmp/commits.txt
70
+ fi
71
+
72
+ if [[ -s /tmp/commits.txt ]]; then
73
+ {
74
+ echo "### Changed"
75
+ cat /tmp/commits.txt
76
+ } > /tmp/fallback-notes.md
77
+ else
78
+ echo "### Changed" > /tmp/fallback-notes.md
79
+ echo "- Release \`v${version}\`." >> /tmp/fallback-notes.md
80
+ fi
81
+
82
+ {
83
+ echo "target=$target"
84
+ echo "version=$version"
85
+ echo "prev_tag=$prev_tag"
86
+ } >> "$GITHUB_OUTPUT"
87
+
88
+ - name: Update version files, changelogs, and lockfile
89
+ env:
90
+ TARGET: ${{ steps.meta.outputs.target }}
91
+ ALLOW_EMPTY: ${{ inputs.allow_empty_unreleased }}
92
+ run: |
93
+ args=(prepare --target "$TARGET" --uv-lock)
94
+ if [[ "$ALLOW_EMPTY" == "true" ]]; then
95
+ args+=(--allow-empty-unreleased --fallback-notes "$(cat /tmp/fallback-notes.md)")
96
+ fi
97
+ uv run python .github/scripts/release.py "${args[@]}"
98
+
99
+ - name: Verify lint, format, types, and tests
100
+ run: |
101
+ uv run ruff check .
102
+ uv run ruff format --check .
103
+ uv run ty check
104
+ uv run pytest
105
+
106
+ - name: Extract release notes
107
+ env:
108
+ VERSION: ${{ steps.meta.outputs.version }}
109
+ run: |
110
+ uv run python .github/scripts/release.py extract-notes \
111
+ --version "$VERSION" \
112
+ --output /tmp/release-notes.md
113
+
114
+ - name: Commit and push release branch
115
+ env:
116
+ VERSION: ${{ steps.meta.outputs.version }}
117
+ run: |
118
+ branch="release/v${VERSION}"
119
+ git config user.name "github-actions[bot]"
120
+ git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
121
+ git checkout -B "$branch"
122
+ git add pyproject.toml microharness/__init__.py core/__init__.py docs/index.md CHANGELOG.md docs/changelog.md uv.lock
123
+ git commit -m "chore(release): v${VERSION}"
124
+ git push --force origin "$branch"
125
+
126
+ - name: Open or update Release PR
127
+ env:
128
+ GH_TOKEN: ${{ secrets.RELEASE_TOKEN || github.token }}
129
+ VERSION: ${{ steps.meta.outputs.version }}
130
+ PREV_TAG: ${{ steps.meta.outputs.prev_tag }}
131
+ run: |
132
+ branch="release/v${VERSION}"
133
+ title="chore(release): v${VERSION}"
134
+ gh label create release \
135
+ --color 0e8a16 \
136
+ --description "Release PR: merging tags, creates GitHub Release, and publishes to PyPI" \
137
+ --force >/dev/null 2>&1 || true
138
+
139
+ {
140
+ echo "## Release \`v${VERSION}\`"
141
+ echo ""
142
+ echo "Merging this PR into \`main\` will automatically:"
143
+ echo "- Create git tag \`v${VERSION}\` and GitHub Release \`v${VERSION}\`"
144
+ echo "- Build and publish \`microharness==${VERSION}\` to PyPI via Trusted Publishing"
145
+ echo ""
146
+ echo "### Release Notes"
147
+ echo ""
148
+ cat /tmp/release-notes.md
149
+ echo ""
150
+ echo "### Commits Since ${PREV_TAG:-repository start}"
151
+ echo ""
152
+ if [[ -s /tmp/commits.txt ]]; then
153
+ cat /tmp/commits.txt
154
+ else
155
+ echo "- _(no new commits)_"
156
+ fi
157
+ } > /tmp/pr-body.md
158
+
159
+ existing_pr="$(gh pr list --state open --head "$branch" --base main --json number --jq '.[0].number // empty')"
160
+ if [[ -n "$existing_pr" ]]; then
161
+ gh pr edit "$existing_pr" --title "$title" --body-file /tmp/pr-body.md --add-label release
162
+ else
163
+ gh pr create --base main --head "$branch" --title "$title" --body-file /tmp/pr-body.md --label release
164
+ fi