fix(installer): write pinned package dependencies
Publish UPM package / publish (push) Successful in 2s

This commit is contained in:
2026-08-26 06:37:53 +08:00
parent 7de7bbbcdc
commit 6fa2ad2623
6 changed files with 78 additions and 48 deletions
+5
View File
@@ -26,6 +26,11 @@ jobs:
shell: bash shell: bash
run: | run: |
set -eu set -eu
machine_id_file="/root/.local/share/unity3d/Unity/.machine-id"
if test -s "$machine_id_file"; then
cat "$machine_id_file" > /etc/machine-id
echo "Unity machine identity restored"
fi
unity_bin="$(command -v unity-editor || command -v unity || command -v Unity || true)" unity_bin="$(command -v unity-editor || command -v unity || command -v Unity || true)"
test -n "$unity_bin" test -n "$unity_bin"
"$unity_bin" \ "$unity_bin" \
+5 -24
View File
@@ -12,9 +12,7 @@ namespace ShrinkSDK.Installer
{ {
internal sealed class ShrinkSdkInstallerWindow : EditorWindow internal sealed class ShrinkSdkInstallerWindow : EditorWindow
{ {
private AddRequest? _addRequest;
private ListRequest? _listRequest; private ListRequest? _listRequest;
private ShrinkSdkPackageEntry? _pendingInstall;
private int _selectedPackageIndex; private int _selectedPackageIndex;
private string _status = "Ready"; private string _status = "Ready";
private MessageType _statusType = MessageType.Info; private MessageType _statusType = MessageType.Info;
@@ -69,26 +67,10 @@ namespace ShrinkSDK.Installer
EditorGUILayout.HelpBox(_status, _statusType); EditorGUILayout.HelpBox(_status, _statusType);
} }
private bool IsBusy => _addRequest != null || _listRequest != null; private bool IsBusy => _listRequest != null;
private void Update() private void Update()
{ {
if (_addRequest != null && _addRequest.IsCompleted)
{
var request = _addRequest;
_addRequest = null;
if (request.Status == StatusCode.Success)
{
SetStatus("Installed " + request.Result.name + " " + request.Result.version, MessageType.Info);
}
else
{
SetStatus("Package install failed: " + request.Error.message, MessageType.Error);
}
_pendingInstall = null;
}
if (_listRequest != null && _listRequest.IsCompleted) if (_listRequest != null && _listRequest.IsCompleted)
{ {
var request = _listRequest; var request = _listRequest;
@@ -110,7 +92,6 @@ namespace ShrinkSDK.Installer
try try
{ {
ShrinkSdkManifestStore.EnsureShrinkSdkRegistry(); ShrinkSdkManifestStore.EnsureShrinkSdkRegistry();
_pendingInstall = null;
Client.Resolve(); Client.Resolve();
SetStatus("Registry configuration written. Unity is resolving packages.", MessageType.Info); SetStatus("Registry configuration written. Unity is resolving packages.", MessageType.Info);
} }
@@ -124,11 +105,11 @@ namespace ShrinkSDK.Installer
{ {
try try
{ {
ShrinkSdkManifestStore.EnsureShrinkSdkRegistry(); ShrinkSdkManifestStore.EnsurePackageInstallation(entry);
Client.Resolve(); Client.Resolve();
_pendingInstall = entry; SetStatus(
_addRequest = Client.Add(entry.PackageSpecifier); "Pinned " + entry.PackageName + " " + entry.Version + " in Packages/manifest.json. Unity is resolving packages.",
SetStatus("Installing " + entry.PackageSpecifier, MessageType.Info); MessageType.Info);
} }
catch (Exception exception) catch (Exception exception)
{ {
+41 -1
View File
@@ -27,6 +27,28 @@ namespace ShrinkSDK.Installer
internal static void EnsureShrinkSdkRegistry() internal static void EnsureShrinkSdkRegistry()
{ {
var manifest = ReadManifest(); var manifest = ReadManifest();
EnsureShrinkSdkRegistry(manifest);
AtomicWrite(manifest.ToString(Formatting.Indented) + Environment.NewLine);
}
internal static void EnsurePackageInstallation(ShrinkSdkPackageEntry package)
{
var manifest = ReadManifest();
EnsureShrinkSdkRegistry(manifest);
EnsurePinnedDependency(manifest, package.PackageName, package.Version);
if (package.RequiresUniTask)
{
EnsurePinnedDependency(
manifest,
ShrinkSdkPackageCatalog.UniTaskPackageName,
ShrinkSdkPackageCatalog.UniTaskGitUrl);
}
AtomicWrite(manifest.ToString(Formatting.Indented) + Environment.NewLine);
}
private static void EnsureShrinkSdkRegistry(JObject manifest)
{
var registries = manifest["scopedRegistries"] as JArray; var registries = manifest["scopedRegistries"] as JArray;
if (registries == null) if (registries == null)
{ {
@@ -71,8 +93,26 @@ namespace ShrinkSDK.Installer
registry["scopes"] = scopes; registry["scopes"] = scopes;
} }
}
AtomicWrite(manifest.ToString(Formatting.Indented) + Environment.NewLine); private static void EnsurePinnedDependency(JObject manifest, string packageName, string version)
{
var dependencies = manifest["dependencies"] as JObject;
if (dependencies == null)
{
dependencies = new JObject();
manifest["dependencies"] = dependencies;
}
var existing = dependencies[packageName];
if (existing != null && !string.Equals(existing.Value<string>(), version, StringComparison.Ordinal))
{
throw new InvalidOperationException(
"Packages/manifest.json already pins " + packageName + " to " + existing.Value<string>() +
". ShrinkSDK requires the fixed version " + version + ".");
}
dependencies[packageName] = version;
} }
private static JObject ReadManifest() private static JObject ReadManifest()
+24 -20
View File
@@ -7,17 +7,18 @@ namespace ShrinkSDK.Installer
{ {
internal sealed class ShrinkSdkPackageEntry internal sealed class ShrinkSdkPackageEntry
{ {
public ShrinkSdkPackageEntry(string displayName, string packageName, string version) public ShrinkSdkPackageEntry(string displayName, string packageName, string version, bool requiresUniTask = false)
{ {
DisplayName = displayName; DisplayName = displayName;
PackageName = packageName; PackageName = packageName;
Version = version; Version = version;
RequiresUniTask = requiresUniTask;
} }
public string DisplayName { get; } public string DisplayName { get; }
public string PackageName { get; } public string PackageName { get; }
public string Version { get; } public string Version { get; }
public string PackageSpecifier => PackageName + "@" + Version; public bool RequiresUniTask { get; }
} }
internal static class ShrinkSdkPackageCatalog internal static class ShrinkSdkPackageCatalog
@@ -25,32 +26,35 @@ namespace ShrinkSDK.Installer
internal const string RegistryName = "ShrinkSDK"; internal const string RegistryName = "ShrinkSDK";
internal const string RegistryUrl = "https://git.crash.work/api/packages/ShrinkSDK/npm/"; internal const string RegistryUrl = "https://git.crash.work/api/packages/ShrinkSDK/npm/";
internal const string RegistryScope = "com.cneicy"; internal const string RegistryScope = "com.cneicy";
internal const string UniTaskPackageName = "com.cysharp.unitask";
internal const string UniTaskGitUrl = "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#7c0f199fe0d3fc528024488ccd671e6c7b27745b";
internal static readonly ShrinkSdkPackageEntry StarterBasic = new( internal static readonly ShrinkSdkPackageEntry StarterBasic = new(
"ShrinkApp Starter Basic", "ShrinkApp Starter Basic",
"com.cneicy.shrink-app-starter-basic", "com.cneicy.shrink-app-starter-basic",
"0.1.0"); "0.1.0",
requiresUniTask: true);
internal static readonly IReadOnlyList<ShrinkSdkPackageEntry> Packages = new[] internal static readonly IReadOnlyList<ShrinkSdkPackageEntry> Packages = new[]
{ {
new ShrinkSdkPackageEntry("ShrinkApp Core", "com.cneicy.shrink-app-core", "0.1.1"), new ShrinkSdkPackageEntry("ShrinkApp Core", "com.cneicy.shrink-app-core", "0.1.1", requiresUniTask: true),
StarterBasic, StarterBasic,
new ShrinkSdkPackageEntry("ShrinkCommand", "com.cneicy.shrink-command", "0.2.0"), new ShrinkSdkPackageEntry("ShrinkCommand", "com.cneicy.shrink-command", "0.2.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkCommand Integration App", "com.cneicy.shrink-command-integration-app", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkCommand Integration App", "com.cneicy.shrink-command-integration-app", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkCommand Integration EventBus", "com.cneicy.shrink-command-integration-eventbus", "0.1.1"), new ShrinkSdkPackageEntry("ShrinkCommand Integration EventBus", "com.cneicy.shrink-command-integration-eventbus", "0.1.1", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkCommand Integration Network", "com.cneicy.shrink-command-integration-network", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkCommand Integration Network", "com.cneicy.shrink-command-integration-network", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkContext App Adapter", "com.cneicy.shrink-context-app-adapter", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkContext App Adapter", "com.cneicy.shrink-context-app-adapter", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkContext Core", "com.cneicy.shrink-context-core", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkContext Core", "com.cneicy.shrink-context-core", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkContext EventBus Adapter", "com.cneicy.shrink-context-eventbus-adapter", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkContext EventBus Adapter", "com.cneicy.shrink-context-eventbus-adapter", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkDataSaver", "com.cneicy.shrink-datasaver", "2.2.0"), new ShrinkSdkPackageEntry("ShrinkDataSaver", "com.cneicy.shrink-datasaver", "2.2.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkDataSaver Integration App", "com.cneicy.shrink-datasaver-integration-app", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkDataSaver Integration App", "com.cneicy.shrink-datasaver-integration-app", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkDataSaver Integration EventBus", "com.cneicy.shrink-datasaver-integration-eventbus", "2.1.0"), new ShrinkSdkPackageEntry("ShrinkDataSaver Integration EventBus", "com.cneicy.shrink-datasaver-integration-eventbus", "2.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkEventBus", "com.cneicy.shrink-eventbus", "2.0.0"), new ShrinkSdkPackageEntry("ShrinkEventBus", "com.cneicy.shrink-eventbus", "2.0.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkEventBus Entities", "com.cneicy.shrink-eventbus-entities", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkEventBus Entities", "com.cneicy.shrink-eventbus-entities", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkModFramework", "com.cneicy.shrink-mod-framework", "0.2.1"), new ShrinkSdkPackageEntry("ShrinkModFramework", "com.cneicy.shrink-mod-framework", "0.2.1", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkNetwork", "com.cneicy.shrink-network", "0.2.0"), new ShrinkSdkPackageEntry("ShrinkNetwork", "com.cneicy.shrink-network", "0.2.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkNetwork Integration App", "com.cneicy.shrink-network-integration-app", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkNetwork Integration App", "com.cneicy.shrink-network-integration-app", "0.1.0", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkNetwork Integration EventBus", "com.cneicy.shrink-network-integration-eventbus", "0.1.1"), new ShrinkSdkPackageEntry("ShrinkNetwork Integration EventBus", "com.cneicy.shrink-network-integration-eventbus", "0.1.1", requiresUniTask: true),
new ShrinkSdkPackageEntry("ShrinkShared CodeGen", "com.cneicy.shrink-shared-codegen", "0.1.0"), new ShrinkSdkPackageEntry("ShrinkShared CodeGen", "com.cneicy.shrink-shared-codegen", "0.1.0"),
new ShrinkSdkPackageEntry("ShrinkTutorial", "com.cneicy.shrink-tutorial", "0.1.0") new ShrinkSdkPackageEntry("ShrinkTutorial", "com.cneicy.shrink-tutorial", "0.1.0")
}; };
+2 -2
View File
@@ -2,12 +2,12 @@
`com.cneicy.shrink-installer` is the Git URL bootstrap package for ShrinkSDK. `com.cneicy.shrink-installer` is the Git URL bootstrap package for ShrinkSDK.
Install the package from an immutable tag, then open `ShrinkSDK/Packages` in the Unity editor. The window merges the public ShrinkSDK scoped registry without replacing other registries and installs only catalogued package versions. Install the package from an immutable tag, then open `ShrinkSDK/Packages` in the Unity editor. The window merges the public ShrinkSDK scoped registry without replacing other registries and writes only catalogue-pinned dependencies to `Packages/manifest.json`. Packages which require UniTask also receive its fixed Git revision.
The installer does not copy templates into `Assets`, does not store credentials, and does not add an unpinned package version. The installer does not copy templates into `Assets`, does not store credentials, and does not add an unpinned package version.
## Bootstrap URL ## Bootstrap URL
```text ```text
https://git.crash.work/ShrinkSDK/Installer.git#v0.1.2 https://git.crash.work/ShrinkSDK/Installer.git#v0.1.3
``` ```
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "com.cneicy.shrink-installer", "name": "com.cneicy.shrink-installer",
"version": "0.1.2", "version": "0.1.3",
"displayName": "ShrinkSDK Installer", "displayName": "ShrinkSDK Installer",
"description": "ShrinkSDK registry bootstrapper and fixed-version package installer.", "description": "ShrinkSDK registry bootstrapper and fixed-version package installer.",
"unity": "2022.3", "unity": "2022.3",