From ce5a19c1318eec414db26d598293e039cd45c4cc Mon Sep 17 00:00:00 2001 From: Kevin Yue Date: Thu, 29 Oct 2026 22:55:19 +0800 Subject: [PATCH] ci(macos): verify selected desktop shell before publication --- .github/workflows/build.yaml | 14 ++++++-- .github/workflows/publish-macos-assets.yaml | 3 +- .github/workflows/publish-update-feeds.yaml | 7 ++++ scripts/tests/test_private_ci.py | 38 +++++++++++++++++++- scripts/tests/test_validate_macos_release.py | 37 +++++++++++++------ scripts/validate-macos-release.py | 7 ++-- 6 files changed, 88 insertions(+), 18 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1cfaf9c..8358ee8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -563,6 +563,8 @@ jobs: runs-on: ${{ vars.MACOS_RUNNER || 'macos-15' }} environment: macos-release timeout-minutes: 120 + env: + MACOS_GUI: tauri steps: - name: Verify runner architecture run: test "$(uname -m)" = arm64 @@ -752,7 +754,7 @@ jobs: if [[ "$CHANNEL" == "snapshot" ]]; then export GPGUI_RELEASE_DEVTOOLS=1 fi - source/gpgui/scripts/build-macos.sh dmg release + source/gpgui/scripts/build-macos.sh dmg release --gui "$MACOS_GUI" ) 2>&1 | awk ' /^MACOS_STAGE: (Native dependencies|Components|Frontend|Application|Bundle|Bundle icons|Bundle metadata|Bundle licenses|Bundle libraries|Bundle frameworks|Bundle optimization|Signing|Validation|App notarization|Update archive|Disk image|Disk image notarization|Complete)$/ { print "::notice::" $0 @@ -789,9 +791,15 @@ jobs: BUILD_VERSION: ${{ format('{0}.{1}', github.run_number, github.run_attempt) }} WORKFLOW_SHA: ${{ github.sha }} run: | + set -euo pipefail GP_REF="$(git -C source/gp rev-parse HEAD)" GPGUI_REF="$(git -C source/gpgui rev-parse HEAD)" - export GP_REF GPGUI_REF + GUI="$(plutil -extract GPDesktopShell raw 'source/gpgui/target/release/bundle/macos/GP Connect.app/Contents/Info.plist')" + if [[ "$GUI" != "$MACOS_GUI" ]]; then + echo "Built desktop shell does not match the selected GUI" >&2 + exit 1 + fi + export GP_REF GPGUI_REF GUI python3 - <<'PYTHON' import hashlib import json @@ -799,7 +807,7 @@ jobs: from pathlib import Path directory = Path("release-assets") metadata = {key.lower(): os.environ[key] for key in ( - "CHANNEL", "RELEASE_TAG", "GP_REF", "GPGUI_REF", "REQUEST_ID", "BUILD_VERSION", "WORKFLOW_SHA")} + "CHANNEL", "RELEASE_TAG", "GP_REF", "GPGUI_REF", "REQUEST_ID", "BUILD_VERSION", "WORKFLOW_SHA", "GUI")} metadata["artifact_version"] = os.environ["MACOS_ARTIFACT_VERSION"] metadata["assets"] = { file.name: hashlib.sha256(file.read_bytes()).hexdigest() diff --git a/.github/workflows/publish-macos-assets.yaml b/.github/workflows/publish-macos-assets.yaml index 2a07d3a..fa5b3b3 100644 --- a/.github/workflows/publish-macos-assets.yaml +++ b/.github/workflows/publish-macos-assets.yaml @@ -66,10 +66,11 @@ jobs: RELEASE_TAG: ${{ inputs.release_tag }} WORKFLOW_COMMIT: ${{ steps.build.outputs.workflow_commit }} ARTIFACT_NAME: ${{ steps.build.outputs.artifact }} + EXPECTED_GUI: tauri run: | set -euo pipefail metadata="$(python3 scripts/validate-macos-release.py release-assets \ - --release-tag "$RELEASE_TAG" --workflow-commit "$WORKFLOW_COMMIT")" + --release-tag "$RELEASE_TAG" --workflow-commit "$WORKFLOW_COMMIT" --gui "$EXPECTED_GUI")" [[ "$ARTIFACT_NAME" == "macos-release-$(jq -r '.request_id' <<<"$metadata")" ]] { echo "gp_ref=$(jq -r '.gp_ref' <<<"$metadata")" diff --git a/.github/workflows/publish-update-feeds.yaml b/.github/workflows/publish-update-feeds.yaml index 3befe75..d904674 100644 --- a/.github/workflows/publish-update-feeds.yaml +++ b/.github/workflows/publish-update-feeds.yaml @@ -88,6 +88,7 @@ jobs: REQUESTED_ARCHIVE: ${{ inputs.archive_name }} FEED_URL: ${{ vars.SPARKLE_FEED_URL }} EXPECTED_TEAM_ID: ${{ vars.MACOS_TEAM_ID }} + EXPECTED_GUI: tauri UPDATES_WORKER_NAME: ${{ vars.UPDATES_WORKER_NAME || 'gp-updates' }} SPARKLE_VERSION: 2.9.2 UPDATE_HIGHLIGHTS: ${{ inputs.highlights }} @@ -285,6 +286,12 @@ jobs: fi file "$app/Contents/MacOS/gpgui" | grep -q 'arm64' + desktop_shell="$(plutil -extract GPDesktopShell raw "$app/Contents/Info.plist")" + if [[ "$desktop_shell" != "$EXPECTED_GUI" ]]; then + echo "Update archive desktop shell does not match the selected GUI" >&2 + exit 1 + fi + feed_url="$(plutil -extract SUFeedURL raw "$app/Contents/Info.plist")" if [[ "$feed_url" != "$FEED_URL" ]]; then echo "Unexpected Sparkle feed URL: $feed_url" >&2 diff --git a/scripts/tests/test_private_ci.py b/scripts/tests/test_private_ci.py index 7e0b99d..f09dc66 100644 --- a/scripts/tests/test_private_ci.py +++ b/scripts/tests/test_private_ci.py @@ -1,5 +1,6 @@ import json import os +import plistlib from pathlib import Path import re import subprocess @@ -27,6 +28,41 @@ def run_block(path, step=None): class PrivateOutputTests(unittest.TestCase): + def test_macos_metadata_records_the_bundled_shell_and_rejects_a_different_one(self): + for gui in ('tauri', 'nsh'): + with self.subTest(gui=gui), tempfile.TemporaryDirectory() as temporary: + root = Path(temporary) + tools = root / 'bin' + tools.mkdir() + git = tools / 'git' + git.write_text('#!/bin/sh\nprintf "%040d\\n" 1\n') + git.chmod(0o755) + plutil = tools / 'plutil' + plutil.write_text(f'#!{sys.executable}\nimport plistlib,sys\n' + 'with open(sys.argv[-1], "rb") as file:\n' + ' print(plistlib.load(file)[sys.argv[2]])\n') + plutil.chmod(0o755) + info = root / 'source/gpgui/target/release/bundle/macos/GP Connect.app/Contents/Info.plist' + info.parent.mkdir(parents=True) + info.write_bytes(plistlib.dumps({'GPDesktopShell': gui})) + artifacts = root / 'release-assets' + artifacts.mkdir() + (artifacts / 'fixture.dmg').write_bytes(b'signed fixture') + env = dict(os.environ, PATH=f'{tools}:{os.environ["PATH"]}', MACOS_GUI='tauri', + CHANNEL='stable', RELEASE_TAG='v3.2.0', REQUEST_ID='42.1.macos', + BUILD_VERSION='42.1', WORKFLOW_SHA='a' * 40, MACOS_ARTIFACT_VERSION='3.2.0') + result = subprocess.run(['bash', '-e', '-c', run_block( + '.github/workflows/build.yaml', 'Record build identity')], + cwd=root, env=env, text=True, capture_output=True) + metadata = artifacts / 'release-build.json' + if gui == 'tauri': + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(json.loads(metadata.read_text())['gui'], 'tauri') + else: + self.assertNotEqual(result.returncode, 0) + self.assertIn('desktop shell', result.stderr) + self.assertFalse(metadata.exists()) + def test_private_checkout_supports_branch_tag_and_sha_without_retaining_token(self): with tempfile.TemporaryDirectory() as temporary: root = Path(temporary) @@ -78,7 +114,7 @@ class PrivateOutputTests(unittest.TestCase): (root / 'updates').mkdir() (root / 'updates/appcast.xml').write_text('fixture') env = dict(os.environ, PATH=f'{root}:{os.environ["PATH"]}', - TEST_STATUS=str(status), CHANNEL='snapshot', GPGUI_BUILDER='fixture', + TEST_STATUS=str(status), CHANNEL='snapshot', MACOS_GUI='tauri', GPGUI_BUILDER='fixture', RUNNER_TEMP=str(root), UPDATES_WORKER_NAME='fixture', PRIVATE_TOKEN='test-token', PRIVATE_REF='test-ref', PRIVATE_PATH='private') result = subprocess.run(['bash', '-e', '-c', run_block(path, step)], diff --git a/scripts/tests/test_validate_macos_release.py b/scripts/tests/test_validate_macos_release.py index c655b7f..cb88065 100644 --- a/scripts/tests/test_validate_macos_release.py +++ b/scripts/tests/test_validate_macos_release.py @@ -18,7 +18,7 @@ class MacOSReleaseTests(unittest.TestCase): self.commit = "a" * 40 self.metadata = {"gp_ref": "b" * 40, "gpgui_ref": "d" * 40, "workflow_sha": self.commit, "channel": "stable", "release_tag": "v3.0.1", "artifact_version": "3.0.1", - "request_id": "42.1.macos", "build_version": "903.1", "assets": {}} + "request_id": "42.1.macos", "build_version": "903.1", "gui": "tauri", "assets": {}} for extension in ("dmg", "zip"): name = f"GPConnect_3.0.1_arm64.{extension}" content = b"signed artifact" @@ -34,48 +34,63 @@ class MacOSReleaseTests(unittest.TestCase): (self.directory / "release-build.json").write_text(json.dumps(self.metadata)) def test_matching_build_passes(self): - self.assertEqual(release.validate(self.directory, "v3.0.1", self.commit), self.metadata) + self.assertEqual(release.validate(self.directory, "v3.0.1", self.commit, "tauri"), self.metadata) + + def test_another_gui_cannot_use_this_build(self): + with self.assertRaisesRegex(ValueError, "desktop shell"): + release.validate(self.directory, "v3.0.1", self.commit, "nsh") + + def test_shell_metadata_is_required(self): + del self.metadata["gui"] + self.save() + with self.assertRaisesRegex(ValueError, "desktop shell"): + release.validate(self.directory, "v3.0.1", self.commit, "tauri") + + def test_nsh_metadata_is_accepted_only_when_requested(self): + self.metadata["gui"] = "nsh" + self.save() + self.assertEqual(release.validate(self.directory, "v3.0.1", self.commit, "nsh"), self.metadata) def test_another_release_cannot_use_this_build(self): with self.assertRaisesRegex(ValueError, "release tag"): - release.validate(self.directory, "v3.0.2", self.commit) + release.validate(self.directory, "v3.0.2", self.commit, "tauri") def test_another_run_commit_cannot_use_this_build(self): with self.assertRaisesRegex(ValueError, "public workflow"): - release.validate(self.directory, "v3.0.1", "c" * 40) + release.validate(self.directory, "v3.0.1", "c" * 40, "tauri") def test_source_commit_cannot_replace_workflow_identity(self): with self.assertRaisesRegex(ValueError, "public workflow"): - release.validate(self.directory, "v3.0.1", self.metadata["gp_ref"]) + release.validate(self.directory, "v3.0.1", self.metadata["gp_ref"], "tauri") def test_invalid_workflow_commit_is_rejected(self): self.metadata["workflow_sha"] = "short" self.save() with self.assertRaisesRegex(ValueError, "Invalid workflow_sha"): - release.validate(self.directory, "v3.0.1", "short") + release.validate(self.directory, "v3.0.1", "short", "tauri") def test_corrupt_download_is_rejected(self): (self.directory / "GPConnect_3.0.1_arm64.zip").write_bytes(b"changed") with self.assertRaisesRegex(ValueError, "checksum mismatch"): - release.validate(self.directory, "v3.0.1", self.commit) + release.validate(self.directory, "v3.0.1", self.commit, "tauri") def test_unexpected_file_is_rejected(self): (self.directory / "unexpected.dmg").write_bytes(b"extra") with self.assertRaisesRegex(ValueError, "Unexpected"): - release.validate(self.directory, "v3.0.1", self.commit) + release.validate(self.directory, "v3.0.1", self.commit, "tauri") def test_missing_checksum_is_rejected(self): self.metadata["assets"].pop("GPConnect_3.0.1_arm64.zip.sha256") self.save() with self.assertRaisesRegex(ValueError, "exactly"): - release.validate(self.directory, "v3.0.1", self.commit) + release.validate(self.directory, "v3.0.1", self.commit, "tauri") def test_snapshot_requires_matching_build_identity(self): self.metadata.update(channel="snapshot", release_tag="snapshot", artifact_version="3.0.1-snapshot.903.2") self.save() with self.assertRaisesRegex(ValueError, "snapshot artifact version"): - release.validate(self.directory, "snapshot", self.commit) + release.validate(self.directory, "snapshot", self.commit, "tauri") def test_matching_snapshot_passes(self): version = "3.0.1-snapshot.903.1" @@ -92,7 +107,7 @@ class MacOSReleaseTests(unittest.TestCase): self.metadata.update(channel="snapshot", release_tag="snapshot", artifact_version=version, assets=assets) self.save() - self.assertEqual(release.validate(self.directory, "snapshot", self.commit), self.metadata) + self.assertEqual(release.validate(self.directory, "snapshot", self.commit, "tauri"), self.metadata) if __name__ == "__main__": diff --git a/scripts/validate-macos-release.py b/scripts/validate-macos-release.py index 9776f9a..24db796 100644 --- a/scripts/validate-macos-release.py +++ b/scripts/validate-macos-release.py @@ -8,8 +8,10 @@ from pathlib import Path import re -def validate(directory, release_tag, workflow_commit): +def validate(directory, release_tag, workflow_commit, gui): metadata = json.loads((directory / "release-build.json").read_text()) + if gui not in ("tauri", "nsh") or metadata.get("gui") != gui: + raise ValueError("Artifact desktop shell does not match the selected GUI") for name in ("gp_ref", "gpgui_ref", "workflow_sha"): if not re.fullmatch(r"[0-9a-f]{40}", metadata[name]): raise ValueError(f"Invalid {name}") @@ -59,9 +61,10 @@ if __name__ == "__main__": parser.add_argument("directory", type=Path) parser.add_argument("--release-tag", required=True) parser.add_argument("--workflow-commit", required=True) + parser.add_argument("--gui", choices=("tauri", "nsh"), required=True) args = parser.parse_args() try: - result = validate(args.directory, args.release_tag, args.workflow_commit) + result = validate(args.directory, args.release_tag, args.workflow_commit, args.gui) except (ValueError, KeyError, OSError) as error: parser.exit(1, f"{error}\n") print(json.dumps(result))