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

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/release-finalize.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ jobs:
exit 0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
ref: ${{ github.sha }}
persist-credentials: false
- name: Require one configured consumer repository
shell: bash
Expand All @@ -168,6 +168,8 @@ jobs:
- name: Dispatch pineforge-release from immutable bytes
env:
GH_TOKEN: ${{ steps.app.outputs.token }}
# Read authority from the hub; the App token is target-only.
HUB_TOKEN: ${{ github.token }}
TAG: ${{ matrix.tag }}
CONSUMER: ${{ matrix.consumer }}
DELIVERY_ATTEMPT: ${{ matrix.attempt }}
Expand Down Expand Up @@ -199,7 +201,7 @@ jobs:
with:
name: release-delivery-${{ matrix.consumer }}-${{ matrix.tag }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/delivery.json
if-no-files-found: warn
if-no-files-found: error
- name: Report failed dispatch
if: ${{ failure() && !cancelled() }}
env:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/release-redeliver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
exit 0
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
ref: ${{ github.sha }}
persist-credentials: false
- name: Authorize consumer and pair before token mint
shell: bash
Expand Down Expand Up @@ -120,6 +120,12 @@ jobs:
run: |
python3 scripts/release_pipeline.py redeliver --tag "$TAG" --consumer "$CONSUMER" \
--output "$RUNNER_TEMP/redelivery.json"
- name: Preserve producing redelivery content
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: release-redelivery-${{ inputs.consumer }}-${{ inputs.tag }}-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/redelivery.json
if-no-files-found: error
- name: Report failed redelivery
if: ${{ failure() && !cancelled() }}
env:
Expand Down
333 changes: 270 additions & 63 deletions scripts/release_pipeline.py

Large diffs are not rendered by default.

322 changes: 233 additions & 89 deletions tests/test_release_binding.py

Large diffs are not rendered by default.

372 changes: 372 additions & 0 deletions tests/test_release_pipeline.py

Large diffs are not rendered by default.

94 changes: 71 additions & 23 deletions tests/test_release_redeliver.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
import release_contract as contract # noqa: E402
import release_pipeline as pipeline # noqa: E402
import release_receipts as adapter # noqa: E402
from test_release_binding import (FinalizeClient, MemoryRegistry, MemoryStore, # noqa: E402
from test_release_binding import (DELIVERY_SOURCES as SOURCE_FILES, # noqa: E402
FinalizeClient, MemoryRegistry, MemoryStore,
expected_pair_payload, fixture_manifest)

TAG = "v1.6.0"
Expand Down Expand Up @@ -87,13 +88,23 @@ def setUp(self):
self.row.update(draft=False, prerelease=False)
self.store.workflow_runs[900] = {
"id": 900, "path": ".github/workflows/release-redeliver.yml",
"head_branch": "main", "status": "completed", "conclusion": "success"}
"run_attempt": 1, "head_sha": "a" * 40,
"head_branch": "main", "status": "completed", "conclusion": "success",
"event": "workflow_dispatch", "repository": {"full_name": contract.HUB},
"head_repository": {"full_name": contract.HUB},
"actor": {"login": "release-operator"}, "run_started_at": CLOCK,
"updated_at": "2026-10-23T00:01:00Z"}
self.store.runs[900, 1] = self.store.workflow_runs[900]
self.seed = self.store.put
self.seed(self.row, contract.ASSET, self.raw)
self.store.operations.clear()
self.public = PublicHub(self.store)
self.authority = self.store
self.authority.variables = {"RELEASE_READY_CONSUMERS": ",".join(contract.ROLES),
"RELEASE_COMPUTE_FIRST_PAIR": "1.0.0"}
self.store.client = self.authority
self.target_client = artifacts.Client(token="target-app-token")
self.hub_client = object()
self.hub_client = self.authority
self.real_store = pipeline.Store
self.tokens, self.requests, self.accepted, self.puts, self.effects = [], [], [], [], []
self.fail_send = self.fail_put = False
Expand All @@ -104,7 +115,8 @@ def setUp(self):
self.start_patch(patch.dict(os.environ, {
"GH_TOKEN": "target-app-token", "HUB_TOKEN": "hub-write-token",
"TARGET_REPOSITORY": TARGET, "RELEASE_READY_CONSUMERS": CONSUMER,
"GITHUB_RUN_ID": "900", "GITHUB_ACTOR": "release-operator",
"GITHUB_RUN_ID": "900", "GITHUB_RUN_ATTEMPT": "1",
"GITHUB_SHA": "a" * 40, "GITHUB_ACTOR": "release-operator",
}, clear=True))
self.start_patch(patch.object(pipeline, "now", return_value=CLOCK))
self.start_patch(patch.object(pipeline, "Client", side_effect=self.client))
Expand Down Expand Up @@ -149,22 +161,43 @@ def put(self, row, name, raw):
if self.fail_put:
raise OSError("hub audit storage unavailable")
self.seed(row, name, raw)
if name.startswith("delivery-redelivered-"):
self.publish_audit(contract.decode(raw))

def audit(self, attempt, *, consumer=CONSUMER):
return {"schema": "pineforge/release-redelivery/v2", "event_id": self.event["event_id"],
candidate = self.store.read(self.row, contract.CANDIDATE) if consumer == "compute" else None
body = {"event_type": contract.EVENT_TYPES[consumer],
"client_payload": contract.pair_payload(self.raw, candidate) if candidate else self.event}
source_files = (*SOURCE_FILES, ".github/workflows/release-redeliver.yml")
return {"schema": "pineforge/release-redelivery/v3", "event_id": self.event["event_id"],
"consumer": consumer, "attempt": attempt, "state": "dispatch_accepted",
"run_id": 900, "dispatch_status": 204, "timestamp": CLOCK, "actor": "release-operator"}
"run_id": int(os.environ["GITHUB_RUN_ID"]), "run_attempt": 1,
"dispatch_status": 204, "timestamp": CLOCK, "actor": "release-operator",
"context": {"tag": self.row["tag_name"], "manifest_sha256": contract.sha256(self.raw),
"candidate_sha256": contract.sha256(candidate) if candidate else None,
"dispatch_sha256": contract.sha256(contract.canonical(body)),
"workflow_commit": "a" * 40,
"source_sha256": {name: contract.sha256(self.authority.sources[name])
for name in source_files}}}

def publish_audit(self, obj):
self.authority.publish_delivery(obj, tag=self.row["tag_name"])

def seed_audit(self, number, *, consumer=CONSUMER, changes=None, name=None):
obj = {**self.audit(number, consumer=consumer), **(changes or {})}
genuine = self.audit(number, consumer=consumer)
genuine["run_id"] = 700 + number
self.publish_audit(genuine)
obj = {**genuine, **(changes or {})}
name = name or f"delivery-redelivered-{consumer}-{number}.json"
self.seed(self.row, name, contract.canonical(obj))

def seed_acceptance(self):
self.seed(self.row, f"delivery-{CONSUMER}.json", contract.canonical({
obj = {
"schema": "pineforge/release-delivery/v1", "event_id": self.event["event_id"],
"consumer": CONSUMER, "attempt": 3, "state": "dispatch_accepted",
"run_id": 800, "timestamp": CLOCK}))
"run_id": 800, "timestamp": CLOCK}
self.authority.publish_delivery(obj, manual=False, tag=self.row["tag_name"])
self.seed(self.row, f"delivery-{CONSUMER}.json", contract.canonical(obj))

def receipt_body(self, state, *, consumer=CONSUMER, attempt=1, sequence=1):
# A trusted hub summary, after the existing receipt adapter verified the
Expand Down Expand Up @@ -377,8 +410,9 @@ def test_audit_records_environment_run_id_and_actual_dispatch_status(self):
with patch.dict(os.environ, {"GITHUB_RUN_ID": "9123"}):
self.invoke()
audit = contract.decode(self.output.read_bytes())
self.assertEqual(audit["schema"], "pineforge/release-redelivery/v2")
self.assertEqual(audit["schema"], "pineforge/release-redelivery/v3")
self.assertEqual(audit["run_id"], 9123)
self.assertEqual(audit["run_attempt"], 1)
self.assertEqual(audit["dispatch_status"], self.dispatch_status)
self.assertEqual(audit["dispatch_status"], 204)
self.assertEqual(self.puts, [(TAG, f"delivery-redelivered-{CONSUMER}-1.json",
Expand All @@ -403,41 +437,52 @@ def test_unconfirmed_history_refuses_before_another_dispatch(self):
"""Mutation: omit confirm_redelivery_run from redeliver's history check."""
success = self.store.workflow_runs[900]
cases = (
({**success, "path": ".github/workflows/release-finalize.yml"}, "redelivery workflow run differs"),
({**success, "head_branch": "repair"}, "redelivery workflow run differs"),
({**success, "conclusion": "failure"}, "redelivery workflow run differs"),
({**success, "status": "in_progress", "conclusion": None}, "redelivery workflow run differs"),
(None, "redelivery workflow run unavailable"),
({**success, "path": ".github/workflows/release-finalize.yml"}, "delivery producing workflow attempt differs"),
({**success, "head_branch": "repair"}, "delivery producing workflow attempt differs"),
({**success, "conclusion": "failure"}, "delivery producing workflow attempt differs"),
({**success, "status": "in_progress", "conclusion": None}, "delivery producing workflow attempt differs"),
(None, "delivery producing workflow attempt unavailable (requires Actions: read)"),
(contract.Invalid("artifact request failed (HTTP 500)"), "artifact request failed (HTTP 500)"),
)
for schema in ("pineforge/release-redelivery/v1", "pineforge/release-redelivery/v2"):
obj = {**self.audit(1), "schema": schema}
obj = {key: value for key, value in obj.items() if key not in ("run_attempt", "context")}
if schema.endswith("/v1"):
obj = {key: value for key, value in obj.items() if key != "dispatch_status"}
self.authority.artifacts.clear()
self.authority.archives.clear()
self.authority.artifact_runs.clear()
self.store.runs[900, 1] = copy.deepcopy(success)
self.store.workflow_runs[900] = self.store.runs[900, 1]
self.authority.publish_delivery(obj)
for run, message in cases:
with self.subTest(schema=schema, run=run):
before = copy.deepcopy(self.store.assets)
assets = copy.deepcopy(self.row["assets"])
self.store.workflow_runs = {} if run is None else {900: run}
self.store.runs = {} if run is None else {(900, 1): run}
self.store.run_reads.clear()
try:
self.seed(self.row, f"delivery-redelivered-{CONSUMER}-1.json", contract.canonical(obj))
self.assert_refused(message=message)
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900"])
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900/attempts/1"])
finally:
self.store.assets = before
self.row["assets"] = assets

def test_confirmed_v1_history_can_append_v2_without_rewriting_history(self):
def test_confirmed_v1_history_can_append_v3_without_rewriting_history(self):
"""Mutation: reject all legacy history instead of confirming its workflow run."""
legacy = {**self.audit(1), "schema": "pineforge/release-redelivery/v1"}
legacy = {key: value for key, value in legacy.items() if key != "dispatch_status"}
legacy = {key: value for key, value in legacy.items()
if key not in ("dispatch_status", "run_attempt", "context")}
self.publish_audit(legacy)
self.seed(self.row, f"delivery-redelivered-{CONSUMER}-1.json", contract.canonical(legacy))
before = copy.deepcopy(self.store.assets)
os.environ["GITHUB_RUN_ID"] = "901"
self.invoke()
audit = contract.canonical(self.audit(2))
name = f"delivery-redelivered-{CONSUMER}-2.json"
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900"])
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900/attempts/1"])
self.assertEqual(self.puts, [(TAG, name, audit)])
self.assertEqual(self.store.assets, {**before, (TAG, name): audit})
self.assertEqual(self.effects, ["send", "put"])
Expand Down Expand Up @@ -481,6 +526,7 @@ def test_numbers_are_contiguous_independent_of_planner_and_other_roles(self):
self.seed_audit(7, consumer="offline")
before = copy.deepcopy(self.store.assets)
for number in (2, 3, 4):
os.environ["GITHUB_RUN_ID"] = str(900 + number)
self.invoke()
self.assertEqual(self.output.read_bytes(), contract.canonical(self.audit(number)))
self.assertEqual([name for _, name, _ in self.puts],
Expand Down Expand Up @@ -628,10 +674,12 @@ def test_compute_redelivery_keeps_an_eligible_older_prerelease_pair(self):
row.update(id=2, draft=False, prerelease=False)
self.store.rows[row["tag_name"]] = row
self.seed(row, contract.ASSET, contract.canonical(newer))
self.seed(self.row, "delivery-compute.json", contract.canonical({
accepted = {
"schema": "pineforge/release-delivery/v1", "event_id": self.event["event_id"],
"consumer": "compute", "attempt": 1, "state": "dispatch_accepted",
"run_id": 800, "timestamp": CLOCK}))
"run_id": 800, "timestamp": CLOCK}
self.authority.publish_delivery(accepted, manual=False, tag=self.row["tag_name"])
self.seed(self.row, "delivery-compute.json", contract.canonical(accepted))
before = copy.deepcopy(self.store.assets)
tag = self.row["tag_name"]
with patch.dict(os.environ, {"RELEASE_READY_CONSUMERS": "compute",
Expand Down Expand Up @@ -700,7 +748,7 @@ def test_accepted_compute_repair_completes_finalization_and_preserves_exhaustion
self.assertEqual(self.store.assets, {**before, (TAG, name): audit_raw})
self.assertEqual(contract.decode(deliveries.read_bytes()), [])
self.assertFalse(report.call_args.kwargs.get("complete", False))
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900"])
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900/attempts/1"])
self.store.workflow_runs[900].update(status="completed", conclusion="success")
self.store.run_reads.clear()
report.reset_mock()
Expand All @@ -714,7 +762,7 @@ def test_accepted_compute_repair_completes_finalization_and_preserves_exhaustion
self.assertEqual(status["stale"], [])
self.assertEqual(contract.decode(deliveries.read_bytes()), [])
self.assertTrue(report.call_args.kwargs["complete"])
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900"])
self.assertEqual(self.store.run_reads, [f"repos/{contract.HUB}/actions/runs/900/attempts/1"])
for key, raw in before.items():
self.assertEqual(self.store.assets[key], raw)
self.assertFalse(any(name.startswith("consumer-") for _, name in self.store.assets))
Expand Down
34 changes: 31 additions & 3 deletions tests/test_release_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -1974,6 +1974,26 @@ def test_dispatch_requires_finalized_manifest_plan(self):
send = next(s for s in job["steps"] if s.get("name", "").startswith("Dispatch pineforge-release"))
self.assertIn("release_pipeline.py dispatch", send["run"])
self.assertNotIn("client_payload[", send["run"])
checkout = next(s for s in job["steps"] if s.get("uses", "").startswith("actions/checkout@"))
self.assertEqual(checkout["with"], {"ref": "${{ github.sha }}", "persist-credentials": "false"})
self.assertEqual(send["env"], {
"GH_TOKEN": "${{ steps.app.outputs.token }}", "HUB_TOKEN": "${{ github.token }}",
"TAG": "${{ matrix.tag }}", "CONSUMER": "${{ matrix.consumer }}",
"DELIVERY_ATTEMPT": "${{ matrix.attempt }}",
})
receipt = next(s for s in job["steps"] if s.get("name") == "Preserve delivery receipt")
self.assertEqual(receipt["env"]["GH_TOKEN"], "${{ github.token }}")
artifact = next(s for s in job["steps"] if s.get("name") == "Preserve this delivery attempt")
self.assertEqual(artifact["uses"],
"actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9")
self.assertEqual(artifact["if"], "${{ !cancelled() }}")
self.assertEqual(artifact["with"], {
"name": "release-delivery-${{ matrix.consumer }}-${{ matrix.tag }}-${{ github.run_id }}-${{ github.run_attempt }}",
"path": "${{ runner.temp }}/delivery.json", "if-no-files-found": "error",
})
self.assertLess(job["steps"].index(checkout), job["steps"].index(send))
self.assertLess(job["steps"].index(send), job["steps"].index(receipt))
self.assertLess(job["steps"].index(receipt), job["steps"].index(artifact))

def test_all_consumer_roles_have_explicit_registry_and_policy(self):
import release_contract as contract
Expand Down Expand Up @@ -2350,12 +2370,13 @@ def test_one_target_app_scope_public_reads_and_hub_audit_token(self):
self.assertEqual(target, sibling["env"]["TARGET_REPOSITORY"].replace("matrix.consumer", "inputs.consumer"))
steps = job["steps"]
self.assertEqual(steps[0], ReleaseTriggerWorkflowTest.APT_GUARD_STEP)
self.assertEqual(len([step for step in steps if "uses" in step]), 2)
self.assertEqual(len([step for step in steps if "uses" in step]), 3)
actions = {step["uses"]: step for step in steps if "uses" in step}
checkout = "actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1"
mint = "actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510"
self.assertEqual(set(actions), {checkout, mint})
self.assertEqual(actions[checkout]["with"], {"ref": "main", "persist-credentials": "false"})
upload = "actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9"
self.assertEqual(set(actions), {checkout, mint, upload})
self.assertEqual(actions[checkout]["with"], {"ref": "${{ github.sha }}", "persist-credentials": "false"})
self.assertEqual(actions[mint]["with"], {
"app-id": "${{ secrets.PINEFORGE_APP_ID }}",
"private-key": "${{ secrets.PINEFORGE_APP_PRIVATE_KEY }}",
Expand Down Expand Up @@ -2385,6 +2406,13 @@ def test_one_target_app_scope_public_reads_and_hub_audit_token(self):
self.assertEqual(sends[0]["run"],
'python3 scripts/release_pipeline.py redeliver --tag "$TAG" --consumer "$CONSUMER" \\\n'
' --output "$RUNNER_TEMP/redelivery.json"\n')
self.assertEqual(actions[upload]["with"], {
"name": "release-redelivery-${{ inputs.consumer }}-${{ inputs.tag }}-${{ github.run_id }}-${{ github.run_attempt }}",
"path": "${{ runner.temp }}/redelivery.json", "if-no-files-found": "error",
})
self.assertLess(steps.index(sends[0]), steps.index(actions[upload]))
self.assertNotIn("env", actions[upload])
self.assertNotIn("continue-on-error", actions[upload])
self.assertNotIn("release_receipts.py", str(steps))
self.assertNotIn("client_payload", str(steps))

Expand Down
Loading