Skip to content

The agent that grows with you

fix(release): a fresh flip advances the head with the receipt it just wrote

ethernet36efcb8c87a2
diff --git a/scripts/releases/sequencer.py b/scripts/releases/sequencer.py
index f6de857d1a7..0a1948f0e3c 100644
--- a/scripts/releases/sequencer.py
+++ b/scripts/releases/sequencer.py
@@ -401,8 +401,10 @@ def reconcile(env: dict, *, run=output, read_head=None, advance_head=None,
for step in steps:
if "flip" in step:
record = by_version[step["flip"]]
- record["docker_manifest_digest"] = stable.publish_attempt(
- record, repository=repository, run=run, read_archive=read_archive)
+ # discover() ran before the receipt tag existed, so the record has no
+ # receipt digests yet; the advance below must check the ones just written.
+ record.update(stable.publish_attempt(
+ record, repository=repository, run=run, read_archive=read_archive))
else:
advance_head(by_version[step["advance"]])
diff --git a/scripts/releases/stable.py b/scripts/releases/stable.py
index 3d83ade119a..11f92a7fb39 100644
--- a/scripts/releases/stable.py
+++ b/scripts/releases/stable.py
@@ -939,14 +939,15 @@ def publish_release_draft(repository: str, release_id: int, tag: str, *, run=out
raise ValueError("Stable release publication did not persist")
-def publish_attempt(record: dict, *, repository: str, run=output, read_archive) -> str:
+def publish_attempt(record: dict, *, repository: str, run=output, read_archive) -> dict:
"""The one ordered publication pass, steps 1-4, each read back before the next.
Explicit publish and autopublish converge here. The manifest digest is
hashed from the attempt archive (nothing records it earlier), the receipt
tag is written, the draft is retargeted and stripped while still a draft,
- and only then does the final call make it public. Returns the Docker
- manifest digest the receipt binds, for the alias move that follows.
+ and only then does the final call make it public. Returns the two digests
+ the receipt binds (candidate manifest and Docker manifest), so the head
+ advance that follows in the same pass checks the receipt it just wrote.
"""
from scripts.releases import docker
@@ -963,7 +964,7 @@ def publish_attempt(record: dict, *, repository: str, run=output, read_archive)
release_id=record["release_id"], run=run)
edit_draft_release(repository, record["release_id"], record["tag"], record["commit"], run=run)
publish_release_draft(repository, record["release_id"], record["tag"], run=run)
- return docker_digest
+ return {"candidate_manifest_sha256": manifest_sha256, "docker_manifest_digest": docker_digest}
def complete(env: dict) -> None:
diff --git a/tests/scripts/test_release_sequencer.py b/tests/scripts/test_release_sequencer.py
index d33b5e2505e..bf51eb8375c 100644
--- a/tests/scripts/test_release_sequencer.py
+++ b/tests/scripts/test_release_sequencer.py
@@ -6,6 +6,7 @@ it; already-resolvable older green claims still make progress.
"""
import hashlib
import json
+import subprocess
import pytest
from datetime import UTC
@@ -393,11 +394,16 @@ def test_two_outstanding_attempts_are_refused_across_versions():
def _sequencer_fixture(*versions, manifest_digest, docker_digest="sha256:" + "b" * 64,
- drafts_on_claim_tag=False, skip_bundles=False):
- """Two green claims with their final tags; releases start as drafts."""
+ drafts_on_claim_tag=False, skip_bundles=False, final_tags=True):
+ """Two green claims with their final tags; releases start as drafts.
+
+ final_tags=False is a fresh green claim: no receipt tag yet, the draft on
+ the attempt ref, and one successful Stable Release run.
+ """
commit = "a" * 40
tags = {}
releases = []
+ workflow_runs = []
for index, version in enumerate(versions, start=1):
claim_tag, tag = f"rc.1-v{version}", f"v{version}"
claim_object, final_object = str(index) * 40, str(index + 2) * 40
@@ -416,9 +422,14 @@ def _sequencer_fixture(*versions, manifest_digest, docker_digest="sha256:" + "b"
"archive": f"releases/tag/{claim_tag}/",
}
tags[claim_tag] = (claim_object, commit, claim)
- tags[tag] = (final_object, commit, final)
+ if final_tags:
+ tags[tag] = (final_object, commit, final)
+ else:
+ workflow_runs.append({"id": 100 + index, "run_attempt": 1, "status": "completed",
+ "conclusion": "success", "head_branch": claim_tag,
+ "head_sha": commit})
releases.append({
- "id": index, "tag_name": claim_tag if drafts_on_claim_tag else tag,
+ "id": index, "tag_name": claim_tag if drafts_on_claim_tag or not final_tags else tag,
"draft": True, "prerelease": False, "published_at": None,
"body": "notes",
})
@@ -444,7 +455,10 @@ def _sequencer_fixture(*versions, manifest_digest, docker_digest="sha256:" + "b"
lines[-1] = f"{target}\t{ref}"
return "\n".join(lines)
if argv[:2] == ["git", "rev-parse"]:
- return tags[argv[-1].removeprefix("refs/tags/")][0]
+ name = argv[-1].removeprefix("refs/tags/")
+ if name not in tags:
+ raise subprocess.CalledProcessError(128, argv)
+ return tags[name][0]
if argv[:3] == ["git", "cat-file", "-t"]:
return "tag"
if argv[:3] == ["git", "cat-file", "-p"]:
@@ -455,7 +469,9 @@ def _sequencer_fixture(*versions, manifest_digest, docker_digest="sha256:" + "b"
return json.dumps(tags[argv[3]][2])
if "tag" in argv and "-a" in argv:
tag = argv[argv.index("-a") + 1]
- tags[tag] = (str(len(tags)) * 40, tags[claim_tag][1], tags[tag][2])
+ message = (tags[tag][2] if tag in tags
+ else json.loads(argv[argv.index("-m") + 1]))
+ tags[tag] = (str(len(tags)) * 40, argv[argv.index("-a") + 2], message)
return ""
if argv[0] == "git" and "push" in argv:
return ""
@@ -464,7 +480,7 @@ def _sequencer_fixture(*versions, manifest_digest, docker_digest="sha256:" + "b"
if argv[:4] == ["gh", "api", "--paginate", "--slurp"]:
if "/releases?" in argv[-1]:
return json.dumps([releases])
- return json.dumps([{"workflow_runs": []}])
+ return json.dumps([{"workflow_runs": workflow_runs}])
if argv[:3] == ["gh", "api", "--method"]:
release = next(row for row in releases if row["id"] == int(argv[4].rsplit("/", 1)[1]))
for _flag, value in zip(argv[5::2], argv[6::2]):
@@ -527,6 +543,42 @@ def test_reconcile_discovers_custody_flips_then_advances_oldest_first():
assert release["tag_name"] == f"v{version}" and release["draft"] is False
+def test_a_fresh_flip_advances_the_head_with_the_receipt_it_just_wrote():
+ """The normal publish: no receipt tag when discover() runs, flip and advance in one pass.
+
+ discover() records no receipt digests for a claim without its final tag, so
+ the advance must see the ones publish_attempt() just wrote. Otherwise the
+ channel advance compares the archive digest against None and every
+ first-pass publish fails after making the release public (0.21.7).
+ """
+ from scripts.releases.sequencer import reconcile
+
+ manifest_digest = hashlib.sha256(b"m").hexdigest()
+ docker_digest = "sha256:" + "c" * 64
+ tags, releases, run = _sequencer_fixture(
+ "0.21.5", manifest_digest=manifest_digest, docker_digest=docker_digest, final_tags=False)
+ assert "v0.21.5" not in tags
+ head = ["0.21.4"]
+ advanced = []
+
+ def advance(record):
+ advanced.append({key: record[key] for key in (
+ "tag", "candidate_manifest_sha256", "docker_manifest_digest")})
+ head[0] = record["version"]
+
+ steps = reconcile(
+ {"GITHUB_REPOSITORY": "example/project", "REQUESTED_VERSION": "0.21.5"},
+ run=run, read_head=lambda: head[0], advance_head=advance,
+ read_archive=lambda _key: b"m",
+ )
+
+ assert steps == [{"flip": "0.21.5"}, {"advance": "0.21.5"}]
+ assert advanced == [{"tag": "v0.21.5", "candidate_manifest_sha256": manifest_digest,
+ "docker_manifest_digest": docker_digest}]
+ assert tags["v0.21.5"][2]["candidateManifestSha256"] == manifest_digest
+ assert releases[0]["tag_name"] == "v0.21.5" and releases[0]["draft"] is False
+
+
def test_the_store_check_joins_the_pass_after_the_aliases_move(monkeypatch):
from scripts.releases import channel_releases, docker, sequencer, store
diff --git a/tests/scripts/test_stable_release.py b/tests/scripts/test_stable_release.py
index b4cf1ac6b17..b07e0694533 100644
--- a/tests/scripts/test_stable_release.py
+++ b/tests/scripts/test_stable_release.py
@@ -670,12 +670,13 @@ def test_publish_attempt_writes_the_receipt_retargets_and_copies_no_bytes(tmp_pa
requested_keys.append(key)
return manifest_bytes
- digest = stable.publish_attempt(
+ digests = stable.publish_attempt(
_publish_record(commit, tag_object, epoch=epoch),
repository="example/project", run=run, read_archive=read_archive,
)
- assert digest == docker_digest
+ assert digests == {"candidate_manifest_sha256": manifest_digest,
+ "docker_manifest_digest": docker_digest}
receipt = tag_record(subprocess.check_output(
["git", "tag", "-l", "v1.2.3", "--format=%(contents)"],
text=True, encoding="utf-8"))