Merge pull request 'fix(ci): continue interrupted releases without replacing assets' (#115) from fix/release-resume-20261107 into main
CI / UI Checks (push) Successful in 10s
CI / Rust Checks (push) Successful in 33m36s
CI / Rust Feature Validation (push) Skipped
CI / Frontend E2E (push) Skipped
CI / Community Image Smoke (push) Skipped
CI / Required Checks (push) Successful in 1s
CI / Deploy (push) Skipped

fix(ci): safely resume incomplete immutable releases
This commit was merged in pull request #115.
This commit is contained in:
bsodfather committed 2026-11-07 14:49:41 +00:00
commit 27f86d4916
3 files changed
+547 -7

No files matched your search

+61 -7
View File
@@ -12,10 +12,20 @@ on:
options: [story, feature]
default: story
required: true
resume_tag:
description: Existing draft release tag to resume with image-only steps
type: string
default: ""
required: false
resume_source_sha:
description: Exact accepted source commit SHA for the resume tag
type: string
default: ""
required: false
env:
REGISTRY: git.itexp.me
IMAGE_TAG: ${{ gitea.ref_name }}
IMAGE_TAG: ${{ inputs.resume_tag || gitea.ref_name }}
ADMIN_API_IMAGE: git.itexp.me/bsodfather/crank-community-admin-api
MCP_SERVER_IMAGE: git.itexp.me/bsodfather/crank-community-mcp-server
UI_IMAGE: git.itexp.me/bsodfather/crank-community-ui
@@ -31,12 +41,37 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
fetch-depth: 0
- name: Verify existing release before resume
id: resume
if: inputs.resume_tag != ''
env:
GITEA_SERVER_URL: https://git.itexp.me
GITEA_REPOSITORY: ${{ gitea.repository }}
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
RELEASE_TAG: ${{ inputs.resume_tag }}
RESUME_SOURCE_SHA: ${{ inputs.resume_source_sha }}
run: python3 scripts/ci-release-resume.py
- name: Checkout validated release source
if: inputs.resume_tag != ''
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
ref: ${{ steps.resume.outputs.release_tag }}
fetch-depth: 0
- name: Assert exact release source checkout
if: inputs.resume_tag != ''
env:
EXPECTED_SOURCE_SHA: ${{ steps.resume.outputs.source_sha }}
run: test "$(git rev-parse HEAD)" = "$EXPECTED_SOURCE_SHA"
- name: Clear optional release evidence
if: inputs.resume_tag == ''
run: rm -f .tmp/openapi-playwright.json .tmp/openapi-ui-evidence.json
- name: Use preinstalled Rust toolchain
if: inputs.resume_tag == ''
run: |
set -eu
toolchain_dir="${RUSTUP_HOME:-$HOME/.rustup}/toolchains/1.96.1-x86_64-unknown-linux-gnu"
@@ -54,6 +89,7 @@ jobs:
"$toolchain_bin/cargo-clippy" --version
- name: Verify runner toolchain
if: inputs.resume_tag == ''
run: |
python3 --version
rustc --version
@@ -65,19 +101,23 @@ jobs:
bao version
- name: Install dependency policy tool
if: inputs.resume_tag == ''
run: cargo install cargo-deny --version 0.20.2 --locked
- name: Check formatting
if: inputs.resume_tag == ''
run: cargo fmt --all --check
- name: Audit Rust dependencies
if: inputs.resume_tag == ''
run: cargo deny --locked check advisories bans licenses sources
- name: Run tooling unit tests
if: inputs.validation_level == 'feature'
if: inputs.resume_tag == '' && inputs.validation_level == 'feature'
run: python3 -m unittest discover -s tests/unit
- name: Check typed runtime configuration contract
if: inputs.resume_tag == ''
run: |
cargo run -p crank-config --bin crank-config-contract -- --check
python3 scripts/check-runtime-config.py --root .
@@ -85,14 +125,17 @@ jobs:
scripts/check-rust-boundaries.sh
- name: Check canonical migration contract
if: inputs.resume_tag == ''
run: cargo run -p admin-api --bin crank-migrate -- plan --check
- name: Check typed metrics contract
if: inputs.resume_tag == ''
run: |
cargo run -p crank-metrics --bin crank-metrics-contract -- --check
python3 scripts/check-metrics-boundaries.py --root .
- name: Check Capability Inventory
if: inputs.resume_tag == ''
run: |
required_args=""
for number in $(seq 1 54); do
@@ -105,6 +148,7 @@ jobs:
$required_args
- name: Check Capability Baseline
if: inputs.resume_tag == ''
run: |
python3 scripts/validate-capability-baseline.py \
--root . \
@@ -112,40 +156,46 @@ jobs:
--schema docs/schemas/capability-baseline.schema.json
- name: Check Community scope
if: inputs.resume_tag == ''
run: scripts/check-community-scope.sh
- name: Run Crank story ATDD
if: inputs.resume_tag == ''
run: scripts/ci-story-checks.sh
- name: Run release quality gates
if: inputs.validation_level == 'feature'
if: inputs.resume_tag == '' && inputs.validation_level == 'feature'
run: |
cargo clippy --workspace --all-targets --all-features -- -D warnings
cargo test --workspace --all-targets -- --test-threads=1
- name: Build release binaries
if: inputs.resume_tag == ''
run: cargo build --release -p admin-api -p mcp-server
- name: Install UI dependencies
if: inputs.resume_tag == ''
working-directory: apps/ui
run: npm ci
- name: Audit UI dependencies
if: inputs.resume_tag == ''
working-directory: apps/ui
run: npm audit --audit-level=high
- name: Build UI dist
if: inputs.resume_tag == ''
working-directory: apps/ui
run: npm run build
- name: Install Playwright browser
if: inputs.validation_level == 'feature'
if: inputs.resume_tag == '' && inputs.validation_level == 'feature'
working-directory: apps/ui
run: npx playwright install --with-deps chromium
- name: Run release end-to-end tests
if: inputs.validation_level == 'feature'
if: inputs.resume_tag == '' && inputs.validation_level == 'feature'
working-directory: apps/ui
run: |
mkdir -p ../../.tmp
@@ -153,7 +203,7 @@ jobs:
PLAYWRIGHT_JSON_OUTPUT=../../.tmp/openapi-playwright.json npm run e2e
- name: Collect sanitized OpenAPI UI release evidence
if: inputs.validation_level == 'feature'
if: inputs.resume_tag == '' && inputs.validation_level == 'feature'
working-directory: apps/ui
run: |
trap 'rm -f ../../.tmp/openapi-playwright.json' EXIT
@@ -175,12 +225,14 @@ jobs:
--require-accepted
- name: Validate deployment manifests
if: inputs.resume_tag == ''
run: |
docker compose -f docker-compose.yml --env-file .env.example config -q
docker compose -f deploy/community/docker-compose.yml --env-file deploy/community/.env.example config -q
docker compose -f deploy/community/docker-compose.images.yml --env-file deploy/community/.env.images.example --profile local-db config -q
- name: Package release artifacts
if: inputs.resume_tag == ''
run: |
set -euo pipefail
mkdir -p dist/release
@@ -204,13 +256,14 @@ jobs:
sha256sum "${files[@]}" > "dist/crank-community-${IMAGE_TAG}-checksums.txt"
- name: Generate SBOM
if: inputs.resume_tag == ''
run: |
docker run --rm -v "$PWD:/workspace" anchore/syft:latest \
dir:/workspace -o spdx-json \
> dist/crank-community-${IMAGE_TAG}-sbom.spdx.json
- name: Publish release bundles, checksums, evidence, and SBOM to Gitea
if: startsWith(gitea.ref, 'refs/tags/v')
if: inputs.resume_tag == '' && startsWith(gitea.ref, 'refs/tags/v')
env:
# gitea.server_url inside the job container is the internal http://gitea:3000 origin;
# the publisher only forwards its token to the public HTTPS origin.
@@ -297,5 +350,6 @@ jobs:
docker push '${{ env.UI_IMAGE }}:latest'
- name: Show release bundle summary
if: inputs.resume_tag == ''
run: |
ls -lh dist
+267
View File
@@ -0,0 +1,267 @@
#!/usr/bin/env python3
"""Validate an existing draft release before resuming its image build."""
from __future__ import annotations
import hashlib
import importlib.util
import os
import re
import subprocess
import sys
from pathlib import Path
from urllib.error import HTTPError, URLError
from urllib.parse import quote, urlsplit
from urllib.request import Request, build_opener
_HERE = Path(__file__).resolve().parent
_ASSETS_SCRIPT = _HERE / "ci-release-assets.py"
_spec = importlib.util.spec_from_file_location("ci_release_assets", _ASSETS_SCRIPT)
if _spec is None or _spec.loader is None:
raise RuntimeError("Could not load release asset helpers")
_assets_module = importlib.util.module_from_spec(_spec)
sys.modules[_spec.name] = _assets_module
_spec.loader.exec_module(_assets_module)
PublishError = _assets_module.PublishError
_NoRedirect = _assets_module._NoRedirect
_assets = _assets_module._assets
_inputs = _assets_module._inputs
_json_request = _assets_module._json_request
_COMMIT = re.compile(r"[0-9a-fA-F]{40}\Z")
_ARCHIVES = re.compile(r"crank-community-(?:admin-api|mcp-server|ui)-.+\.tar\.gz\Z")
_MAX_ASSET_SIZE = 512 * 1024 * 1024
_MAX_TOTAL_SIZE = 1024 * 1024 * 1024
_REQUIRED_SOURCE_STATUSES = (
"CI / Required Checks (push)",
"CI / Rust Checks (push)",
"CI / UI Checks (push)",
)
def _fail(message: str) -> None:
raise PublishError(message)
def _git(*args: str) -> str:
try:
result = subprocess.run(
["git", *args], check=False, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, text=True,
)
except OSError:
_fail("Could not inspect checked out Git history")
if result.returncode:
_fail("Resume source tag is unavailable or is not based on checked out main")
return result.stdout.strip()
def _check_source(tag: str, source_sha: str, env: dict[str, str]) -> None:
if env.get("GITHUB_EVENT_NAME") != "workflow_dispatch" or env.get("GITHUB_REF") != "refs/heads/main":
_fail("Resume is allowed only for manual dispatches from main")
if not _COMMIT.fullmatch(source_sha):
_fail("RESUME_SOURCE_SHA must be an exact 40-character commit SHA")
tag_sha = _git("rev-parse", "--verify", f"refs/tags/{tag}^{{commit}}")
if tag_sha.lower() != source_sha.lower():
_fail("Release tag does not point to the requested source commit")
try:
result = subprocess.run(
["git", "merge-base", "--is-ancestor", tag_sha, "HEAD"],
check=False, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
)
except OSError:
_fail("Could not verify release source ancestry")
if result.returncode:
_fail("Release source is not an ancestor of checked out main")
def _api_tag_commit(api: str, tag: str, token: str, opener) -> str:
result, status = _json_request(
opener, "GET", f"{api}/tags/{quote(tag, safe='')}", token
)
if status != 200 or not isinstance(result, dict) or result.get("name") != tag:
_fail("Gitea did not return the requested tag")
commit = result.get("commit")
if not isinstance(commit, dict) or not isinstance(commit.get("sha"), str):
_fail("Gitea returned a malformed tag commit")
return commit["sha"]
def _download(origin: str, item: dict, token: str, opener) -> bytes:
url = urlsplit(item["browser_download_url"])
trusted = urlsplit(origin)
if (
url.scheme != "https" or url.netloc != trusted.netloc
or url.username or url.password or url.fragment or not url.path.startswith("/")
):
_fail(f"Release asset {item['name']} has an untrusted download URL")
size = item["size"]
if size < 0 or size > _MAX_ASSET_SIZE:
_fail(f"Release asset {item['name']} exceeds the download size limit")
request = Request(item["browser_download_url"], headers={"Authorization": f"token {token}"})
chunks: list[bytes] = []
total = 0
try:
with opener.open(request, timeout=30) as response:
while True:
chunk = response.read(min(1024 * 1024, size + 1 - total))
if not chunk:
break
total += len(chunk)
if total > size:
_fail(f"Release asset {item['name']} size does not match Gitea metadata")
chunks.append(chunk)
except PublishError:
raise
except HTTPError as exc:
status = exc.code
exc.close()
_fail(f"Could not download release asset (HTTP {status})")
except (URLError, TimeoutError, OSError):
_fail("Could not download release asset or request timed out")
if total != size:
_fail(f"Release asset {item['name']} size does not match Gitea metadata")
return b"".join(chunks)
def _sha_manifest(data: bytes, expected: set[str]) -> dict[str, str]:
try:
lines = data.decode("utf-8").splitlines()
except UnicodeDecodeError:
_fail("SHA256SUMS is not valid UTF-8")
parsed: dict[str, str] = {}
for line in lines:
match = re.fullmatch(r"([0-9a-fA-F]{64}) [ *](?:dist/)?([^\s/\\]+)", line)
if not match or match.group(2) in parsed:
_fail("SHA256SUMS has an invalid or duplicate entry")
parsed[match.group(2)] = match.group(1).lower()
if set(parsed) != expected:
_fail("SHA256SUMS does not cover exactly all release payload assets")
return parsed
def _verify_payloads(payload: dict[str, bytes], manifest_data: bytes, tag: str) -> dict[str, str]:
archives = sorted(name for name in payload if _ARCHIVES.fullmatch(name))
checksums = [name for name in payload if name.endswith("-checksums.txt")]
sboms = [name for name in payload if name.endswith("-sbom.spdx.json")]
expected_archives = {
f"crank-community-admin-api-{tag}.tar.gz",
f"crank-community-mcp-server-{tag}.tar.gz",
f"crank-community-ui-{tag}.tar.gz",
}
if (
set(archives) != expected_archives
or checksums != [f"crank-community-{tag}-checksums.txt"]
or sboms != [f"crank-community-{tag}-sbom.spdx.json"]
):
_fail("Draft release is missing an expected archive, checksums file, or SBOM")
if len(payload) != 5:
_fail("Draft release contains an unexpected payload asset set")
manifest = _sha_manifest(manifest_data, set(payload))
hashes = {name: hashlib.sha256(data).hexdigest() for name, data in payload.items()}
if any(manifest[name] != digest for name, digest in hashes.items()):
_fail("SHA256SUMS does not match a release payload asset")
try:
checksum_lines = payload[checksums[0]].decode("utf-8").splitlines()
except UnicodeDecodeError:
_fail("Release checksums file is not valid UTF-8")
checksum_entries: dict[str, str] = {}
for line in checksum_lines:
match = re.fullmatch(r"([0-9a-fA-F]{64}) [ *](?:dist/)?([^\s/\\]+)", line)
if not match or match.group(2) in checksum_entries:
_fail("Release checksums file has an invalid or duplicate entry")
checksum_entries[match.group(2)] = match.group(1).lower()
if set(checksum_entries) != set(archives) or any(
checksum_entries[name] != hashlib.sha256(payload[name]).hexdigest() for name in archives
):
_fail("Release checksums file does not match all three release archives")
return hashes
def _require_source_ci(status_data: object, status_code: int) -> None:
if status_code != 200 or not isinstance(status_data, dict):
_fail("Could not read required source CI statuses")
statuses = status_data.get("statuses")
if not isinstance(statuses, list):
_fail("Gitea did not return source CI status records")
for context in _REQUIRED_SOURCE_STATUSES:
matches = [
item for item in statuses
if isinstance(item, dict) and item.get("context") == context
]
if not matches:
_fail(f"Required source CI status is missing: {context}")
if any(not isinstance(item.get("updated_at"), str) for item in matches):
_fail(f"Required source CI status has invalid timestamp: {context}")
latest = max(matches, key=lambda item: item["updated_at"])
if latest.get("status") != "success":
_fail(f"Required source CI status is not successful: {context}")
def verify(env=None, opener=None) -> dict[str, object]:
env = os.environ if env is None else env
origin, api, tag, token = _inputs(env)
source_sha = env.get("RESUME_SOURCE_SHA", "")
_check_source(tag, source_sha, env)
opener = opener or build_opener(_NoRedirect())
release, status = _json_request(
opener, "GET", f"{api}/releases/tags/{quote(tag, safe='')}", token, allow_404=True
)
if status == 404 or not isinstance(release, dict):
_fail("The requested release does not already exist")
release_id = release.get("id")
if (
release.get("tag_name") != tag or release.get("draft") is not True
or not isinstance(release_id, int) or release_id <= 0
):
_fail("The requested release is not the expected existing draft")
if _api_tag_commit(api, tag, token, opener).lower() != source_sha.lower():
_fail("Gitea tag does not point to the requested source commit")
status_data, status_code = _json_request(
opener, "GET", f"{api}/commits/{source_sha}/status", token
)
_require_source_ci(status_data, status_code)
existing = _assets(api, release_id, token, opener)
if len(existing) != 6:
_fail("Draft release must contain exactly the five expected payloads and SHA256SUMS")
sums_names = [name for name in existing if name == "SHA256SUMS"]
if len(sums_names) != 1:
_fail("Draft release must contain one canonical SHA256SUMS asset")
if sum(item["size"] for item in existing.values()) > _MAX_TOTAL_SIZE:
_fail("Draft release payload exceeds the total download size limit")
payload: dict[str, bytes] = {}
for name, item in existing.items():
payload[name] = _download(origin, item, token, opener)
if "SHA256SUMS" not in payload:
_fail("Draft release must contain one canonical SHA256SUMS asset")
sums = payload.pop("SHA256SUMS")
hashes = _verify_payloads(payload, sums, tag)
return {
"tag": tag,
"release_id": release_id,
"source_sha": source_sha.lower(),
"assets": hashes,
}
def main() -> int:
try:
result = verify()
except PublishError as exc:
print(f"Gitea release resume: {exc}", file=sys.stderr)
return 1
output = os.environ.get("GITHUB_OUTPUT")
if not output:
print("GITHUB_OUTPUT is unavailable", file=sys.stderr)
return 1
with open(output, "a", encoding="utf-8") as target:
target.write(f"release_id={result['release_id']}\n")
target.write(f"source_sha={result['source_sha']}\n")
target.write(f"release_tag={result['tag']}\n")
print(f"Validated existing draft {result['tag']} (id {result['release_id']}) and source CI")
return 0
if __name__ == "__main__":
raise SystemExit(main())
+219
View File
@@ -0,0 +1,219 @@
from __future__ import annotations
import hashlib
import importlib.util
import unittest
from pathlib import Path
from unittest.mock import patch
ROOT = Path(__file__).resolve().parents[2]
SCRIPT = ROOT / "scripts" / "ci-release-resume.py"
spec = importlib.util.spec_from_file_location("ci_release_resume", SCRIPT)
assert spec and spec.loader
resume = importlib.util.module_from_spec(spec)
spec.loader.exec_module(resume)
TAG = "v0.4.0-rc.15"
SHA = "29ee01b6efced04b027569fbeed2e865991c8f55"
FILES = {
f"crank-community-admin-api-{TAG}.tar.gz": b"admin archive",
f"crank-community-mcp-server-{TAG}.tar.gz": b"mcp archive",
f"crank-community-ui-{TAG}.tar.gz": b"ui archive",
f"crank-community-{TAG}-checksums.txt": b"",
f"crank-community-{TAG}-sbom.spdx.json": b"{}",
}
def payloads():
files = dict(FILES)
archives = [name for name in files if name.endswith(".tar.gz")]
files[f"crank-community-{TAG}-checksums.txt"] = "".join(
f"{hashlib.sha256(files[name]).hexdigest()} dist/{name}\n" for name in archives
).encode()
manifest = "".join(
f"{hashlib.sha256(data).hexdigest()} {name}\n" for name, data in files.items()
).encode()
return files, manifest
class ResumeValidationTests(unittest.TestCase):
def setUp(self):
self.env = {
"GITEA_SERVER_URL": "https://git.itexp.me",
"GITEA_REPOSITORY": "bsodfather/crank-community",
"GITEA_TOKEN": "test-token",
"RELEASE_TAG": TAG,
"RESUME_SOURCE_SHA": SHA,
"GITHUB_EVENT_NAME": "workflow_dispatch",
"GITHUB_REF": "refs/heads/main",
}
self.files, self.manifest = payloads()
self.calls = []
def api(self, _opener, method, url, token, payload=None, allow_404=False):
self.calls.append((method, url, payload))
if url.endswith("/releases/tags/" + TAG):
return ({"id": 426, "tag_name": TAG, "draft": True}, 200)
if url.endswith("/tags/" + TAG):
return ({"name": TAG, "commit": {"sha": SHA}}, 200)
if url.endswith("/commits/" + SHA + "/status"):
contexts = {"CI / Required Checks (push)", "CI / Rust Checks (push)", "CI / UI Checks (push)"}
return ({
"state": "failure",
"statuses": [
{"context": context, "status": "success", "updated_at": "2026-11-07T10:00:00Z"}
for context in contexts
] + [
{"context": "Community Release (push)", "status": "failure", "updated_at": "2026-11-07T10:01:00Z"}
],
}, 200)
raise AssertionError(f"Unexpected API URL: {url}")
def assets(self, _api, release_id, token, opener):
self.assertEqual(release_id, 426)
result = {}
for name, data in {**self.files, "SHA256SUMS": self.manifest}.items():
result[name] = {"name": name, "id": len(result) + 1, "size": len(data),
"browser_download_url": f"https://git.itexp.me/releases/download/{name}"}
return result
def download(self, origin, item, token, opener):
self.assertEqual(origin, "https://git.itexp.me")
return self.files.get(item["name"], self.manifest)
def run_verify(self):
with (
patch.object(resume, "_inputs", return_value=("https://git.itexp.me", "https://git.itexp.me/api/v1/repos/bsodfather/crank-community", TAG, "test-token")),
patch.object(resume, "_check_source") as check_source,
patch.object(resume, "_json_request", side_effect=self.api),
patch.object(resume, "_assets", side_effect=self.assets),
patch.object(resume, "_download", side_effect=self.download),
):
result = resume.verify(self.env, opener=object())
check_source.assert_called_once_with(TAG, SHA, self.env)
return result
def test_valid_draft_is_read_only_and_outputs_source_receipt(self):
result = self.run_verify()
self.assertEqual(result["release_id"], 426)
self.assertEqual(result["source_sha"], SHA)
self.assertEqual(set(result["assets"]), set(self.files))
self.assertTrue(self.calls)
self.assertTrue(all(call[0] == "GET" and call[2] is None for call in self.calls))
def test_missing_release_rejected(self):
with patch.object(resume, "_inputs", return_value=("https://git.itexp.me", "https://api", TAG, "token")), \
patch.object(resume, "_check_source"), \
patch.object(resume, "_json_request", return_value=(None, 404)):
with self.assertRaisesRegex(resume.PublishError, "does not already exist"):
resume.verify(self.env, opener=object())
def test_source_mismatch_rejected_before_api(self):
with patch.object(resume, "_inputs", return_value=("https://git.itexp.me", "https://api", TAG, "token")), \
patch.object(resume, "_check_source", side_effect=resume.PublishError("tag mismatch")), \
patch.object(resume, "_json_request") as request:
with self.assertRaisesRegex(resume.PublishError, "tag mismatch"):
resume.verify(self.env, opener=object())
request.assert_not_called()
def test_api_tag_commit_mismatch_rejected(self):
with patch.object(resume, "_inputs", return_value=("https://git.itexp.me", "https://api", TAG, "token")), \
patch.object(resume, "_check_source"), \
patch.object(resume, "_json_request", side_effect=self.api), \
patch.object(resume, "_api_tag_commit", return_value="0" * 40):
with self.assertRaisesRegex(resume.PublishError, "Gitea tag does not point"):
resume.verify(self.env, opener=object())
def test_unexpected_asset_set_rejected_before_download(self):
assets = self.assets(None, 426, "token", None)
assets["unexpected.txt"] = {
"name": "unexpected.txt", "id": 99, "size": 0,
"browser_download_url": "https://git.itexp.me/unexpected.txt",
}
with patch.object(resume, "_inputs", return_value=("https://git.itexp.me", "https://api", TAG, "token")), \
patch.object(resume, "_check_source"), \
patch.object(resume, "_json_request", side_effect=self.api), \
patch.object(resume, "_api_tag_commit", return_value=SHA), \
patch.object(resume, "_assets", return_value=assets), \
patch.object(resume, "_download") as download:
with self.assertRaisesRegex(resume.PublishError, "exactly the five expected"):
resume.verify(self.env, opener=object())
download.assert_not_called()
def test_required_source_status_missing_or_failed_is_rejected(self):
cases = (
{"state": "failure", "statuses": []},
{"state": "failure", "statuses": [
{"context": "CI / Required Checks (push)", "status": "failure", "updated_at": "2026-11-07T10:00:00Z"},
{"context": "CI / Rust Checks (push)", "status": "success", "updated_at": "2026-11-07T10:00:00Z"},
{"context": "CI / UI Checks (push)", "status": "success", "updated_at": "2026-11-07T10:00:00Z"},
]},
{"state": "failure", "statuses": [
{"context": "CI / Required Checks (push)", "status": "success", "updated_at": "2026-11-07T09:00:00Z"},
{"context": "CI / Required Checks (push)", "status": "failure", "updated_at": "2026-11-07T10:00:00Z"},
{"context": "CI / Rust Checks (push)", "status": "success", "updated_at": "2026-11-07T10:00:00Z"},
{"context": "CI / UI Checks (push)", "status": "success", "updated_at": "2026-11-07T10:00:00Z"},
]},
)
for status_data in cases:
with self.subTest(status_data=status_data):
with self.assertRaises(resume.PublishError):
resume._require_source_ci(status_data, 200)
def test_missing_expected_asset_rejected(self):
files = dict(self.files)
files.pop(f"crank-community-{TAG}-sbom.spdx.json")
with self.assertRaisesRegex(resume.PublishError, "missing an expected"):
resume._verify_payloads(files, self.manifest, TAG)
def test_checksum_manifest_rejects_missing_or_bad_payload_entries(self):
for manifest in (b"", b"0" * 64 + b" wrong.tar.gz\n"):
with self.subTest(manifest=manifest):
with self.assertRaises(resume.PublishError):
resume._verify_payloads(self.files, manifest, TAG)
def test_checksum_manifest_rejects_mismatched_archive_checksum(self):
files = dict(self.files)
checksum_name = f"crank-community-{TAG}-checksums.txt"
files[checksum_name] = b"0" * 64 + b" crank-community-admin-api-" + TAG.encode() + b".tar.gz\n"
updated_manifest = "".join(
f"{hashlib.sha256(data).hexdigest()} {name}\n" for name, data in files.items()
).encode()
with self.assertRaisesRegex(resume.PublishError, "checksums file"):
resume._verify_payloads(files, updated_manifest, TAG)
def test_download_rejects_untrusted_origin_before_network(self):
item = {"name": "payload", "size": 1, "browser_download_url": "https://evil.example/payload"}
opener = unittest.mock.Mock()
with self.assertRaisesRegex(resume.PublishError, "untrusted download URL"):
resume._download("https://git.itexp.me", item, "token", opener)
opener.open.assert_not_called()
def test_download_rejects_redirect_without_following(self):
class Redirecting:
def open(self, request, timeout):
raise resume.PublishError("redirect refused")
item = {"name": "payload", "size": 1, "browser_download_url": "https://git.itexp.me/payload"}
with self.assertRaisesRegex(resume.PublishError, "redirect refused"):
resume._download("https://git.itexp.me", item, "token", Redirecting())
class WorkflowResumeTests(unittest.TestCase):
def test_resume_selects_tag_source_and_skips_asset_production(self):
workflow = (ROOT / ".gitea/workflows/release.yml").read_text()
self.assertIn("resume_tag:", workflow)
self.assertIn("resume_source_sha:", workflow)
self.assertIn("IMAGE_TAG: ${{ inputs.resume_tag || gitea.ref_name }}", workflow)
self.assertIn("python3 scripts/ci-release-resume.py", workflow)
self.assertIn("ref: ${{ steps.resume.outputs.release_tag }}", workflow)
self.assertIn('test "$(git rev-parse HEAD)" = "$EXPECTED_SOURCE_SHA"', workflow)
for step in ("Build release binaries", "Build UI dist", "Package release artifacts", "Generate SBOM"):
start = workflow.index(f"- name: {step}")
self.assertIn("if: inputs.resume_tag == ''", workflow[start : start + 180])
self.assertIn("if: inputs.resume_tag == '' && startsWith(gitea.ref, 'refs/tags/v')", workflow)
self.assertIn("if: inputs.resume_tag == ''\n run: |\n ls -lh dist", workflow)
if __name__ == "__main__":
unittest.main()