-
-
Notifications
You must be signed in to change notification settings - Fork 250
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Force module install on Mac #659
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -20,6 +20,8 @@ class SetupMac { | |||||||||||||||||||||||
await SetupMac.installUnity(buildParameters); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
await SetupMac.ensureRequiredModuleIsInstalled(buildParameters); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
await SetupMac.setEnvironmentVariables(buildParameters, actionFolder); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
|
@@ -119,6 +121,26 @@ class SetupMac { | |||||||||||||||||||||||
return moduleArgument; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
private static async ensureRequiredModuleIsInstalled(buildParameters: BuildParameters) { | ||||||||||||||||||||||||
const unityChangeset = await getUnityChangeset(buildParameters.editorVersion); | ||||||||||||||||||||||||
const moduleArguments = SetupMac.getModuleParametersForTargetPlatform(buildParameters.targetPlatform); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
const execArguments: string[] = [ | ||||||||||||||||||||||||
'--', | ||||||||||||||||||||||||
'--headless', | ||||||||||||||||||||||||
'install-modules', | ||||||||||||||||||||||||
...['--version', buildParameters.editorVersion], | ||||||||||||||||||||||||
...['--changeset', unityChangeset.changeset], | ||||||||||||||||||||||||
...moduleArguments, | ||||||||||||||||||||||||
'--childModules', | ||||||||||||||||||||||||
]; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
await exec(this.unityHubExecPath, execArguments, { | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace 'this' with class name in static method Using Apply this diff to fix the issue: - await exec(this.unityHubExecPath, execArguments, {
+ await exec(SetupMac.unityHubExecPath, execArguments, { 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||||||||||||||||||||
silent: true, | ||||||||||||||||||||||||
ignoreReturnCode: true, | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
Comment on lines
+138
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Handle the error code from 'exec' to detect installation failures Currently, the Apply this diff to handle the error code: - await exec(SetupMac.unityHubExecPath, execArguments, {
- silent: true,
- ignoreReturnCode: true,
- });
+ const errorCode = await exec(SetupMac.unityHubExecPath, execArguments, {
+ silent: true,
+ ignoreReturnCode: true,
+ });
+ if (errorCode) {
+ throw new Error(`There was an error installing the required module. See logs above for details.`);
+ } 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
private static async installUnity(buildParameters: BuildParameters, silent = false) { | ||||||||||||||||||||||||
const unityEditorPath = `/Applications/Unity/Hub/Editor/${buildParameters.editorVersion}`; | ||||||||||||||||||||||||
const key = `Cache-MacOS-UnityEditor-With-Module-${buildParameters.targetPlatform}@${buildParameters.editorVersion}`; | ||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Avoid redundant module installations by checking if the module is already installed
Unconditionally calling
ensureRequiredModuleIsInstalled
may lead to reinstalling modules that are already present, increasing setup time and potentially causing issues on non-ephemeral runners. Consider implementing a check to determine if the required module for the target platform is already installed before attempting installation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea AI. How would one do this? I do not know of any way to get Unity Hub to expose what modules are currently installed other than asking to install them.
Docs can be found here: https://docs.unity3d.com/hub/manual/HubCLI.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Rycieos, thanks for pointing that out. The script didn't work because the
UNITY_VERSION
andBUILD_TARGET
environment variables were empty. We can address this by integrating the check directly into theensureRequiredModuleIsInstalled
method. Here's how you might modify the method to check if the required module is already installed before attempting installation:By checking if the module's directory exists using
fs.existsSync(modulePath)
, we can determine whether the required module is already installed. If the module is missing, the script proceeds to install it using Unity Hub CLI.Let me know if this solution works for you!
(•ᴗ•)
🔗 Analysis chain
@Rycieos, you're correct that Unity Hub CLI doesn't provide a direct way to list installed modules. However, we can check if the required module's files exist in the Unity installation directory before attempting installation. Here's a script that performs this check:
This script checks if the module directory exists within the Unity installation. If the directory is not found, it proceeds to install the module using Unity Hub CLI. Integrating this check into the
ensureRequiredModuleIsInstalled
method should prevent redundant installations.(•ᵕ•)
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 286