Skip to content
Merged
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
296 changes: 264 additions & 32 deletions .github/workflows/release.yml

Large diffs are not rendered by default.

387 changes: 387 additions & 0 deletions autohands/rehearsed_commits.py

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions bin/autohands
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ INTERNAL_MODULES=(
env_config # env-profile resolution library
result_collector # per-run JSON result library
generate_autofit # generate.py's autofit-specific branch
rehearsed_commits # release.yml helper: pins/resolves the rehearsed library commits (#337)
)

# _python_in_autohands <script> [args...]
Expand All @@ -135,14 +136,19 @@ _python_in_autohands() {

help_pre_build() {
cat <<'EOF'
autohands pre_build [minor_version]
autohands pre_build [minor_version] [rehearsal_run_id]

Require a clean PyAutoHands main, then run black + generate notebooks + commit
and push for every workspace repo before dispatching release.yml. PyAutoHands
itself is never staged or committed by this command.

Arguments:
minor_version Minor version suffix appended to YYYY.M.D (default: 1)
minor_version Minor version suffix appended to YYYY.M.D (default: 1)
rehearsal_run_id The successful rehearsal run of release.yml whose recorded
library commits this release publishes (or
$REHEARSAL_RUN_ID). Required: release.yml builds only
rehearsed commits (PyAutoHands#337). An optional
$COMMIT_SHAS_FILE manifest is cross-checked against it.

This is the bash entry point wrapped by the pre_build skill.
EOF
Expand Down
89 changes: 88 additions & 1 deletion docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ All scripts in `autohands/` are run from within a checked-out workspace director
- **`script_matrix.py <project1> [project2 ...]`** — Outputs a JSON matrix of `{name, directory}` pairs for GitHub Actions matrix strategy
- **`tag_and_merge.sh --version <version>`** — Commits pending changes and tags library repos (PyAutoNerves, PyAutoFit, PyAutoArray, PyAutoGalaxy, PyAutoLens) for release
- **`url_check`** — URL hygiene moved to PyAutoHeart (Heart owns all health checking). `autohands url_check` is now a thin shim to `pyauto-heart url_check`; the ecosystem-wide sweep runs from PyAutoHeart's central `url-check.yml` workflow (replacing the old per-repo `url_check.yml` workflows). The runnable scripts live at `PyAutoHeart/heart/checks/url_check*.{sh,py}`.
- **`bump_colab_urls.sh <new-tag>`** — Rewrites every `colab.research.google.com/github/PyAutoLabs/<repo>/blob/<old-tag>/...` URL in cwd to use `<new-tag>`, where `<repo>` is one of `autofit_workspace`, `autogalaxy_workspace`, `autolens_workspace`, `HowToFit`, `HowToGalaxy`, `HowToLens`. Called by the `release_workspaces` and `bump_library_colab_urls` jobs in `release.yml` so README/docs Colab links always pin to the just-released tag. Idempotent; skips URLs not in canonical PyAutoLabs/date-tagged form.
- **`bump_colab_urls.sh <new-tag>`** — Rewrites every `colab.research.google.com/github/PyAutoLabs/<repo>/blob/<old-tag>/...` URL in cwd to use `<new-tag>`, where `<repo>` is one of `autofit_workspace`, `autogalaxy_workspace`, `autolens_workspace`, `HowToFit`, `HowToGalaxy`, `HowToLens`. Called by the `release_workspaces` and `bump_library_colab_urls` jobs in `release.yml` so README/docs Colab links pin to the just-released tag (workspaces on their `main` + tag; libraries on a `release/<version>` branch, never `main` — #337). Idempotent; skips URLs not in canonical PyAutoLabs/date-tagged form.

### What `--report-dir` contains

Expand Down Expand Up @@ -351,6 +351,93 @@ The workflow (`release.yml`) is manually dispatched with inputs:
resolved version as the `testpypi-rehearsal-version` artifact, then STOP (no PyPI upload, no git
tag, no notebook/version commits, no Colab bumps). This is the mode the Heart/Brain
release-validation gate dispatches so it can install and validate the built wheels.
- `rehearsal_run_id` / `commit_shas` — which library commits the run builds (PyAutoHands#337).
The `resolve_commits` job settles this once, before anything builds, and every library
checkout uses its output; `main` is never re-read for what to publish.
- Rehearsal: each library's `main` HEAD is pinned at run start (or the `commit_shas` JSON is
built verbatim), and the `testpypi-rehearsal-version` artifact's `rehearsal.json` records
them as `commit_shas`. That artifact is the rehearsal record.
- Live: the commits come from a rehearsal record: the run named by `rehearsal_run_id`, or,
with only `commit_shas`, a recent successful rehearsal that recorded exactly those. The run
refuses before building when no rehearsal is named, the run has no record (failed, not a
rehearsal, artifact expired, or recorded before #337), or the record and `commit_shas`
disagree. `main` having moved since the rehearsal is reported, not refused: the rehearsed
commits ship and later merges wait for the next release. Each library leg logs the
rehearsed commit, the commit checked out and how far `main` is ahead, and after tagging
confirms the tag on origin peels to the rehearsed commit (`identical`).
- The library Colab URL bump (`bump_library_colab_urls`) is committed on top of the released
commit and pushed as `release/<version>` — never to `main` — so the tag stays the rehearsed
commit and the release never moves a library `main`. `main` takes it by PR. Workspace
notebooks and Colab bumps (`release_workspaces`) are unchanged.
- Every leg, rehearsal and live, also refuses a commit that is not on `main`
(`git merge-base --is-ancestor HEAD origin/main`), so a `commit_shas` input naming a PR
head or side-branch commit never becomes a rehearsal record and is never released.
- Logic and tests: `autohands/rehearsed_commits.py`, `tests/test_rehearsed_commits.py`.

#### Caller contract (Brain nightly driver and release door)

Any caller that dispatches a **live** `release.yml` (`rehearsal=false`) must follow this; a live
dispatch without it refuses in `resolve_commits` before anything is built.

The PyAutoBrain files that implement it (changed in the Brain PR that merges with this one):

- `agents/conductors/release/rehearse.sh` (around line 126): the `capture-heads` step of the
Stage 2 plan, which today reads each library's `main` HEAD after the rehearsal. It must
emit a step that takes `commit_shas` from the downloaded `rehearsal.json` instead.
- `agents/conductors/release/nightly.sh` (around lines 395-423): the consumer of that step. It
writes `$ART_DIR/commit_shas.json` (now from `rehearsal.json`, not `gh api .../commits/main`),
passes that file to `pyauto-heart validate --commit-shas`, and must add `rehearsal_run_id`
(and `commit_shas`) to the step-6 live dispatch inputs.
- The manual door: `agents/conductors/release/release.sh`, the release
`agents/conductors/release/AGENTS.md`, and `agents/conductors/build/build.sh --mode release`,
which runs `autohands pre_build`. The door must take the rehearsal run id and forward it as
`pre_build`'s second argument (or `REHEARSAL_RUN_ID`).

1. **Rehearse first.** Dispatch `release.yml` with `rehearsal=true` (optionally
`commit_shas=<json>` to build specific on-main commits). Keep the run's id.
2. **Read the record.** On success the run uploads the artifact **`testpypi-rehearsal-version`**
(`gh run download <run id> -R <owner>/PyAutoHands -n testpypi-rehearsal-version -D <dir>`).
It contains, at the artifact root, `testpypi_version.txt` and **`rehearsal.json`**:

```json
{
"mode": "rehearsal",
"index": "testpypi",
"version": "2026.11.12.1.dev123401",
"packages": ["autonerves", "autoarray", "autofit", "autogalaxy", "autolens", "autocti"],
"run_id": "12345678901",
"run_attempt": "1",
"build_sha": "<PyAutoHands commit that ran the rehearsal>",
"commit_shas": {"<library repo>": "<full 40-hex sha>", "...": "..."}
}
```

`commit_shas` has one entry per library in `autohands/config/workspaces.yaml` `libraries`
(bare repo names, the same keys as `commit_shas.json` and Heart's report). These are the
commits every leg of that run built; they are the authority, not `main` HEADs read later.
3. **Feed Heart the same commits.** Write `rehearsal.json`'s `commit_shas` object to the file
passed to `pyauto-heart validate --ingest <dir> --commit-shas <file>` (instead of re-reading
`main` after the rehearsal).

**Heart must change in the same merge.** Today `PyAutoHeart/heart/readiness.py` (about lines
596-617) compares the report's `commit_shas` with the current `main` HEADs and marks the
validation STALE ("source moved since rehearsal") whenever they differ. With rehearsed
commits as the record, `main` moving on after a rehearsal is normal, so that rule would
make most nights STALE. The Heart change, on the Heart#340 branch, makes the check
"each rehearsed SHA is an ancestor of the current `main` HEAD": fresh when that holds,
STALE only when a rehearsed commit is not on `main`. Merge Hands#337, the Brain change and
Heart#340 together; any one of them alone breaks the nightly.
4. **Dispatch the live release** with:
- `rehearsal_run_id` = the rehearsal run id (string of digits). **Required** in practice.
- `commit_shas` = the compact JSON of `rehearsal.json`'s `commit_shas` (optional cross-check;
if given it must equal the record exactly, or the run refuses).
- `minor_version` and `rehearsal=false` as before.

From the shell door: `autohands pre_build <minor_version> <rehearsal_run_id>`, with optional
`COMMIT_SHAS_FILE=<file>`; it refuses before touching any workspace without the run id.

A rehearsal record exists only for a run that concluded `success`; a failed, cancelled, live or
pre-#337 run (no `commit_shas` key), or an expired artifact, is refused as "no rehearsal record".

(The legacy `skip_scripts` / `skip_notebooks` / `skip_release` force-through knobs and the
`update_notebook_visualisations` path were removed with the Heart/Build split — Build is a pure
Expand Down
31 changes: 27 additions & 4 deletions pre_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
# notebooks + git commit & push for all workspace repos before triggering the
# GitHub Actions release workflow.
#
# Usage: bash pre_build.sh [minor_version]
# minor_version Minor version suffix (default: 1)
# Usage: bash pre_build.sh [minor_version] [rehearsal_run_id]
# minor_version Minor version suffix (default: 1)
# rehearsal_run_id The successful rehearsal run of release.yml whose recorded
# library commits this release publishes (or $REHEARSAL_RUN_ID).
# $COMMIT_SHAS_FILE Optional {library: sha} manifest; release.yml refuses
# unless it equals that rehearsal's record.
#
# pre_build always dispatches a full real release. To build + publish to
# TestPyPI without releasing (e.g. the Heart/Brain validation gate), dispatch
Expand All @@ -13,6 +17,21 @@
set -e

MINOR_VERSION="${1:-1}"
REHEARSAL_RUN_ID="${2:-${REHEARSAL_RUN_ID:-}}"

# A live release publishes exactly the commits a rehearsal built (M2.4,
# PyAutoHands#337); release.yml refuses without a rehearsal record. Refuse here
# too, before any workspace is formatted, committed or pushed.
if ! [[ "$REHEARSAL_RUN_ID" =~ ^[0-9]+$ ]]; then
echo "ABORT: pre_build needs the rehearsal run id (second argument or \$REHEARSAL_RUN_ID)." >&2
echo " A release publishes exactly the library commits that rehearsal built;" >&2
echo " rehearse first (release.yml rehearsal=true), then pass its run id." >&2
exit 1
fi
COMMIT_SHAS_JSON=""
if [ -n "${COMMIT_SHAS_FILE:-}" ]; then
COMMIT_SHAS_JSON="$(cat "$COMMIT_SHAS_FILE")"
fi

# Resolve PYAUTOBASE — the workspace root holding PyAutoHands and every
# workspace repo — through the one shared resolver when a PyAutoBrain checkout
Expand Down Expand Up @@ -243,10 +262,14 @@ done

# Trigger the GitHub Actions release workflow
echo ""
echo "=== Triggering release workflow (minor_version=$MINOR_VERSION) ==="
echo "=== Triggering release workflow (minor_version=$MINOR_VERSION, rehearsal_run_id=$REHEARSAL_RUN_ID) ==="
DISPATCH_FIELDS=(--field minor_version="$MINOR_VERSION" --field rehearsal_run_id="$REHEARSAL_RUN_ID")
if [ -n "$COMMIT_SHAS_JSON" ]; then
DISPATCH_FIELDS+=(--field commit_shas="$COMMIT_SHAS_JSON")
fi
gh workflow run release.yml \
--repo PyAutoLabs/PyAutoHands \
--field minor_version="$MINOR_VERSION"
"${DISPATCH_FIELDS[@]}"

echo ""
echo "Pre-build complete. Workflow dispatched."
Expand Down
4 changes: 2 additions & 2 deletions skills/pre_build/pre_build.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ step and say so; it is a signal, not a precondition.
Invoke the bash entry point directly:

```bash
bash $HOME/Code/PyAutoLabs/PyAutoHands/bin/autohands pre_build <minor_version>
bash $HOME/Code/PyAutoLabs/PyAutoHands/bin/autohands pre_build <minor_version> <rehearsal_run_id>
```

The script handles every mechanical step of the pre-build flow:
Expand All @@ -87,7 +87,7 @@ The script handles every mechanical step of the pre-build flow:
3. Ensures the canonical `pending-release` label exists on each release-window repo.
4. For every workspace, runs black on the staged dirs (`scripts/`, `slam_pipeline/`), runs `generate.py` for projects with a notebook target, and stages only what the run itself produced (`notebooks/`, `scripts/`, plus `slam_pipeline/` for `autolens_workspace`) — tracked edits and deletions via `git add -u`, plus newly created files by explicit path. It never runs `git add <dir>/`, which also sweeps in untracked files; that is what committed and pushed a human's uncommitted script during the 2026-08-07 release rehearsal, and is the same leak class as #126. It does not stage `dataset/` or `config/` — nothing in the run modifies them. Root-level artifacts and README Colab URLs are committed by `release.yml` on the runner, not here. `generate.py` also writes each notebook's Colab Gemini instructions from the project's assistant (`colab/contexts.yaml`), found locally via `$PYAUTO_ASSISTANT_ROOT` or else the assistant checkout in this workspace; one without that file is skipped with a warning.
5. Commits and pushes each workspace (skipping if no changes are staged).
6. Dispatches `gh workflow run release.yml --repo PyAutoLabs/PyAutoHands --field minor_version=<N>`.
6. Dispatches `gh workflow run release.yml --repo PyAutoLabs/PyAutoHands --field minor_version=<N> --field rehearsal_run_id=<run>` (plus `commit_shas` when `$COMMIT_SHAS_FILE` is set). The release builds exactly the library commits that rehearsal recorded, even if `main` has moved since, and refuses if the run has no record (PyAutoHands#337). Without a rehearsal run id the script stops before step 2.

Release-readiness — including the version-skew check that used to run here
(`verify_workspace_versions.sh`) — is gated **upstream by PyAutoHeart**
Expand Down
56 changes: 53 additions & 3 deletions tests/test_pre_build_staging.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def stub_bin(tmp_path):
# check_dataset_allowlist.py; generate.py is asked to create a notebook so
# the "new file this run produced" path is covered.
(bindir / "black").write_text("#!/bin/bash\nexit 0\n")
(bindir / "gh").write_text("#!/bin/bash\nexit 0\n")
# gh records each call's argv so the dispatch fields can be asserted.
(bindir / "gh").write_text(
'#!/bin/bash\nprintf "%s\\n" "$*" >> "$(dirname "$0")/gh_calls.log"\nexit 0\n'
)
stub_python = (
"#!/bin/bash\n"
'case "$*" in\n'
Expand All @@ -124,8 +127,10 @@ def stub_bin(tmp_path):
return bindir


def _run(base, stub_bin):
def _run(base, stub_bin, args=("1", "123"), extra_env=None):
env = dict(os.environ)
env.pop("REHEARSAL_RUN_ID", None)
env.update(extra_env or {})
env["PATH"] = f"{stub_bin}:{env['PATH']}"
# pre_build only runs ensure_workspace_labels.sh when gh is on PATH; it is
# stubbed, so give it a real (no-op) script to find.
Expand All @@ -136,7 +141,9 @@ def _run(base, stub_bin):
labels.chmod(0o755)

return subprocess.run(
["bash", str(base / "PyAutoHands" / "pre_build.sh")],
# Default: minor version 1, rehearsal run 123. A live release must name
# its rehearsal (M2.4) — the rehearsal tests at the bottom cover it.
["bash", str(base / "PyAutoHands" / "pre_build.sh"), *args],
capture_output=True,
text=True,
env=env,
Expand Down Expand Up @@ -260,3 +267,46 @@ def test_black_touches_only_what_is_staged(base, stub_bin):
assert _git(base / repo, "status", "--porcelain") == "", repo
reformatted = "# black" in (base / repo / "slam_pipeline" / "pipe.py").read_text()
assert reformatted == (slam == "true"), repo


# --- M2.4 (PyAutoHands#337): a release names the rehearsal it publishes -----


def _dispatches(stub_bin):
log = stub_bin / "gh_calls.log"
calls = log.read_text().splitlines() if log.exists() else []
return [c for c in calls if c.startswith("workflow run release.yml")]


def test_pre_build_refuses_without_a_rehearsal_before_touching_anything(base, stub_bin):
result = _run(base, stub_bin, args=("1",))

assert result.returncode != 0
assert "needs the rehearsal run id" in result.stderr
assert _dispatches(stub_bin) == []
for repo, *_ in SPECS:
assert "pre build" not in _git(base / repo, "log", "--oneline")


def test_pre_build_dispatches_the_named_rehearsal(base, stub_bin, tmp_path):
manifest = tmp_path / "commit_shas.json"
# Any key does: pre_build passes the manifest through; release.yml judges it.
manifest.write_text('{"lib": "' + "a" * 40 + '"}')

result = _run(base, stub_bin, args=("2", "456"),
extra_env={"COMMIT_SHAS_FILE": str(manifest)})

assert result.returncode == 0, result.stderr
(dispatch,) = _dispatches(stub_bin)
assert "minor_version=2" in dispatch
assert "rehearsal_run_id=456" in dispatch
assert "commit_shas=" in dispatch and "a" * 40 in dispatch


def test_pre_build_reads_the_rehearsal_from_the_environment(base, stub_bin):
result = _run(base, stub_bin, args=("1",), extra_env={"REHEARSAL_RUN_ID": "789"})

assert result.returncode == 0, result.stderr
(dispatch,) = _dispatches(stub_bin)
assert "rehearsal_run_id=789" in dispatch
assert "commit_shas=" not in dispatch
Loading
Loading