mirror of
https://github.com/yuezk/GlobalProtect-openconnect.git
synced 2026-11-18 22:16:18 -05:00
ci(macos): verify selected desktop shell before publication
This commit is contained in:
6 files changed
+88
-18
No files matched your search
@@ -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)],
|
||||
|
||||
@@ -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__":
|
||||
|
||||
Reference in new issue
Block a user