Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 0 additions & 5 deletions .github/mac-release-pipeline.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
{
"engine": {
"version": "v0.9.2-omarchy.50",
"url": "https://github.com/omacom/omarchy-mac-installer/releases/download/engine-v0.9.2-omarchy.50/installer-v0.9.2-omarchy.50.tar.gz",
"fileName": "installer-v0.9.2-omarchy.50.tar.gz",
"sizeBytes": 18037588,
"sha256": "313f91571422170094a8fa1ac65fb24002d708bba86f7a2dbfe4821f89b12e6e",
"downstreamRevision": "6b644750fa3165d47838892cdbc46801cfe75018"
},
"installer": {
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/mac-catalog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ on:
type: string
required: true
installer:
description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; required for engines from v0.9.2-omarchy.18
description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; minimumVersion at least 2.1.0
type: string
default: ''
required: true
channel:
description: Channel to publish (edge only until promotion is unparked)
type: string
Expand Down Expand Up @@ -84,9 +84,9 @@ on:
type: string
required: true
installer:
description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; required for engines from v0.9.2-omarchy.18
description: App compatibility as JSON {minimumVersion, latestVersion, downloadURL}; minimumVersion at least 2.1.0
type: string
default: ''
required: true
channel:
description: Channel to publish
type: choice
Expand Down Expand Up @@ -140,7 +140,7 @@ jobs:
printf '%s\n' "$ENGINE" >"$inputs/engine.json"
printf '%s\n' "$INSTALLER_DATA" >"$inputs/installer-data.json"
printf '%s\n' "$EVIDENCE" >"$inputs/evidence.json"
[[ -z $INSTALLER ]] || printf '%s\n' "$INSTALLER" >"$inputs/installer.json"
printf '%s\n' "$INSTALLER" >"$inputs/installer.json"
{
git rev-parse HEAD
openssl version
Expand All @@ -156,13 +156,11 @@ jobs:
run: |
set -euo pipefail
inputs=$RUNNER_TEMP/catalog-inputs
installer=()
[[ ! -f $inputs/installer.json ]] || installer=(--installer "$inputs/installer.json")
python3 scripts/catalog_release.py prepare \
--channel "$(<"$inputs/channel")" --image "$(<"$inputs/image")" \
--payload "$inputs/payload.json" --engine "$inputs/engine.json" \
--installer-data "$inputs/installer-data.json" --evidence "$inputs/evidence.json" \
"${installer[@]}" --verify-remote --check-live --host github-release \
--installer "$inputs/installer.json" --verify-remote --check-live --host github-release \
--out "$inputs" | tee "$inputs/prepare.log"
echo "catalog-sha256=$(sed -n 's/^catalog_sha256=//p' "$inputs/prepare.log")" >>"$GITHUB_OUTPUT"
{
Expand Down
17 changes: 11 additions & 6 deletions .github/workflows/mac-release-pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ name: Mac release pipeline
# Namespace's Apple-backed Linux ARM64 runner).
# Writes the evidence record, attests it when it passed, and
# fails unless it passed.
# catalog-inputs the engine and app blocks from .github/mac-release-pipeline.json;
# catalog-inputs the engine pinned in Engine/source-lock.json and the app
# block from .github/mac-release-pipeline.json;
# a real run without an app release stops here, before anything
# is public
# upload mac-upload.yml, only after passing evidence: in the publish
Expand Down Expand Up @@ -147,21 +148,25 @@ jobs:
echo "::error::$config names no app release (installer); set it to a published app release (mac-app-release.yml) before a catalog can be signed"
exit 1
fi
# The catalog's own checks, so a malformed block stops here too.
python3 -I - "$config" <<'PY'
# The engine is the one Engine/source-lock.json pins; the config adds
# only its downstreamRevision. The catalog's own checks run on both
# blocks, so a malformed one stops here too.
engine=$(python3 -I - "$config" <<'PY'
import importlib.util, json, sys
spec = importlib.util.spec_from_file_location("catalog_release", "scripts/catalog_release.py")
release = importlib.util.module_from_spec(spec)
spec.loader.exec_module(release)
config = json.load(open(sys.argv[1]))
try:
release.check_engine(config["engine"])
engine = release.pipeline_engine(config["engine"])
if config["installer"] is not None:
release.check_installer(config["installer"], config["engine"]["version"])
release.check_installer(config["installer"])
except (release.Refusal, KeyError, TypeError) as error:
sys.exit(f"::error::{sys.argv[1]}: {error}")
print(json.dumps(engine, separators=(",", ":")))
PY
echo "engine=$(jq -c .engine "$config")" | tee -a "$GITHUB_OUTPUT"
)
echo "engine=$engine" | tee -a "$GITHUB_OUTPUT"
echo "installer=$(jq -c .installer "$config")" | tee -a "$GITHUB_OUTPUT"

upload:
Expand Down
128 changes: 128 additions & 0 deletions Engine/engine_pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/env python3
"""Name the installation engine the source lock pins, and check that name.

Engine/source-lock.json is the only place the engine is pinned: downstream_overlay.version
names it and validation_artifact holds its file name, size and digest. Everything else
reads it there: the app (OmarchyEnginePinPlugin, at build time), Packaging/build-app.sh,
the release workflows and the catalog tools. See docs/engine-versions.md.

engine_pin.py name [--date YYYYMMDD] [--write]
The name for the engine the lock describes: v0.9.2-omarchy.<date>.<content id>.
The content id is a digest of the lock's build inputs, so two branches that change
the engine differently get different names, and the same inputs get the same id.
--write puts the name (and the matching archive file name) in the lock.

engine_pin.py check
Fail if a dated name's content id does not match the lock's build inputs, or if
the archive name does not follow the name.

After merging two branches that both changed the engine: resolve the lock's build inputs,
run `name --write`, rebuild the engine and record its size and digest.
"""

import argparse
from datetime import datetime, timezone
import hashlib
import json
from pathlib import Path
import re
import sys

ROOT = Path(__file__).resolve().parents[1]
LOCK = ROOT / "Engine" / "source-lock.json"

BASE = "v0.9.2-omarchy"
DATED = re.compile(r"v0\.9\.2-omarchy\.(\d{8})\.([0-9a-f]{12})")

# The lock's build inputs. Everything else in it either describes the result
# (the name and the artifact) or is prose.
INPUTS = (
"upstream_installer",
"upstream_metadata",
"downstream_overlay",
"incremental_build",
"build_inputs",
"build_toolchain",
"build_recipe",
)


class PinError(Exception):
pass


def load_lock(path=LOCK):
return json.loads(Path(path).read_text())


def content_id(lock):
inputs = {key: lock[key] for key in INPUTS if key in lock}
inputs["downstream_overlay"] = {
key: value for key, value in inputs["downstream_overlay"].items() if key != "version"
}
inputs["metadata_sha256"] = lock["validation_artifact"]["metadata_sha256"]
canonical = json.dumps(inputs, sort_keys=True, separators=(",", ":")).encode()
return hashlib.sha256(canonical).hexdigest()[:12]


def dated_name(lock, date):
if not re.fullmatch(r"\d{8}", date):
raise PinError(f"the date must be YYYYMMDD: {date}")
datetime.strptime(date, "%Y%m%d")
return f"{BASE}.{date}.{content_id(lock)}"


def archive_name(version):
return f"installer-{version}.tar.gz"


def dump_json(document):
return json.dumps(document, indent=2, ensure_ascii=False) + "\n"


def check(lock):
problems = []
version = lock["downstream_overlay"]["version"]
# Engines named before dated names (v0.9.2-omarchy.50 and earlier) pass
# until the next engine change renames them.
if (match := DATED.fullmatch(version)) and match.group(2) != content_id(lock):
problems.append(
f"{version} names content {match.group(2)}, but the lock's build inputs are {content_id(lock)}; "
"run `engine_pin.py name --write`"
)
filename = lock["validation_artifact"]["filename"]
if filename != archive_name(version):
problems.append(f"validation_artifact.filename is {filename}, expected {archive_name(version)}")
return problems


def main(argv=None):
parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0])
commands = parser.add_subparsers(dest="command", required=True)
name = commands.add_parser("name", help="print (or --write) the dated engine name")
name.add_argument("--date", default=datetime.now(timezone.utc).strftime("%Y%m%d"))
name.add_argument("--write", action="store_true")
commands.add_parser("check", help="fail if the lock's engine name is inconsistent")
args = parser.parse_args(argv)
lock = load_lock()
try:
if args.command == "name":
version = dated_name(lock, args.date)
if args.write:
lock["downstream_overlay"]["version"] = version
lock["validation_artifact"]["filename"] = archive_name(version)
LOCK.write_text(dump_json(lock))
print(version)
else:
problems = check(lock)
for problem in problems:
print(problem, file=sys.stderr)
return 1 if problems else 0
except PinError as error:
print(error, file=sys.stderr)
return 1
return 0


if __name__ == "__main__":
sys.exit(main())
4 changes: 2 additions & 2 deletions Engine/rebuild-python-overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
'asahi_firmware/bluetooth.py': 'aa12e6cd684ed5b55d732db1f040d84570537bacc991d03ee6f854cbb232c369',
}
BASE_COMMIT = 'f0469cea0899f3efed8efead604174c7a53c4451'
VERSION = 'v0.9.2-omarchy.50'

_SPEC = importlib.util.spec_from_file_location(
'verify_source_lock', Path(__file__).resolve().parent / 'verify-source-lock.py')
Expand Down Expand Up @@ -137,7 +136,8 @@ def rebuild(checkout, base, output):
if item['destination'] != 'bin/' + Path(item['path']).name:
raise ValueError('bundled tool destination is invalid: ' + item['path'])
overlay[item['destination']] = (root / item['path']).read_bytes()
overlay['version.tag'] = (VERSION + '\n').encode()
# The name is the lock's; Engine/engine_pin.py chooses it.
overlay['version.tag'] = (lock['downstream_overlay']['version'] + '\n').encode()
with tarfile.open(fileobj=io.BytesIO(data), mode='r:gz') as archive:
# The engine carries its own installer metadata; the per-payload copy in the repository is a different file.
if sha256(archive.extractfile('./installer_data.json').read()) != lock['validation_artifact']['metadata_sha256']:
Expand Down
2 changes: 1 addition & 1 deletion Engine/source-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@
},
{
"path": "rebuild-python-overlay.py",
"sha256": "2b9861e574228f69d81e136f93336e67488a889fc788ca6dbbb10c2d5779b7ac"
"sha256": "3ea07c0b9b7cb26b371c0bd970405d5ecb223a766c54dd6a31c3d2dcebea1139"
},
{
"path": "RestoreImage/LICENSE",
Expand Down
89 changes: 89 additions & 0 deletions Engine/tests/test_engine_pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import copy
import importlib.util
from pathlib import Path
import subprocess
import unittest


MODULE_PATH = Path(__file__).resolve().parents[1] / "engine_pin.py"
SPEC = importlib.util.spec_from_file_location("engine_pin", MODULE_PATH)
PIN = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(PIN)


class EnginePinTests(unittest.TestCase):
def setUp(self):
self.lock = PIN.load_lock()

def test_the_lock_names_its_engine_consistently(self):
self.assertEqual(PIN.check(self.lock), [])

def test_nothing_else_repeats_the_pin(self):
# Every consumer reads the lock, so an engine change touches only the
# lock and two branches that change the engine conflict only there.
# Docs and evidence may record the history of past engines.
digest = self.lock["validation_artifact"]["sha256"]
result = subprocess.run(["git", "grep", "-l", "-F", digest, "--", ".",
":!Engine/source-lock.json", ":!docs", ":!evidence", ":!*.md"],
cwd=PIN.ROOT, capture_output=True, text=True)
if result.returncode == 128:
self.skipTest(f"not a git checkout: {result.stderr.strip()}")
self.assertEqual(result.stdout.split(), [], "these files repeat the engine digest; read the lock instead")

def test_the_content_id_ignores_the_name_and_the_built_artifact(self):
other = copy.deepcopy(self.lock)
other["downstream_overlay"]["version"] = "v0.9.2-omarchy.99"
other["validation_artifact"]["filename"] = "installer-v0.9.2-omarchy.99.tar.gz"
other["validation_artifact"]["sha256"] = "0" * 64
other["validation_artifact"]["size_bytes"] = 1
other["status"] = "prose changes do not rename the engine"
self.assertEqual(PIN.content_id(other), PIN.content_id(self.lock))

def test_any_build_input_change_gives_a_new_content_id(self):
cases = {
"an overlay source": lambda lock: lock["downstream_overlay"]["files"][0].update(sha256="1" * 64),
"the runtime patch": lambda lock: lock["downstream_overlay"]["patch"].update(sha256="2" * 64),
"the build recipe": lambda lock: lock["build_recipe"][0].update(sha256="3" * 64),
"the base engine": lambda lock: lock["incremental_build"].update(base_sha256="4" * 64),
"the engine metadata": lambda lock: lock["validation_artifact"].update(metadata_sha256="5" * 64),
}
for name, change in cases.items():
with self.subTest(name):
other = copy.deepcopy(self.lock)
change(other)
self.assertNotEqual(PIN.content_id(other), PIN.content_id(self.lock))

def test_dated_names_carry_the_date_and_the_content_id(self):
name = PIN.dated_name(self.lock, "20261014")
self.assertEqual(name, f"v0.9.2-omarchy.20261014.{PIN.content_id(self.lock)}")
self.assertEqual(PIN.archive_name(name), f"installer-{name}.tar.gz")

def test_impossible_dates_are_refused(self):
for date in ("2026101", "20261301", "2026-10-14"):
with self.subTest(date):
with self.assertRaises((PIN.PinError, ValueError)):
PIN.dated_name(self.lock, date)

def test_a_dated_name_must_match_the_lock_inputs(self):
other = copy.deepcopy(self.lock)
stale = "v0.9.2-omarchy.20261014.000000000000"
other["downstream_overlay"]["version"] = stale
other["validation_artifact"]["filename"] = PIN.archive_name(stale)
problems = PIN.check(other)
self.assertTrue(any("names content 000000000000" in problem for problem in problems), problems)

def test_the_archive_name_must_follow_the_version(self):
other = copy.deepcopy(self.lock)
other["validation_artifact"]["filename"] = "installer-something-else.tar.gz"
self.assertTrue(any("expected installer-" in problem for problem in PIN.check(other)))

def test_name_write_renames_the_engine_and_its_archive(self):
other = copy.deepcopy(self.lock)
name = PIN.dated_name(other, "20261014")
other["downstream_overlay"]["version"] = name
other["validation_artifact"]["filename"] = PIN.archive_name(name)
self.assertEqual(PIN.check(other), [])


if __name__ == "__main__":
unittest.main()
11 changes: 10 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,20 @@ let package = Package(
capability: .buildTool(),
dependencies: ["OmarchyInstallerIdentityGenerator"]
),
.executableTarget(
name: "OmarchyEnginePinGenerator",
path: "Sources/OmarchyEnginePinGenerator"
),
.plugin(
name: "OmarchyEnginePinPlugin",
capability: .buildTool(),
dependencies: ["OmarchyEnginePinGenerator"]
),
.target(
name: "OmarchyAppleInstallerTrustCore",
dependencies: ["OmarchyInstallerSystem", "RecoveryAccountCore"],
path: "Sources/OmarchyAppleInstaller",
plugins: ["OmarchyInstallerIdentityPlugin"]
plugins: ["OmarchyInstallerIdentityPlugin", "OmarchyEnginePinPlugin"]
),
.target(
name: "OmarchyInstallerUXCore",
Expand Down
1 change: 1 addition & 0 deletions Packaging/build-app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ helper_identifier="$INSTALLER_HELPER_IDENTIFIER"
app_name="$INSTALLER_APP_NAME.app"
app_executable_name="OmarchyAppleInstallerApp"
daemon_plist_name="$helper_identifier.plist"
# The engine is pinned only in the source lock (docs/engine-versions.md).
read -r engine_file_name engine_digest engine_size < <(
python3 "$script_directory/read-validation-engine.py"
)
Expand Down
Loading
Loading