Skip to content

Commit

Permalink
Merge pull request #3 from kurone-kito/improve-the-project
Browse files Browse the repository at this point in the history
Improve the project
  • Loading branch information
kurone-kito authored Mar 9, 2024
2 parents d99b94b + 679d787 commit d3cb263
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 210 deletions.
14 changes: 14 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
chat:
auto_reply: true
early_access: true
language: en
reviews:
auto_review:
enabled: true
path_filters:
- '!Assets'
- '!Packages/com.vrchat.core.*/**/*'
- '!ProjectSettings'
path_instructions:
- instructions: Some files look broken, but they contain templates from Scriban. Please review with this in mind.
path: Website/**/*
29 changes: 7 additions & 22 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ jobs:
config_package: ${{ steps.config_package.outputs.configPackage }}
steps:

# Ensure that required repository variable has been created for the Package
- name: Validate Package Config
- name: Ensure that required repository variable has been created for the Package
id: config_package
run: |
if [ "${{ vars.PACKAGE_NAME }}" != "" ]; then
Expand All @@ -20,8 +19,6 @@ jobs:
echo "configPackage=false" >> $GITHUB_OUTPUT;
fi
# Build and release the Package
# If the repository is not configured properly, this job will be skipped
build:
needs: config
runs-on: ubuntu-latest
Expand All @@ -39,39 +36,27 @@ jobs:
with:
file_path: "${{ env.packagePath }}/package.json"
prop_path: "version"

# Configure the Environment Variables needed for releasing the Package
- name: Set Environment Variables
- name: Configure the Environment Variables needed for releasing the Package
run: |
echo "zipFile=${{ vars.PACKAGE_NAME }}-${{ steps.version.outputs.value }}".zip >> $GITHUB_ENV
echo "unityPackage=${{ vars.PACKAGE_NAME }}-${{ steps.version.outputs.value }}.unitypackage" >> $GITHUB_ENV
echo "version=${{ steps.version.outputs.value }}" >> $GITHUB_ENV
# Zip the Package for release
- name: Create Package Zip
- name: Zip the Package for release
working-directory: "${{ env.packagePath }}"
run: zip -r "${{ github.workspace }}/${{ env.zipFile }}" .

# Build a list of .meta files for future use
- name: Track Package Meta Files
- name: Build a list of .meta files for future use
run: find "${{ env.packagePath }}/" -name \*.meta >> metaList

# Make a UnityPackage version of the Package for release
- name: Create UnityPackage
- name: Make a UnityPackage version of the Package for release
uses: pCYSl5EDgo/create-unitypackage@v1
with:
package-path: ${{ env.unityPackage }}
include-files: metaList

# Make a release tag of the version from the package.json file
- name: Create Tag
- name: Create a release tag of the version from the package.json file
id: tag_version
uses: rickstaa/action-create-tag@v1
with:
tag: "${{ env.version }}"

# Publish the Release to GitHub
- name: Make Release
- name: Publish the Release to GitHub
uses: softprops/[email protected]
with:
files: |
Expand Down
7 changes: 5 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"dotnet.preferCSharpExtension": true,
"files.associations": {
"*.asmdef": "json",
"*.asset": "yaml",
"*.mat": "yaml",
"*.meta": "yaml",
"*.prefab": "yaml",
"*.uss": "css",
"LICENSE": "plaintext"
},
Expand Down Expand Up @@ -54,8 +57,8 @@
"tag:unity3d.com,2011:1386491679 mapping"
],
"yaml.schemas": {
"https://raw.githubusercontent.com/reviewpad/schemas/main/latest/schema.json": [
"reviewpad.yml"
"https://coderabbit.ai/integrations/coderabbit-overrides.v2.json": [
".coderabbit.yaml"
],
"https://raw.githubusercontent.com/streetsidesoftware/cspell/main/packages/cspell-types/cspell.schema.json": [
"cspell.config.yml"
Expand Down
Binary file not shown.
167 changes: 117 additions & 50 deletions Packages/com.vrchat.core.vpm-resolver/Editor/Resolver/ResolverWindow.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEditor;
Expand All @@ -21,9 +23,25 @@ public class ResolverWindow : EditorWindow
private static Button _resolveButton;
private static Box _manifestInfo;
private static Label _manifestLabel;
private static Label _manifestInfoText;
private static VisualElement _manifestPackageList;
private static bool _isUpdating;
private static Color _colorPositive = Color.green;
private static Color _colorNegative = new Color(1, 0.3f, 0.3f);

const string HAS_REFRESHED_KEY = "VRC.PackageManagement.Resolver.Refreshed";

private static bool IsUpdating
{
get => _isUpdating;
set
{
_isUpdating = value;
_refreshButton.SetEnabled(!value);
_refreshButton.text = value ? "Refreshing..." : "Refresh";
_manifestLabel.text = value ? "Refreshing packages ..." : "Required Packages";
}
}


[MenuItem("VRChat SDK/Utilities/Package Resolver")]
Expand All @@ -33,48 +51,66 @@ public static void ShowWindow()
wnd.titleContent = new GUIContent("Package Resolver");
}

public static void Refresh()
public static async Task Refresh()
{
if (_rootView == null || string.IsNullOrWhiteSpace(Resolver.ProjectDir)) return;

_manifestInfo.SetEnabled(!_isUpdating);
_refreshButton.SetEnabled(!_isUpdating);
_manifestLabel.text = (_isUpdating ? "Working ..." : "Required Packages");
_manifestInfo.Clear();
_manifestInfo.Add(_manifestLabel);

bool needsResolve = VPMProjectManifest.ResolveIsNeeded(Resolver.ProjectDir);
string resolveStatus = needsResolve ? "Please press \"Resolve\" to Download them." : "All of them are in the project.";
IsUpdating = true;
_manifestPackageList.Clear();

// check for vpm dependencies
if (!Resolver.VPMManifestExists())
{
TextElement noManifestText = new TextElement();
noManifestText.text = "No VPM Manifest";
noManifestText.style.color = _colorNegative;
_manifestInfo.Add(noManifestText);
_manifestInfoText.style.display = DisplayStyle.Flex;
_manifestInfoText.text = "No VPM Manifest";
_manifestInfoText.style.color = _colorNegative;
}
else
{
var manifest = VPMProjectManifest.Load(Resolver.ProjectDir);
var project = new UnityProject(Resolver.ProjectDir);

// Here is where we detect if all dependencies are installed
var allDependencies = (manifest.locked != null && manifest.locked.Count > 0)
? manifest.locked
: manifest.dependencies;
_manifestInfoText.style.display = DisplayStyle.None;
}

var manifest = VPMProjectManifest.Load(Resolver.ProjectDir);
var project = await Task.Run(() => new UnityProject(Resolver.ProjectDir));

// Here is where we detect if all dependencies are installed
var allDependencies = manifest.locked != null && manifest.locked.Count > 0
? manifest.locked
: manifest.dependencies;

var depList = await Task.Run(() =>
{
var results = new Dictionary<(string id, string version), (IVRCPackage package, List<string> allVersions)>();
foreach (var pair in allDependencies)
{
var id = pair.Key;
var version = pair.Value.version;
IVRCPackage package = project.VPMProvider.GetPackage(id, version);
_manifestInfo.Add(CreateDependencyRow(id, version, project, (package != null)));
var package = project.VPMProvider.GetPackage(id, version);
results.Add((id, version), (package, Resolver.GetAllVersionsOf(id)));
}

var legacyPackages = project.VPMProvider.GetLegacyPackages();

results = results.Where(i => !legacyPackages.Contains(i.Key.id)).ToDictionary(i => i.Key, i => i.Value);

return results;
});

foreach (var dep in depList)
{

_manifestPackageList.Add(
CreateDependencyRow(
dep.Key.id,
dep.Key.version,
project,
dep.Value.package,
dep.Value.allVersions
)
);
}
_resolveButton.SetEnabled(needsResolve);
Resolver.ForceRefresh();

IsUpdating = false;
}

/// <summary>
Expand Down Expand Up @@ -119,44 +155,81 @@ private void CreateGUI()
name = "manifest-info",
};
_manifestLabel = (new Label("Required Packages") { name = "manifest-header" });
_manifestInfo.Add(_manifestLabel);
_manifestInfoText = new Label();
_manifestInfo.Add(_manifestInfoText);
_manifestPackageList = new VisualElement();
_manifestPackageList.style.flexDirection = FlexDirection.Column;
_manifestPackageList.style.alignItems = Align.Stretch;
_manifestInfo.Add(_manifestPackageList);

_rootView.Add(_manifestInfo);

// Refresh Button
var refreshBox = new Box();
_refreshButton = new Button(Refresh)
_refreshButton = new Button(() =>
{
// When manually refreshing - ensure package manager is also up to date
Resolver.ForceRefresh();
Refresh();
})
{
text = "Refresh",
name = "refresh-button-base"
};
refreshBox.Add(_refreshButton);
_rootView.Add(refreshBox);

// Refresh on open
// Sometimes unity can get into a bad state where calling package manager refresh will endlessly reload assemblies
// That in turn means that a Full refresh will be called every single time assemblies are loaded
// Which locks up the editor in an endless loop
// This condition ensures that the UPM resolve only happens on first launch
// We also call it after installing packages or hitting Refresh manually
if (!SessionState.GetBool(HAS_REFRESHED_KEY, false))
{
SessionState.SetBool(HAS_REFRESHED_KEY, true);
Resolver.ForceRefresh();
}

Refresh();
rootVisualElement.schedule.Execute(() => Refresh()).ExecuteLater(100);
}

private static VisualElement CreateDependencyRow(string id, string version, UnityProject project, bool havePackage)
private static VisualElement CreateDependencyRow(string id, string version, UnityProject project, IVRCPackage package, List <string> allVersions)
{
// Table

VisualElement row = new Box() { name = "package-box" };
VisualElement column1 = new Box() { name = "package-box" };
VisualElement column2 = new Box() { name = "package-box" };
VisualElement column3 = new Box() { name = "package-box" };
VisualElement column4 = new Box() { name = "package-box" };
bool havePackage = package != null;

// Table Row
VisualElement row = new Box { name = "package-row" };
VisualElement column1 = new Box { name = "package-box" };
VisualElement column2 = new Box { name = "package-box" };
VisualElement column3 = new Box { name = "package-box" };
VisualElement column4 = new Box { name = "package-box" };

column1.style.minWidth = 200;
column1.style.width = new StyleLength(new Length(40, LengthUnit.Percent));
column2.style.minWidth = 100;
column2.style.width = new StyleLength(new Length(20, LengthUnit.Percent));
column3.style.minWidth = 100;
column3.style.width = new StyleLength(new Length(20, LengthUnit.Percent));
column4.style.minWidth = 100;
column4.style.width = new StyleLength(new Length(20, LengthUnit.Percent));

row.Add(column1);
row.Add(column2);
row.Add(column3);
row.Add(column4);

// Package Name + Status

column1.style.alignItems = Align.FlexStart;
if (havePackage)
{
column1.style.flexDirection = FlexDirection.Column;
var titleRow = new VisualElement();
titleRow.style.unityFontStyleAndWeight = FontStyle.Bold;
titleRow.Add(new Label(package.Title));
column1.Add(titleRow);
}
TextElement text = new TextElement { text = $"{id} {version} " };

column1.Add(text);
Expand All @@ -165,29 +238,23 @@ private static VisualElement CreateDependencyRow(string id, string version, Unit
{
TextElement missingText = new TextElement { text = "MISSING" };
missingText.style.color = _colorNegative;
missingText.style.display = (_isUpdating ? DisplayStyle.None : DisplayStyle.Flex);
column2.Add(missingText);
}

// Version Popup

var choices = new List<string>();
foreach (string n in Resolver.GetAllVersionsOf(id))
var currVersion = Mathf.Max(0, havePackage ? allVersions.IndexOf(package.Version) : 0);
var popupField = new PopupField<string>(allVersions, 0)
{
choices.Add(n);
}

var popupField = new PopupField<string>(choices, 0);
popupField.value = choices[0];
popupField.style.display = (_isUpdating ? DisplayStyle.None : DisplayStyle.Flex);
value = allVersions[currVersion]
};

column3.Add(popupField);

// Button

Button updateButton = new Button() { text = "Update" };
if (havePackage)
RefreshUpdateButton(updateButton, version, choices[0]);
RefreshUpdateButton(updateButton, version, allVersions[0]);
else
RefreshMissingButton(updateButton);

Expand Down Expand Up @@ -264,7 +331,6 @@ private static void RefreshMissingButton(Button button)
{
button.text = "Resolve";
SetButtonColor(button, Color.white);
button.style.display = (_isUpdating ? DisplayStyle.None : DisplayStyle.Flex);
}

private static void SetButtonColor(Button button, Color color)
Expand All @@ -281,11 +347,12 @@ private static void SetButtonColor(Button button, Color color)
private static async void OnUpdatePackageClicked(UnityProject project, IVRCPackage package)
{
_isUpdating = true;
Refresh();
await Refresh();
await Task.Delay(500);
await Task.Run(() => project.UpdateVPMPackage(package));
project.UpdateVPMPackage(package);
_isUpdating = false;
Refresh();
Resolver.ForceRefresh();
}

}
Expand Down
Loading

0 comments on commit d3cb263

Please sign in to comment.