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
20 changes: 19 additions & 1 deletion .project/projectctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,30 @@ def source(root):
"event": os.environ.get("GITHUB_EVENT_NAME", "local"),
"ref": os.environ.get("GITHUB_REF", "")}

# Xcode records each distribution in an archive's top-level Info.plist, so
# uploading changes that file. An archive's identity is every other file,
# byte for byte, plus what that Info.plist says about the archive and the app
# inside it.
ARCHIVE_KEYS = ("ArchiveVersion", "CreationDate", "Name", "SchemeName")
ARCHIVE_APPLICATION_KEYS = ("ApplicationPath", "Architectures", "CFBundleIdentifier", "CFBundleShortVersionString",
"CFBundleVersion", "SigningIdentity", "Team")

def archive_identity(path):
info = plistlib.loads((path / "Info.plist").read_bytes())
application = info.get("ApplicationProperties", {})
identity = {key: info[key] for key in ARCHIVE_KEYS if key in info}
identity["ApplicationProperties"] = {key: application[key] for key in ARCHIVE_APPLICATION_KEYS if key in application}
return json.dumps(identity, sort_keys=True, default=str).encode()

def digest(path):
path = Path(path)
files = sorted(path.rglob("*")) if path.is_dir() else [path]
archive = path.is_dir() and path.suffix == ".xcarchive" and (path / "Info.plist").is_file()
value = hashlib.sha256()
for item in files:
if item.is_symlink():
if archive and item == path / "Info.plist":
value.update(b"Info.plist\0" + archive_identity(path))
elif item.is_symlink():
value.update(str(item.relative_to(path)).encode() + b"\0" + os.readlink(item).encode())
elif item.is_file():
value.update((str(item.relative_to(path)) if path.is_dir() else path.name).encode() + b"\0")
Expand Down
4 changes: 2 additions & 2 deletions .project/runtime.lock.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"schema": "project-runtime/v1",
"files": {
"projectctl.py": "904c215b4decc03e4bd97de694d105b93dfda65288fdb3634f14bca770a3779a",
"projectctl.py": "de877635fafa33085a7ed416ef47661dbce5d0fe46c63e33f0269c8006b005f6",
"install.py": "68d74f7bfb6fbd9b2b65c9001e26307f3c7051cbea0f525461a37074b2db0bd6",
"tests/test_projectctl.py": "24da05795b6ab89c33de1603f6afb278b07b4d0e8ab35c895f812bc5985e30d1"
"tests/test_projectctl.py": "485d1e5cc7e32bf502c2bce5a9ffb8634bdef82ca86bca470c0dfa9d51d889fd"
}
}
29 changes: 29 additions & 0 deletions .project/tests/test_projectctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,35 @@ def test_wrong_source_manifest_rejected(self):
def test_dirty_artifact_rejected(self):
artifact,_=self.artifact(dirty='YES')
with self.assertRaisesRegex(ctl.ContractError,'Source changed'):self.project.record(artifact,ctl.source(self.root))
def test_xcode_upload_bookkeeping_is_not_an_archive_change(self):
artifact,_=self.artifact(channel='testflight',tagged='NO')
self.project.record(artifact,ctl.source(self.root))
info=plistlib.loads((artifact/'Info.plist').read_bytes())
def upload(archive, environment):
# What Xcode does when it distributes an archive: it records the upload.
recorded=dict(info, Distributions=[{'destination':'upload','date':datetime(2026,10,9)}])
(archive/'Info.plist').write_bytes(plistlib.dumps(recorded))
stub=SimpleNamespace(upload_archive=upload, load_environment=lambda: {})
with patch.object(self.project,'apple_module',return_value=stub):
self.project.run(self.opts('upload',value=str(artifact),channel='testflight'))
# A retry of the same archive still verifies.
self.project.verify(artifact,'testflight')
def test_upload_that_changes_the_app_or_its_identity_fails(self):
for change in ('product','identity'):
artifact,_=self.artifact(channel='testflight',tagged='NO')
self.project.record(artifact,ctl.source(self.root))
def upload(archive, environment, change=change):
if change=='product':
(archive/'Products/Applications/Example.app/Contents/Extra').write_text('tampered')
else:
info=plistlib.loads((archive/'Info.plist').read_bytes())
info['ApplicationProperties']['CFBundleIdentifier']='com.example.other'
(archive/'Info.plist').write_bytes(plistlib.dumps(info))
stub=SimpleNamespace(upload_archive=upload, load_environment=lambda: {})
with patch.object(self.project,'apple_module',return_value=stub):
with self.assertRaisesRegex(ctl.ContractError,'Upload modified the archive'):
self.project.run(self.opts('upload',value=str(artifact),channel='testflight'))
shutil.rmtree(artifact); (self.root/'build/Example.xcarchive.project.json').unlink()
def test_valid_beta_archive_identity_preserved(self):
artifact,_=self.artifact();manifest=self.project.record(artifact,ctl.source(self.root)); before=ctl.digest(artifact)
self.project.verify(artifact,'testflight');self.assertEqual(before,ctl.digest(artifact));self.assertEqual(manifest['build'],'2026.1001.0900')
Expand Down
Loading