|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import json |
| 4 | +import re |
| 5 | +import sys |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | + |
| 9 | +ROOT = Path(__file__).resolve().parents[2] |
| 10 | +DEMO = ROOT / "examples/demo" |
| 11 | +BOOTSTRAP = ROOT / "examples/demo/Assets/OneSignal" |
| 12 | +SAMPLE = ROOT / "com.onesignal.unity.core/Samples~" |
| 13 | +INVENTORY = BOOTSTRAP / "Editor/Resources/OneSignalFileInventory.asset" |
| 14 | + |
| 15 | +EXCLUDED_PREFIXES = ( |
| 16 | + "Assets/OneSignal/Attribution", |
| 17 | + "Assets/OneSignal/Example", |
| 18 | +) |
| 19 | +EXCLUDED_FILES = { |
| 20 | + "Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml", |
| 21 | + "Assets/OneSignal/Editor/OneSignalAndroidDependencies.xml.meta", |
| 22 | + "Assets/OneSignal/Editor/OneSignaliOSDependencies.xml", |
| 23 | + "Assets/OneSignal/Editor/OneSignaliOSDependencies.xml.meta", |
| 24 | +} |
| 25 | +REQUIRED_SAMPLE_GUIDS = { |
| 26 | + "OneSignal.UnityPackage.Example.asmdef.meta": "a28dab59edddfb3448f1fd9318f85c32", |
| 27 | + "OneSignalExampleBehaviour.cs.meta": "1a40a711031e4cb8b9b3f674dda19d55", |
| 28 | + "OneSignalExampleScene.unity.meta": "54284d014d2241544a24b57b13c09ac8", |
| 29 | + "INCONSOLATA-VARIABLEFONT_WDTH,WGHT.TTF.meta": "792110c4f5f19e64196eb25f41c0b783", |
| 30 | +} |
| 31 | + |
| 32 | + |
| 33 | +def fail(message: str) -> None: |
| 34 | + print(f"Unity distribution validation failed: {message}", file=sys.stderr) |
| 35 | + raise SystemExit(1) |
| 36 | + |
| 37 | + |
| 38 | +def is_distributed(path: str) -> bool: |
| 39 | + if path in EXCLUDED_FILES or path.endswith("/.DS_Store"): |
| 40 | + return False |
| 41 | + return not any( |
| 42 | + path == prefix |
| 43 | + or path == f"{prefix}.meta" |
| 44 | + or path.startswith(f"{prefix}/") |
| 45 | + for prefix in EXCLUDED_PREFIXES |
| 46 | + ) |
| 47 | + |
| 48 | + |
| 49 | +def validate_inventory() -> None: |
| 50 | + actual = sorted( |
| 51 | + path.relative_to(DEMO).as_posix() |
| 52 | + for path in BOOTSTRAP.rglob("*") |
| 53 | + if path.is_file() and is_distributed(path.relative_to(DEMO).as_posix()) |
| 54 | + ) |
| 55 | + recorded = re.findall(r"^\s*-\s+(Assets/OneSignal/.+)$", INVENTORY.read_text(), re.MULTILINE) |
| 56 | + |
| 57 | + if actual != recorded: |
| 58 | + missing = sorted(set(actual) - set(recorded)) |
| 59 | + stale = sorted(set(recorded) - set(actual)) |
| 60 | + fail( |
| 61 | + "file inventory is out of date" |
| 62 | + + (f"; missing: {', '.join(missing)}" if missing else "") |
| 63 | + + (f"; stale: {', '.join(stale)}" if stale else "") |
| 64 | + ) |
| 65 | + |
| 66 | + |
| 67 | +def validate_sample() -> None: |
| 68 | + for filename, expected_guid in REQUIRED_SAMPLE_GUIDS.items(): |
| 69 | + path = SAMPLE / filename |
| 70 | + if not path.is_file(): |
| 71 | + fail(f"sample is missing {path.relative_to(ROOT)}") |
| 72 | + match = re.search(r"^guid:\s*(\w+)$", path.read_text(), re.MULTILINE) |
| 73 | + if match is None or match.group(1) != expected_guid: |
| 74 | + fail(f"{path.relative_to(ROOT)} does not preserve GUID {expected_guid}") |
| 75 | + |
| 76 | + scene = (SAMPLE / "OneSignalExampleScene.unity").read_text() |
| 77 | + if "OneSignalSDK.OneSignalExampleBehaviour" in scene: |
| 78 | + fail("sample scene contains stale OneSignalExampleBehaviour type references") |
| 79 | + if "OneSignalExampleBehaviour, OneSignal.UnityPackage.Example" not in scene: |
| 80 | + fail("sample scene does not contain OneSignalExampleBehaviour button bindings") |
| 81 | + behaviour = (SAMPLE / "OneSignalExampleBehaviour.cs").read_text() |
| 82 | + if "ExitLiveActivityAsync" in scene or "LiveActivities.ExitAsync" in behaviour: |
| 83 | + fail("sample exposes the deprecated Live Activities exit API") |
| 84 | + |
| 85 | + asmdef = json.loads((SAMPLE / "OneSignal.UnityPackage.Example.asmdef").read_text()) |
| 86 | + required_references = { |
| 87 | + "OneSignal.Core", |
| 88 | + "UnityEngine.UI", |
| 89 | + "UnityEngine.JSONSerializeModule", |
| 90 | + } |
| 91 | + if not required_references.issubset(asmdef["references"]): |
| 92 | + fail("sample assembly is missing required references") |
| 93 | + |
| 94 | + package = json.loads((ROOT / "com.onesignal.unity.core/package.json").read_text()) |
| 95 | + if not any(sample.get("path") == "Samples~" for sample in package.get("samples", [])): |
| 96 | + fail("core package does not register Samples~") |
| 97 | + if not any( |
| 98 | + version.get("name") == "com.onesignal.unity.core" |
| 99 | + and version.get("expression") == package["version"] |
| 100 | + and version.get("define") == "ONE_SIGNAL_INSTALLED" |
| 101 | + for version in asmdef.get("versionDefines", []) |
| 102 | + ): |
| 103 | + fail("sample version define does not match the core package version") |
| 104 | + |
| 105 | + |
| 106 | +def main() -> None: |
| 107 | + if (BOOTSTRAP / "Example").exists() or (BOOTSTRAP / "Example.meta").exists(): |
| 108 | + fail("empty legacy Asset Store Example path still exists") |
| 109 | + if (BOOTSTRAP / "Documentation~").exists(): |
| 110 | + fail("Documentation~ is hidden from Unity and cannot be exported") |
| 111 | + if not (BOOTSTRAP / "Documentation").is_dir(): |
| 112 | + fail("exportable bootstrap documentation is missing") |
| 113 | + validate_inventory() |
| 114 | + validate_sample() |
| 115 | + print("Unity distribution layout is valid.") |
| 116 | + |
| 117 | + |
| 118 | +if __name__ == "__main__": |
| 119 | + main() |
0 commit comments