diff --git a/.agents/generated-rules.json b/.agents/generated-rules.json index 6fc7863..c505ed1 100644 --- a/.agents/generated-rules.json +++ b/.agents/generated-rules.json @@ -1,7 +1,7 @@ { "copier-template": "c297313eea2b16f7b713e0faf4a3672de05d6ea27a4ff374e659d3960d9784bc", "documentation-toc": "c9a57aa3bd766ede36c80761786aa113bea025e92c3fc28a189c0b1bfc86f356", - "github-actions": "ff2bdef59ef786c7aae187227b1e7313427a199134538abf98eb495be87b2737", + "github-actions": "00e9df140a396df37cda1ecc47400e441e0715c44817a4f714360316de9259bd", "markdown-documentation": "b83a62259c4f741f4e4ddb88faa403c4123dde19f9c2fd4078527ec26eafe8c2", - "shell-scripts": "bfb8e475d0e8f9e01fe1fd241625bb5c06ba5845748ff00baf80e1829d5dde1c" + "shell-scripts": "bdeed1f2724292989168f25949c8d83245f1436c24a3b82dab10429f60790d64" } diff --git a/.agents/rules/commit-message-convention.md b/.agents/rules/commit-message-convention.md index 80a61f5..b46b63b 100644 --- a/.agents/rules/commit-message-convention.md +++ b/.agents/rules/commit-message-convention.md @@ -14,6 +14,7 @@ Allowed types: - `chore` - `style` - `perf` +- `ci` Rules: diff --git a/.agents/rules/github-actions.md b/.agents/rules/github-actions.md index 6ba59a5..9ea4b70 100644 --- a/.agents/rules/github-actions.md +++ b/.agents/rules/github-actions.md @@ -3,12 +3,12 @@ ## Callable workflows (this repository) - Files under **`.github/workflows/`** that define **`on: workflow_call`** are **reusable entry points**. This repo uses the **`reusable-` filename prefix** as an org convention for discoverability (see `docs/reusable-workflows.md`). Renaming a published reusable file is a **breaking change** for every consumer `uses:` path. -- **`release-tag.yml`** runs on pushes to `main`. On a version bump, its shared workflow creates the tag and publishes the GitHub Release. The calling job grants `contents: write` for publication. See **`docs/versioning.md`**. +- **`release-tag.yml`** runs on pushes to `main`. On a version bump, its shared workflow creates the tag and publishes the GitHub Release. The calling job grants `contents: write` for publication. Its `release-please` job stays suspended until the repository is enrolled for Release Please. See **`docs/versioning.md`**. - **`reusable-pre-commit.yml`** should remain a thin, predictable pipeline: checkout → setup Python (with pip cache) → optional pre-install → install → `pre-commit run --all-files` (or overridden command). Avoid surprising side effects in defaults; document new **`inputs`** in `docs/reusable-workflows.md` and **`CHANGELOG.md`** when behavior or contract changes. ## Template caller workflows (`template/.github/workflows/`) -- **`lint.yml`** is the **Tier A** pattern: a single job that **`uses:`** the org reusable workflow with a **pinned ref**. The pin is bumped by **`scripts/standards_release_bump.sh`** (`.bumpversion.toml`) and reaches consumers via `copier update`. +- **`lint.yml`** is the **Tier A** pattern: a single job that **`uses:`** the org reusable workflow with a **pinned ref**. Its pin carries the `x-release-please-version` marker so release preparation bumps it with `STANDARDS_VERSION`, and it reaches consumers via `copier update`. - **`test.yml`** is a **starter only** for consumer repos. This standards repo does **not** ship a reusable test matrix. Reviews should resist moving project-specific test logic here unless the README and docs explicitly expand that scope. ## Review checklist diff --git a/.agents/rules/shell-scripts.md b/.agents/rules/shell-scripts.md index eb5a998..72a845c 100644 --- a/.agents/rules/shell-scripts.md +++ b/.agents/rules/shell-scripts.md @@ -1,5 +1,4 @@ # Review: shell scripts - Prefer **`#!/usr/bin/env bash`** with **`set -euo pipefail`** for new or heavily edited scripts. -- **`scripts/publish_github_release.py`** is maintainer-only: keep it working with **`CHANGELOG.md`** section headers **`## [X.Y.Z]`** and **`gh release create`**. - Use portable patterns where reasonable. Avoid introducing dependencies on nonstandard tools without documenting them. diff --git a/.bumpversion.toml b/.bumpversion.toml deleted file mode 100644 index a66e4ff..0000000 --- a/.bumpversion.toml +++ /dev/null @@ -1,44 +0,0 @@ -# Maintainer-only: sync STANDARDS_VERSION, example @v pins, and docs with bump-my-version. -# Run via scripts/standards_release_bump.sh (then finalize_changelog). Do not list CHANGELOG.md here. - -[tool.bumpversion] -current_version = "5.2.1" -commit = false -tag = false -allow_dirty = false -parse = "(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)" -serialize = ["{major}.{minor}.{patch}"] -regex = false - -[[tool.bumpversion.files]] -filename = "STANDARDS_VERSION" - -[[tool.bumpversion.files]] -filename = "README.md" -search = "@v{current_version}" -replace = "@v{new_version}" - -[[tool.bumpversion.files]] -filename = "docs/migration-guide.md" -search = "@v{current_version}" -replace = "@v{new_version}" - -[[tool.bumpversion.files]] -filename = "docs/migration-guide.md" -search = "{current_version}" -replace = "{new_version}" - -[[tool.bumpversion.files]] -filename = "docs/reusable-workflows.md" -search = "@v{current_version}" -replace = "@v{new_version}" - -[[tool.bumpversion.files]] -filename = "docs/versioning.md" -search = "v{current_version}" -replace = "v{new_version}" - -[[tool.bumpversion.files]] -filename = "template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja" -search = "@v{current_version}" -replace = "@v{new_version}" diff --git a/.claude/rules/github-actions.md b/.claude/rules/github-actions.md index ccc73ab..ae8dc1b 100644 --- a/.claude/rules/github-actions.md +++ b/.claude/rules/github-actions.md @@ -10,12 +10,12 @@ paths: ## Callable workflows (this repository) - Files under **`.github/workflows/`** that define **`on: workflow_call`** are **reusable entry points**. This repo uses the **`reusable-` filename prefix** as an org convention for discoverability (see `docs/reusable-workflows.md`). Renaming a published reusable file is a **breaking change** for every consumer `uses:` path. -- **`release-tag.yml`** runs on pushes to `main`. On a version bump, its shared workflow creates the tag and publishes the GitHub Release. The calling job grants `contents: write` for publication. See **`docs/versioning.md`**. +- **`release-tag.yml`** runs on pushes to `main`. On a version bump, its shared workflow creates the tag and publishes the GitHub Release. The calling job grants `contents: write` for publication. Its `release-please` job stays suspended until the repository is enrolled for Release Please. See **`docs/versioning.md`**. - **`reusable-pre-commit.yml`** should remain a thin, predictable pipeline: checkout → setup Python (with pip cache) → optional pre-install → install → `pre-commit run --all-files` (or overridden command). Avoid surprising side effects in defaults; document new **`inputs`** in `docs/reusable-workflows.md` and **`CHANGELOG.md`** when behavior or contract changes. ## Template caller workflows (`template/.github/workflows/`) -- **`lint.yml`** is the **Tier A** pattern: a single job that **`uses:`** the org reusable workflow with a **pinned ref**. The pin is bumped by **`scripts/standards_release_bump.sh`** (`.bumpversion.toml`) and reaches consumers via `copier update`. +- **`lint.yml`** is the **Tier A** pattern: a single job that **`uses:`** the org reusable workflow with a **pinned ref**. Its pin carries the `x-release-please-version` marker so release preparation bumps it with `STANDARDS_VERSION`, and it reaches consumers via `copier update`. - **`test.yml`** is a **starter only** for consumer repos. This standards repo does **not** ship a reusable test matrix. Reviews should resist moving project-specific test logic here unless the README and docs explicitly expand that scope. ## Review checklist diff --git a/.claude/rules/shell-scripts.md b/.claude/rules/shell-scripts.md index 3a9c06a..5359711 100644 --- a/.claude/rules/shell-scripts.md +++ b/.claude/rules/shell-scripts.md @@ -7,5 +7,4 @@ paths: # Review: shell scripts - Prefer **`#!/usr/bin/env bash`** with **`set -euo pipefail`** for new or heavily edited scripts. -- **`scripts/publish_github_release.py`** is maintainer-only: keep it working with **`CHANGELOG.md`** section headers **`## [X.Y.Z]`** and **`gh release create`**. - Use portable patterns where reasonable. Avoid introducing dependencies on nonstandard tools without documenting them. diff --git a/.github/release-policy.json b/.github/release-policy.json index e809912..e0f71e5 100644 --- a/.github/release-policy.json +++ b/.github/release-policy.json @@ -4,13 +4,7 @@ "path": "STANDARDS_VERSION", "format": "text" }, - "mirrors": [ - { - "path": ".bumpversion.toml", - "format": "toml", - "key": "tool.bumpversion.current_version" - } - ], + "mirrors": [], "tag_prefix": "v", "changelog": "CHANGELOG.md", "outputs": { diff --git a/.github/workflows/agent-guidance.yml b/.github/workflows/agent-guidance.yml index 353a750..7c36724 100644 --- a/.github/workflows/agent-guidance.yml +++ b/.github/workflows/agent-guidance.yml @@ -30,7 +30,7 @@ jobs: run: | python3 .agent-config-engine/scripts/render-project-rules.py . python3 .agent-config-engine/scripts/check-project-agents.py . - - name: Test release preparation + - name: Check release version markers run: python3 -m unittest discover -s scripts/tests -p "test_release_*.py" - name: Verify rendered consumer templates run: bash scripts/tests/agent-template.sh "$GITHUB_WORKSPACE/.agent-config-engine/scripts/check-project-agents.py" diff --git a/.github/workflows/pr-title.yml b/.github/workflows/pr-title.yml new file mode 100644 index 0000000..31a71c1 --- /dev/null +++ b/.github/workflows/pr-title.yml @@ -0,0 +1,18 @@ +# A title edit reruns this check without restarting the test suite. +name: PR title + +on: + pull_request: + branches: [main] + types: [opened, edited, synchronize, reopened] + +permissions: + pull-requests: read + +concurrency: + group: pr-title-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + +jobs: + pr-title: + uses: BehindTheMusicTree/github-workflows/.github/workflows/pr-title.yml@8b10f1dfcb88a245e4e4256e61164b49e595faea diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index d9d2d93..649a215 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -21,3 +21,15 @@ jobs: app-id: ${{ vars.RELEASE_APP_ID }} secrets: release-app-private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} + + release-please: + needs: release-tag + # Pushes skip this job until the App and main ruleset are configured. + if: github.event_name == 'workflow_dispatch' + uses: BehindTheMusicTree/github-workflows/.github/workflows/release-please.yml@8b10f1dfcb88a245e4e4256e61164b49e595faea # v6.5.0 + with: + app-id: ${{ vars.RELEASE_PR_APP_ID }} + release-policies: .github/release-policy.json + auto-merge: true + secrets: + release-pr-app-private-key: ${{ secrets.RELEASE_PR_APP_PRIVATE_KEY }} diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f44120..d3a95f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,14 @@ The format is inspired by Keep a Changelog and follows semantic-style versioning ## [Unreleased] +### Changed + +- Prepare the move to Release Please: mark the seven standards pins with `x-release-please-version`, add the `pr-title` check and a suspended `release-please` job, and check that marked pins match `STANDARDS_VERSION`. + +### Removed + +- The manual bump path (`scripts/standards_release_bump.sh`, `scripts/finalize_standards_changelog.py`, `scripts/publish_github_release.py` and `.bumpversion.toml`) and the `.bumpversion.toml` mirror in the release policy. CI already owns tagging and publication. + ## [5.2.1] - 2026-11-25 ### Changed diff --git a/README.md b/README.md index 05c11b8..70bd7cc 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Portable agent guidance is an optional Copier bootstrap; see [development guidan - `copier.yml` + `template/`: **[Copier](https://copier.readthedocs.io/)** template rendered into consumer repos — `.pre-commit-config.yaml`, `baselines/ruff.toml`, optional `.github/workflows/lint.yml` (updated by `copier update`), plus bootstrap-only `pyproject.toml` and `.github/workflows/test.yml`. - `.github/workflows/reusable-*.yml`: **callable** workflows (shared pre-commit) for repos that reference this repository instead of duplicating lint YAML. The **`reusable-` filename prefix** is an org convention for discoverability, not a GitHub requirement — see the **Naming** section in [docs/reusable-workflows.md](docs/reusable-workflows.md). - `docs/`: **[development.md](docs/development.md)** (hub), migration guide, versioning, reusable workflows, and style notes (e.g. [`string-enums.md`](docs/string-enums.md)). -- `scripts/`: maintainer release tooling; **`standards_release_bump.sh`** + **`finalize_standards_changelog.py`** automate SemVer bumps (see [docs/versioning.md](docs/versioning.md)). **`.bumpversion.toml`** configures **`bump-my-version`** for **`STANDARDS_VERSION`** and example **`@v…`** pins (not **`CHANGELOG.md`**). +- `scripts/tests/`: repository checks, including the read-only sync between **`STANDARDS_VERSION`** and every pin carrying the Release Please version marker (see [docs/versioning.md](docs/versioning.md)). ## Usage Model @@ -77,7 +77,7 @@ Not every Python repo should use the same CI shape. Use these tiers: | **A — Library** | Packaged library, multi-OS/Python matrix, `pyproject.toml` dev extras | **Delegated** [`reusable-pre-commit.yml`](.github/workflows/reusable-pre-commit.yml) for lint; **owned** `test.yml` (see [`template/.github/workflows/test.yml`](template/.github/workflows/) + local matrix/coverage) | Thin `lint.yml` caller; full control over test CI | | **B — Service / API** | Django/FastAPI apps, Docker, DB, secrets, long integration jobs | [`reusable-pre-commit.yml`](.github/workflows/reusable-pre-commit.yml), pre-commit + policy templates | Full test / deploy workflows in the app repository | -**Pinning:** Consumer workflows should reference a **release tag** such as **`@v5.2.1`** (or a commit SHA), not **`@main`**; `copier update` bumps the template `lint.yml` pin. See [docs/versioning.md](docs/versioning.md). +**Pinning:** Consumer workflows should reference a **release tag** such as **`@v5.2.1`** (or a commit SHA), not **`@main`**; `copier update` bumps the template `lint.yml` pin. See [docs/versioning.md](docs/versioning.md). **Example Tier B:** [hear-the-music-tree-api](https://github.com/BehindTheMusicTree/hear-the-music-tree-api) keeps database and containerized pytest in its own workflow and may call **reusable pre-commit** only. See that repo’s `docs/ci/python-project-standards.md`. @@ -95,7 +95,7 @@ See [docs/reusable-workflows.md](docs/reusable-workflows.md) for caller examples Versions are **SemVer** (`v1.2.3` tags, `STANDARDS_VERSION` without `v`). Maintainers prepare version and **`CHANGELOG.md`** changes through a PR to `main`; CI creates **`vX.Y.Z`** and publishes a **GitHub Release** with the same notes. Consumers pin callable workflows to that tag (or a commit SHA), not to `main` long term. -After a version change merges into `main`, [`.github/workflows/release-tag.yml`](.github/workflows/release-tag.yml) creates the SemVer tag and publishes the GitHub Release from the matching **`CHANGELOG.md`** section. Use **`python3 scripts/publish_github_release.py --dry-run`** locally to preview notes; publication is owned by CI (see **[docs/versioning.md](docs/versioning.md)**). +After a version change merges into `main`, [`.github/workflows/release-tag.yml`](.github/workflows/release-tag.yml) creates the SemVer tag and publishes the GitHub Release from the matching **`CHANGELOG.md`** section. Publication is owned by CI; Release Please will prepare version and changelog PRs from conventional PR titles once activated (see **[docs/versioning.md](docs/versioning.md)**). ## Status diff --git a/docs/migration-guide.md b/docs/migration-guide.md index e634dab..989ebd3 100644 --- a/docs/migration-guide.md +++ b/docs/migration-guide.md @@ -18,7 +18,7 @@ Reusable workflows are resolved **at CI runtime** from this repository. Template Prefer a **release tag** or **commit SHA**, not `main`: ```yaml -uses: BehindTheMusicTree/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1 +uses: BehindTheMusicTree/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1 # x-release-please-version ``` The template’s `lint.yml` carries this pin, so `copier update` bumps it. Repos with their own caller workflow (`reusable_lint: false`) bump the pin by hand. See [versioning.md](versioning.md). @@ -28,7 +28,7 @@ The template’s `lint.yml` carries this pin, so `copier update` bumps it. Repos Install Copier with an exact pin (for example `uv tool install copier==9.18.2`), then from the repository root: ```bash -copier copy --vcs-ref v5.2.1 gh:BehindTheMusicTree/python-project-standards . --overwrite +copier copy --vcs-ref v5.2.1 gh:BehindTheMusicTree/python-project-standards . --overwrite # x-release-please-version git add -p # keep repo-specific hooks and settings the template overwrote ``` diff --git a/docs/reusable-workflows.md b/docs/reusable-workflows.md index b888c21..20b36a0 100644 --- a/docs/reusable-workflows.md +++ b/docs/reusable-workflows.md @@ -18,7 +18,7 @@ This repository uses the **`reusable-` prefix** as an **organizational conventio ## Requirements - The consumer repo must be allowed to use workflows from this repository (typically same GitHub organization and org settings that permit reusable workflows). -- Pin the callee ref (**prefer `@v5.2.1` or a commit SHA**). Avoid `@main` in production CI so standards updates do not surprise you. +- Pin the callee ref (**prefer `@v5.2.1` or a commit SHA**). Avoid `@main` in production CI so standards updates do not surprise you. ## Reference workflows @@ -33,7 +33,7 @@ This repository uses the **`reusable-` prefix** as an **organizational conventio ```yaml jobs: pre-commit: - uses: YOUR_ORG/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1 + uses: YOUR_ORG/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1 # x-release-please-version with: python-version: "3.14" install-command: | @@ -55,7 +55,7 @@ on: jobs: lint: - uses: YOUR_ORG/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1 + uses: YOUR_ORG/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1 # x-release-please-version ``` Override inputs only when needed (see table below). diff --git a/docs/versioning.md b/docs/versioning.md index 18925dd..a0a9a77 100644 --- a/docs/versioning.md +++ b/docs/versioning.md @@ -46,45 +46,17 @@ Each GitHub Release (and matching `CHANGELOG.md` section) should make adoption s ## Releasing (maintainers) -Prepare a release on a clean task branch created from current `main`. Keep the coordinated pins managed by `.bumpversion.toml`; `STANDARDS_VERSION` remains the canonical version. +`STANDARDS_VERSION` is the canonical version. Release Please will prepare releases from conventional PR titles once it is activated; until then, prepare a release by hand on a clean task branch created from current `main`: -### Automated bump (recommended) - -1. Commit meaningful release notes under `## [Unreleased]` in `CHANGELOG.md` on the task branch. -2. Run `bash scripts/standards_release_bump.sh patch` (or `minor` / `major`). It updates the version, configured example pins, and changelog together. `--commit` stages only modified release paths and creates the preparation commit. Set `CHANGELOG_DATE=YYYY-MM-DD` to override the release date. -3. Review the diff, including the updated changelog TOC. Commit the preparation and open a pull request against `main`. -4. After merge, CI validates the version, mirror, nonempty changelog section and main ancestry, then creates an annotated tag on that exact commit. The same workflow publishes the GitHub release from those notes. Rerun the failed workflow to recover; an existing release is retained. - -`--dry-run` runs the coordinated bump simulation without finalizing the changelog or committing. Only `--dry-run`, `--verbose` and `-v` are forwarded; configuration overrides and tagging options are refused. Empty changelog sections are refused before the bump. The script also refuses `main`, `develop`, detached HEADs, and dirty trees. - -**Tooling:** Prefer `uv run --with bump-my-version==1.3.0 …`; otherwise install `bump-my-version==1.3.0` on `PATH`. If the tool crashes on macOS, set `BUMP_MY_VERSION_PYTHON=3.12` (see troubleshooting below). - -### Manual checklist - -1. On the task branch, set `STANDARDS_VERSION`, `.bumpversion.toml` `current_version`, and every pin listed in that configuration to the same new version. +1. Set `STANDARDS_VERSION` and every pin marked `x-release-please-version` to the same new version. `scripts/tests/test_release_version_sync.py` fails if a marked pin differs or a current-version pin lacks its marker. 2. Move release notes into the unique matching `## [X.Y.Z] - YYYY-MM-DD` changelog section, retaining an empty `Unreleased` section and updating the TOC. -3. Commit, open a pull request against `main`, and let CI create the tag and release after merge. Do not tag or publish locally. `scripts/publish_github_release.py --dry-run` remains available to preview notes; local publication is refused once the release policy is present. - -Initial adoption keeps version v5.2.0 and creates no tag. App access and tag protections are activated separately through `github-config` before a subsequent release is prepared. +3. Commit, open a pull request against `main`, and let CI create the tag and release after merge. Do not tag or publish locally. -**Frequency:** Cut a release when there is something adopters should **intentionally** pick up—not necessarily for every doc typo. Batch small doc fixes into the next **PATCH** or **MINOR** as appropriate. - -### Troubleshooting: bump-my-version on macOS - -If **`bash scripts/standards_release_bump.sh …`** dies with **`Segmentation fault: 11`** (sometimes after a **CoreFoundation** / **“process has forked … YOU MUST exec()”** message), typical causes are: +After merge, CI validates the version, the nonempty changelog section and main ancestry, then creates an annotated tag on that exact commit. The same workflow publishes the GitHub release from those notes. Rerun the failed workflow to recover; an existing release is retained. -1. **Very new CPython** (for example **3.14** as the default **`python3`**) plus **`bump-my-version`**’s stack (**`pydantic-core`**, **`httpx`**, etc.). Wheels and extension modules may still be catching up; a **native** bug often shows up as **SIGSEGV** rather than a clean Python traceback. -2. **`uv run`** on **macOS** in a **sandboxed** or unusual environment (some IDE terminals, security tools, or **`sandbox-exec`** policies) stressing **SystemConfiguration** / network stacks; see upstream discussion around **`uv`** and macOS sandboxes ([astral-sh/uv#17799](https://github.com/astral-sh/uv/issues/17799) and linked issues). +**Version markers:** the Release Please Generic updater replaces the first SemVer of each marked line. Mark only the line holding the standards pin: `` at the end of a prose line, ` # x-release-please-version` on a pin or `copier copy --vcs-ref` line in a copyable YAML or shell example, and `{# x-release-please-version #}` directly after the template pin so the rendered workflow carries no comment or trailing space. -**What to try (in order):** - -- **Pin the interpreter for the bump only:** - **`BUMP_MY_VERSION_PYTHON=3.12 bash scripts/standards_release_bump.sh patch`** - When **`uv`** is on **`PATH`**, the script passes that value to **`uv run --python …`** so **`bump-my-version==1.3.0`** runs on a stable runtime (**`uv`** can install a managed **3.12** if needed). Without **`uv`**, install **`bump-my-version==1.3.0`** on a **3.11–3.12** environment and ensure **`bump-my-version`** on **`PATH`** uses that same interpreter. -- **Skip `uv`:** install **`bump-my-version==1.3.0`** into a **venv** with **3.12**, activate it, run **`bump-my-version bump …`** by hand, then **`python3 scripts/finalize_standards_changelog.py`** from the repo root (see the automated bump steps above). -- **Last resort (not recommended long-term):** some macOS **fork-safety** warnings go away with **`OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES`**; treat this as a diagnostic knob, not a fix for a segfaulting native extension. - -If **`bump-my-version bump --dry-run`** succeeds but a real bump crashes, the failure is likely in a code path that edits files or runs **git**—still try an older **Python** first. +**Frequency:** Cut a release when there is something adopters should **intentionally** pick up—not necessarily for every doc typo. Batch small doc fixes into the next **PATCH** or **MINOR** as appropriate. ## History diff --git a/scripts/finalize_standards_changelog.py b/scripts/finalize_standards_changelog.py deleted file mode 100644 index f917c5d..0000000 --- a/scripts/finalize_standards_changelog.py +++ /dev/null @@ -1,138 +0,0 @@ -#!/usr/bin/env python3 -"""Move CHANGELOG.md ## [Unreleased] body into ## [VERSION] using STANDARDS_VERSION.""" - -from __future__ import annotations - -import argparse -import re -import sys -from datetime import date -from pathlib import Path - - -def _repo_root() -> Path: - return Path(__file__).resolve().parents[1] - - -def _read_version(root: Path) -> str: - raw = (root / "STANDARDS_VERSION").read_text(encoding="utf-8").strip() - if not re.fullmatch(r"\d+\.\d+\.\d+", raw): - print(f"STANDARDS_VERSION must be SemVer X.Y.Z (got {raw!r}).", file=sys.stderr) - sys.exit(1) - return raw - - -def _split_unreleased(lines: list[str]) -> tuple[int, int, str] | None: - """Return (start_line_index, first_line_after_body, body_without_surrounding_blank_runs).""" - start = None - for i, line in enumerate(lines): - if line.startswith("## [Unreleased]"): - start = i - break - if start is None: - print("CHANGELOG.md: missing ## [Unreleased] section.", file=sys.stderr) - sys.exit(1) - - j = None - for k in range(start + 1, len(lines)): - if lines[k].startswith("## [") and not lines[k].startswith("## [Unreleased]"): - j = k - break - if j is None: - j = len(lines) - - body_lines = lines[start + 1 : j] - while body_lines and body_lines[0].strip() == "": - body_lines.pop(0) - while body_lines and body_lines[-1].strip() == "": - body_lines.pop() - - body = "".join(body_lines).rstrip("\n") - return start, j, body - - -def main() -> None: - parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument( - "--date", - metavar="YYYY-MM-DD", - help="Release date (default: today, local timezone).", - ) - parser.add_argument( - "--allow-empty", - action="store_true", - help="Allow an empty ## [Unreleased] body (creates a dated section with no subsections).", - ) - parser.add_argument( - "--dry-run", - action="store_true", - help="Print the new section only; do not write CHANGELOG.md.", - ) - parser.add_argument( - "--check-unreleased", - action="store_true", - help="Require nonempty release notes without writing files.", - ) - args = parser.parse_args() - - root = _repo_root() - version = _read_version(root) - changelog = root / "CHANGELOG.md" - text = changelog.read_text(encoding="utf-8") - lines = text.splitlines(keepends=True) - - start, j, body = _split_unreleased(lines) - meaningful = re.sub(r"", "", body, flags=re.DOTALL) - meaningful = "\n".join( - line - for line in meaningful.splitlines() - if line.strip() and not line.lstrip().startswith("#") - ) - if not meaningful.strip() and not args.allow_empty: - print( - "CHANGELOG.md: ## [Unreleased] has no release notes. " - "Add bullets or pass --allow-empty.", - file=sys.stderr, - ) - sys.exit(1) - - if args.check_unreleased: - return - - header = f"## [{version}] - {args.date or date.today().isoformat()}\n" - new_block = f"## [Unreleased]\n\n{header}\n" - if body.strip(): - new_block += f"{body}\n\n" - else: - new_block += "\n" - - tail = "".join(lines[j:]) - if re.search(rf"^## \[{re.escape(version)}\]", tail, re.MULTILINE): - print( - f"CHANGELOG.md already contains ## [{version}] below [Unreleased].", - file=sys.stderr, - ) - sys.exit(1) - - out_lines = lines[:start] + [new_block] + lines[j:] - out = "".join(out_lines) - - anchor_version = version.replace(".", "") - toc_entry = "- [Unreleased](#unreleased)" - if toc_entry in out: - out = out.replace( - toc_entry, - f"{toc_entry}\n- [{version} - {args.date or date.today().isoformat()}](#{anchor_version}---{args.date or date.today().isoformat()})", - 1, - ) - - if args.dry_run: - print(new_block, end="") - return - - changelog.write_text(out, encoding="utf-8", newline="\n") - print(f"CHANGELOG.md: finalized [Unreleased] → [{version}].") - - -if __name__ == "__main__": - main() diff --git a/scripts/publish_github_release.py b/scripts/publish_github_release.py deleted file mode 100644 index aa29141..0000000 --- a/scripts/publish_github_release.py +++ /dev/null @@ -1,174 +0,0 @@ -#!/usr/bin/env python3 -"""Create a GitHub Release from CHANGELOG.md using the GitHub CLI (`gh`).""" - -from __future__ import annotations - -import argparse -import os -import re -import subprocess -import sys -import tempfile -from pathlib import Path - - -def _gh_token_from_actions() -> bool: - return os.environ.get("GITHUB_ACTIONS") == "true" and bool( - os.environ.get("GITHUB_TOKEN") or os.environ.get("GH_TOKEN") - ) - - -def _git_root() -> Path: - p = subprocess.run( - ["git", "rev-parse", "--show-toplevel"], - check=True, - capture_output=True, - text=True, - ) - return Path(p.stdout.strip()) - - -def _read_version(root: Path, explicit: str | None) -> str: - if explicit: - return explicit.removeprefix("v") - return ( - (root / "STANDARDS_VERSION") - .read_text(encoding="utf-8") - .strip() - .removeprefix("v") - ) - - -def _extract_changelog_body(changelog_text: str, version: str) -> str | None: - header = re.compile(rf"^## \[{re.escape(version)}\]") - next_section = re.compile(r"^## \[") - lines = changelog_text.splitlines(keepends=True) - started = False - out: list[str] = [] - for line in lines: - if not started: - if header.match(line): - started = True - continue - if next_section.match(line): - break - out.append(line) - if not started: - return None - body = "".join(out).strip() - return body + "\n" if body else "\n" - - -def main() -> None: - parser = argparse.ArgumentParser( - description="Publish a GitHub Release for tag vX.Y.Z using the matching CHANGELOG section.", - ) - parser.add_argument( - "version", - nargs="?", - help="SemVer without v (default: STANDARDS_VERSION)", - ) - parser.add_argument( - "--draft", - action="store_true", - help="Create a draft release", - ) - parser.add_argument( - "--dry-run", - action="store_true", - help="Print release notes and gh command only", - ) - args = parser.parse_args() - - root = _git_root() - if (root / ".github/release-policy.json").exists() and not args.dry_run: - parser.error("Publication is owned by CI; rerun the Release on tag workflow.") - ver = _read_version(root, args.version) - tag = f"v{ver}" - - changelog_path = root / "CHANGELOG.md" - if not changelog_path.is_file(): - print("CHANGELOG.md not found.", file=sys.stderr) - sys.exit(1) - - body = _extract_changelog_body(changelog_path.read_text(encoding="utf-8"), ver) - if body is None: - print(f"No '## [{ver}]' section found in CHANGELOG.md.", file=sys.stderr) - sys.exit(1) - - if args.dry_run: - print(f"--- Release notes for {tag} ---\n{body}", end="") - cmd = [ - "gh", - "release", - "create", - tag, - "--verify-tag", - "--title", - tag, - "--notes-file", - "", - ] - if args.draft: - cmd.append("--draft") - print("Would run:", " ".join(cmd).replace("", "(changelog body)")) - return - - if not _gh_token_from_actions(): - gh_check = subprocess.run(["gh", "auth", "status"], capture_output=True) - if gh_check.returncode != 0: - print( - "GitHub CLI is not logged in. Run `gh auth login` and retry.", - file=sys.stderr, - ) - sys.exit(1) - - tag_check = subprocess.run( - ["git", "rev-parse", "--verify", f"{tag}^{{commit}}"], - capture_output=True, - cwd=root, - ) - if tag_check.returncode != 0: - print( - f"Git tag {tag} not found locally. Create and push the tag first.", - file=sys.stderr, - ) - sys.exit(1) - - view = subprocess.run(["gh", "release", "view", tag], capture_output=True, cwd=root) - if view.returncode == 0: - print(f"Release {tag} already exists. Nothing to do.", file=sys.stderr) - sys.exit(0) - - with tempfile.NamedTemporaryFile( - mode="w", - suffix=".md", - encoding="utf-8", - delete=False, - ) as tmp: - tmp.write(body) - tmp_path = tmp.name - - try: - cmd = [ - "gh", - "release", - "create", - tag, - "--verify-tag", - "--title", - tag, - "--notes-file", - tmp_path, - ] - if args.draft: - cmd.append("--draft") - subprocess.run(cmd, check=True, cwd=root) - finally: - Path(tmp_path).unlink(missing_ok=True) - - print(f"Published GitHub release {tag}.") - - -if __name__ == "__main__": - main() diff --git a/scripts/standards_release_bump.sh b/scripts/standards_release_bump.sh deleted file mode 100755 index 0dd8a39..0000000 --- a/scripts/standards_release_bump.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/usr/bin/env bash -# Bump STANDARDS_VERSION + example pins (bump-my-version), then fold CHANGELOG [Unreleased]. -set -euo pipefail - -usage() { - echo "usage: $0 patch|minor|major [--commit] [--dry-run] [--verbose]" >&2 - echo " Requires a clean git working tree (matches .bumpversion.toml allow_dirty = false)." >&2 - echo " --commit after bump + finalize, git add only files changed since HEAD, then commit chore(release): vX.Y.Z" >&2 - echo "Optional env: CHANGELOG_DATE=YYYY-MM-DD (passed to finalize script)." >&2 - echo "Optional env: BUMP_MY_VERSION_PYTHON=3.12 (or an interpreter path) — forwarded as uv run --python when using uv;" >&2 - echo " use if bump-my-version segfaults on macOS (often default pyenv 3.14 + native deps or uv/sandbox interaction)." >&2 -} - -[[ "${1:-}" == patch || "${1:-}" == minor || "${1:-}" == major ]] || { - usage - exit 1 -} - -part="$1" -shift - -commit_release=false -bump_args=() -while [[ $# -gt 0 ]]; do - case "$1" in - --commit) - commit_release=true - shift - ;; - --dry-run|--verbose|-v) - bump_args+=("$1") - shift - ;; - *) - echo "error: unsupported option: $1 (tagging and configuration overrides are not allowed)." >&2 - exit 1 - ;; - esac -done - -root="$(git rev-parse --show-toplevel)" -cd "$root" - -branch="$(git symbolic-ref --quiet --short HEAD)" || { - echo "error: use a task branch, not a detached HEAD." >&2 - exit 1 -} -if [[ "$branch" == main || "$branch" == develop ]]; then - echo "error: prepare releases on a task branch and open a pull request against main." >&2 - exit 1 -fi - -if [[ -n "$(git status --porcelain 2>/dev/null)" ]]; then - echo "error: git working tree is not clean (see git status)." >&2 - echo " Commit or stash your edits first so bump-my-version matches allow_dirty = false." >&2 - echo " Tip: commit your ## [Unreleased] draft, then run this script." >&2 - exit 1 -fi - -dry_run=false -for a in "${bump_args[@]}"; do - if [[ "$a" == "--dry-run" ]]; then - dry_run=true - break - fi -done - -python3 "$root/scripts/finalize_standards_changelog.py" --check-unreleased - -uv_python_args=() -if [[ -n "${BUMP_MY_VERSION_PYTHON:-}" ]]; then - uv_python_args=(--python "$BUMP_MY_VERSION_PYTHON") -fi - -if command -v uv >/dev/null 2>&1; then - uv run "${uv_python_args[@]}" --with bump-my-version==1.3.0 bump-my-version bump "$part" "${bump_args[@]}" -else - bump-my-version bump "$part" "${bump_args[@]}" -fi - -if [[ "$dry_run" == true ]]; then - echo "Dry run complete; version, changelog, and commits are unchanged." - exit 0 -fi - -py=(python3 "$root/scripts/finalize_standards_changelog.py") -[[ -n "${CHANGELOG_DATE:-}" ]] && py+=(--date "$CHANGELOG_DATE") -"${py[@]}" - -ver="$(tr -d '[:space:]' <"$root/STANDARDS_VERSION")" - -if [[ "$commit_release" == true ]]; then - changed=() - while IFS= read -r line; do - [[ -n "$line" ]] && changed+=("$line") - done < <(git diff --name-only HEAD) - - if [[ ${#changed[@]} -eq 0 ]]; then - echo "error: no modified files after bump + finalize; nothing to commit." >&2 - exit 1 - fi - - git add -- "${changed[@]}" - git commit -m "chore(release): v${ver}" - printf '%s\n' "Committed release-only paths: ${changed[*]}" - printf '%s\n' "Next: open a pull request against main; CI creates the release tag after merge." -else - printf '%s\n' "Next: review git diff; stage only release files (paths from: git diff --name-only HEAD), then:" - printf '%s\n' " git commit -m \"chore(release): v${ver}\"" - printf '%s\n' "Then open a pull request against main; CI creates the tag and publishes the release." - printf '%s\n' "Tip: pass --commit on this script to create that commit automatically (same paths only, never git add -A)." -fi diff --git a/scripts/tests/test_release_preparation.py b/scripts/tests/test_release_preparation.py deleted file mode 100644 index 1d7d363..0000000 --- a/scripts/tests/test_release_preparation.py +++ /dev/null @@ -1,130 +0,0 @@ -"""Exercise release preparation in disposable Git repositories without publishing.""" - -from pathlib import Path -import os -import shutil -import subprocess -import tempfile -import unittest - - -SOURCE = Path(__file__).resolve().parents[2] - - -class PreparationTests(unittest.TestCase): - def setUp(self): - self.temp = tempfile.TemporaryDirectory() - self.addCleanup(self.temp.cleanup) - self.root = Path(self.temp.name) - (self.root / "scripts").mkdir() - for name in ( - "standards_release_bump.sh", - "finalize_standards_changelog.py", - "publish_github_release.py", - ): - shutil.copyfile(SOURCE / "scripts" / name, self.root / "scripts" / name) - (self.root / "STANDARDS_VERSION").write_text("1.0.0\n") - (self.root / ".bumpversion.toml").write_text( - '[tool.bumpversion]\ncurrent_version = "1.0.0"\n' - ) - self.notes = "# Changelog\n\n## [Unreleased]\n\n### Changed\n\n- Useful change.\n\n## [1.0.0]\n\n- Previous.\n" - (self.root / "CHANGELOG.md").write_text(self.notes) - self.git("init", "-q", "-b", "feature/release-test") - self.git("config", "user.email", "fixture@example.test") - self.git("config", "user.name", "Fixture") - self.commit() - binary = self.root / ".git" / "bin" - binary.mkdir() - uv = binary / "uv" - uv.write_text("""#!/usr/bin/env python3 -import pathlib, sys -pathlib.Path('.git/bump-called').touch() -if '--dry-run' not in sys.argv: - pathlib.Path('STANDARDS_VERSION').write_text('1.0.1\\n') - pathlib.Path('.bumpversion.toml').write_text('[tool.bumpversion]\\ncurrent_version = "1.0.1"\\n') -""") - uv.chmod(0o755) - self.env = dict(os.environ, PATH=str(binary) + os.pathsep + os.environ["PATH"]) - - def git(self, *args): - return subprocess.check_output(["git", *args], cwd=self.root, text=True).strip() - - def commit(self): - self.git("add", ".") - self.git("commit", "-qm", "fixture") - - def run_script(self, *args, success=True): - result = subprocess.run( - ["bash", "scripts/standards_release_bump.sh", "patch", *args], - cwd=self.root, - env=self.env, - text=True, - capture_output=True, - ) - self.assertEqual(result.returncode == 0, success, result.stdout + result.stderr) - return result - - def test_dry_run_does_not_change_files_or_commit(self): - before = self.git("rev-parse", "HEAD") - self.run_script("--dry-run", "--commit") - self.assertEqual(self.git("status", "--porcelain"), "") - self.assertEqual(self.git("rev-parse", "HEAD"), before) - self.assertEqual((self.root / "CHANGELOG.md").read_text(), self.notes) - - def test_preparation_updates_notes_without_creating_tag(self): - self.run_script("--commit") - self.assertEqual((self.root / "STANDARDS_VERSION").read_text(), "1.0.1\n") - self.assertIn("## [1.0.1]", (self.root / "CHANGELOG.md").read_text()) - self.assertEqual(self.git("tag"), "") - self.assertEqual(self.git("status", "--porcelain"), "") - - def test_preparation_updates_changelog_navigation(self): - notes = self.notes.replace( - "## [Unreleased]", - "## Table of Contents\n\n- [Unreleased](#unreleased)\n\n## [Unreleased]", - 1, - ) - (self.root / "CHANGELOG.md").write_text(notes) - self.commit() - self.run_script() - output = (self.root / "CHANGELOG.md").read_text() - self.assertRegex(output, r"- \[1\.0\.1 - [0-9-]+\]\(#101---[0-9-]+\)") - - def test_protected_branch_and_detached_head_fail_before_bump(self): - for branch in ("main", "develop"): - self.git("checkout", "-qb", branch) - self.run_script(success=False) - self.git("checkout", "--detach", "-q") - self.run_script(success=False) - self.assertFalse((self.root / ".git/bump-called").exists()) - - def test_empty_notes_fail_before_bump(self): - (self.root / "CHANGELOG.md").write_text( - "# Changelog\n\n## [Unreleased]\n\n### Changed\n\n\n\n## [1.0.0]\n" - ) - self.commit() - self.run_script(success=False) - self.assertFalse((self.root / ".git/bump-called").exists()) - - def test_dirty_tree_and_overrides_fail_before_bump(self): - for option in ("--tag", "--config-file=other.toml", "--allow-dirty"): - self.run_script(option, success=False) - (self.root / "untracked").touch() - self.run_script(success=False) - self.assertFalse((self.root / ".git/bump-called").exists()) - - def test_local_publication_refuses_policy_before_credentials(self): - (self.root / ".github").mkdir() - (self.root / ".github/release-policy.json").write_text("{}") - result = subprocess.run( - ["python3", "scripts/publish_github_release.py"], - cwd=self.root, - capture_output=True, - text=True, - ) - self.assertNotEqual(result.returncode, 0) - self.assertIn("Publication is owned by CI", result.stderr) - - -if __name__ == "__main__": - unittest.main() diff --git a/scripts/tests/test_release_version_sync.py b/scripts/tests/test_release_version_sync.py new file mode 100644 index 0000000..914b39a --- /dev/null +++ b/scripts/tests/test_release_version_sync.py @@ -0,0 +1,40 @@ +"""Check that every pin Release Please bumps is marked and matches STANDARDS_VERSION.""" + +from pathlib import Path +import re +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +MARKER = "x-release-please-version" +SEMVER = re.compile(r"\d+\.\d+\.\d+") +# A missing marker leaves a pin behind on the next release, so the expected count is fixed. +EXPECTED = { + "README.md": 1, + "docs/migration-guide.md": 2, + "docs/reusable-workflows.md": 3, + "template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja": 1, +} + + +class VersionSyncTests(unittest.TestCase): + def test_marked_pins_match_standards_version(self): + version = (ROOT / "STANDARDS_VERSION").read_text().strip() + self.assertRegex(version, rf"^{SEMVER.pattern}$") + for path, count in EXPECTED.items(): + marked = [line for line in (ROOT / path).read_text().splitlines() if MARKER in line] + self.assertEqual(len(marked), count, path) + for line in marked: + # The Generic updater rewrites the first SemVer of a marked line. + self.assertEqual(SEMVER.search(line).group(), version, f"{path}: {line}") + + def test_current_version_lines_are_all_marked(self): + version = (ROOT / "STANDARDS_VERSION").read_text().strip() + for path in EXPECTED: + for line in (ROOT / path).read_text().splitlines(): + if f"v{version}" in line: + self.assertIn(MARKER, line, f"{path}: {line}") + + +if __name__ == "__main__": + unittest.main() diff --git a/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja b/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja index 35c90c4..d980388 100644 --- a/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja +++ b/template/.github/workflows/{% if reusable_lint %}lint.yml{% endif %}.jinja @@ -8,4 +8,4 @@ on: jobs: lint: - uses: BehindTheMusicTree/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1 + uses: BehindTheMusicTree/python-project-standards/.github/workflows/reusable-pre-commit.yml@v5.2.1{# x-release-please-version #}