Skip to content

Commit bb67d2b

Browse files
unity-setup@v1.3.0 (#43)
- updated version checking and validation - fix release version failure log printing - refactor how .sh scripts are invoked with bash command - fix `UNITY_EDITOR_PATH` formatting to be proper json object
1 parent 8371eb5 commit bb67d2b

File tree

9 files changed

+84
-40
lines changed

9 files changed

+84
-40
lines changed

.github/workflows/validate.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ on:
66
branches: [main]
77
pull_request:
88
branches: ['*']
9+
types: [opened, synchronize, reopened, ready_for_review]
910
# Allows you to run this workflow manually from the Actions tab
1011
workflow_dispatch:
1112
concurrency:
1213
group: ${{ github.workflow }}-${{ github.ref }}
1314
cancel-in-progress: true
1415
jobs:
1516
setup:
17+
if: github.event.pull_request.draft == false
1618
runs-on: ubuntu-latest
1719
permissions:
1820
contents: read

dist/index.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35984,7 +35984,7 @@ async function installUnityHub() {
3598435984
case 'darwin':
3598535985
{
3598635986
const scriptPath = __nccwpck_require__.ab + "install-unityhub-macos.sh";
35987-
exitCode = await exec.exec('sh', [__nccwpck_require__.ab + "install-unityhub-macos.sh"]);
35987+
exitCode = await exec.exec('bash', [__nccwpck_require__.ab + "install-unityhub-macos.sh"]);
3598835988
if (exitCode !== 0) {
3598935989
throw new Error(`Failed to install Unity Hub: ${exitCode}`);
3599035990
}
@@ -35995,7 +35995,7 @@ async function installUnityHub() {
3599535995
{
3599635996
const scriptPath = __nccwpck_require__.ab + "install-unityhub-linux.sh";
3599735997
let output = '';
35998-
exitCode = await exec.exec('sh', [__nccwpck_require__.ab + "install-unityhub-linux.sh"], {
35998+
exitCode = await exec.exec('bash', [__nccwpck_require__.ab + "install-unityhub-linux.sh"], {
3599935999
listeners: {
3600036000
stdout: (data) => {
3600136001
output += data.toString();
@@ -36133,7 +36133,7 @@ const retryErrorMessages = [
3613336133
async function UnityEditor(unityVersion, modules) {
3613436134
core.info(`Getting release info for Unity ${unityVersion.toString()}...`);
3613536135
let editorPath = await checkInstalledEditors(unityVersion, false);
36136-
if (!unityVersion.isLegacy() && !editorPath) {
36136+
if (!unityVersion.isLegacy() && !editorPath && !unityVersion.changeset) {
3613736137
try {
3613836138
const releases = await getLatestHubReleases();
3613936139
unityVersion = unityVersion.findMatch(releases);
@@ -36142,7 +36142,12 @@ async function UnityEditor(unityVersion, modules) {
3614236142
}
3614336143
catch (error) {
3614436144
core.warning(`Failed to get Unity release info for ${unityVersion.toString()}! falling back to legacy search...\n${error}`);
36145-
unityVersion = await fallbackVersionLookup(unityVersion);
36145+
try {
36146+
unityVersion = await fallbackVersionLookup(unityVersion);
36147+
}
36148+
catch (fallbackError) {
36149+
core.warning(`Failed to lookup changeset for Unity ${unityVersion.toString()}!\n${fallbackError}`);
36150+
}
3614636151
}
3614736152
}
3614836153
let installPath = null;
@@ -36232,7 +36237,7 @@ async function installUnity(unityVersion, modules) {
3623236237
core.startGroup(`Installing Unity ${unityVersion.toString()}...`);
3623336238
if (process.platform === 'linux') {
3623436239
const installLinuxDepsScript = __nccwpck_require__.ab + "install-linux-dependencies.sh";
36235-
const exitCode = await exec.exec('sh', [__nccwpck_require__.ab + "install-linux-dependencies.sh", unityVersion.version], {
36240+
const exitCode = await exec.exec('bash', [__nccwpck_require__.ab + "install-linux-dependencies.sh", unityVersion.version], {
3623636241
ignoreReturnCode: true
3623736242
});
3623836243
if (exitCode !== 0) {
@@ -36288,7 +36293,7 @@ async function installUnity4x(unityVersion) {
3628836293
const installPath = path.join(installDir, `Unity ${unityVersion.version}`, 'Unity.app');
3628936294
if (!fs.existsSync(installPath)) {
3629036295
const scriptPath = __nccwpck_require__.ab + "unity-editor-installer.sh";
36291-
const exitCode = await exec.exec('sh', [__nccwpck_require__.ab + "unity-editor-installer.sh", unityVersion.version, installDir], {
36296+
const exitCode = await exec.exec('bash', [__nccwpck_require__.ab + "unity-editor-installer.sh", unityVersion.version, installDir], {
3629236297
ignoreReturnCode: true
3629336298
});
3629436299
if (exitCode !== 0) {
@@ -36437,7 +36442,7 @@ async function getEditorReleaseInfo(unityVersion) {
3643736442
core.debug(`Get Unity Release: ${JSON.stringify(request, null, 2)}`);
3643836443
const { data, error } = await releasesClient.api.ReleaseService.getUnityReleases(request);
3643936444
if (error) {
36440-
throw new Error(`Failed to get Unity releases: ${error}`);
36445+
throw new Error(`Failed to get Unity releases: ${JSON.stringify(error, null, 2)}`);
3644136446
}
3644236447
if (!data || !data.results || data.results.length === 0) {
3644336448
throw new Error(`No Unity releases found for version: ${version}`);
@@ -36480,7 +36485,7 @@ async function fallbackVersionLookup(unityVersion) {
3648036485
return unityVersion;
3648136486
}
3648236487
const responseText = await response.text();
36483-
if (core.isDebug()) {
36488+
if (core.isDebug() || !response.ok) {
3648436489
core.info(responseText);
3648536490
}
3648636491
if (!response.ok) {
@@ -47277,20 +47282,20 @@ const main = async () => {
4727747282
if (installPath && installPath.length > 0) {
4727847283
await unityHub.SetInstallPath(installPath);
4727947284
}
47280-
const editors = [];
47285+
const installedEditors = [];
4728147286
for (const unityVersion of versions) {
4728247287
const unityEditorPath = await unityHub.UnityEditor(unityVersion, modules);
4728347288
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath);
4728447289
if (modules.includes('android') && unityProjectPath !== undefined) {
4728547290
await (0, install_android_sdk_1.CheckAndroidSdkInstalled)(unityEditorPath, unityProjectPath);
4728647291
}
4728747292
core.info(`Installed Unity Editor: ${unityVersion.toString()} at ${unityEditorPath}`);
47288-
editors.push([unityVersion.version, unityEditorPath]);
47293+
installedEditors.push({ version: unityVersion.version, path: unityEditorPath });
4728947294
}
47290-
if (editors.length !== versions.length) {
47291-
throw new Error(`Expected to install ${versions.length} Unity versions, but installed ${editors.length}.`);
47295+
if (installedEditors.length !== versions.length) {
47296+
throw new Error(`Expected to install ${versions.length} Unity versions, but installed ${installedEditors.length}.`);
4729247297
}
47293-
core.exportVariable('UNITY_EDITORS', JSON.stringify(Object.fromEntries(editors)));
47298+
core.exportVariable('UNITY_EDITORS', JSON.stringify(Object.fromEntries(installedEditors.map(e => [e.version, e.path]))));
4729447299
core.info('Unity Setup Complete!');
4729547300
process.exit(0);
4729647301
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/install-linux-dependencies.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ fi
1313
echo "::group::Installing additional dependencies for Unity $unityVersion..."
1414

1515
# Unity 2019.{1,2}
16-
if [[ "$unityVersion" =~ ^2019\.[12]\. ]]; then
16+
case "$unityVersion" in
17+
2019.1.*|2019.2.*)
1718
curl -LO https://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb
1819
sudo dpkg -i libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb
1920
rm libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb
20-
fi
21+
;;
22+
esac
2123

2224
# Unity 2019.{3,4}/2020.*
23-
if [[ "$unityVersion" =~ ^2019\.[34]\. ]] || [[ "$unityVersion" =~ ^2020\. ]]; then
25+
case "$unityVersion" in
26+
2019.3.*|2019.4.*|2020.*)
2427
curl -LO https://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
2528
sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
2629
rm libssl1.1_1.1.0g-2ubuntu4_amd64.deb
27-
fi
30+
;;
31+
esac
2832

2933
echo "::endgroup::"

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unity-setup",
3-
"version": "1.2.6",
3+
"version": "1.3.0",
44
"description": "A GitHub action for setting up the Unity Game Engine for CI/CD workflows.",
55
"author": "RageAgainstThePixel",
66
"license": "MIT",

src/index.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,42 @@ import core = require('@actions/core');
66
const main = async () => {
77
try {
88
const [versions, modules, unityProjectPath, installPath] = await ValidateInputs();
9+
910
if (unityProjectPath) {
1011
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
1112
}
13+
1214
const unityHubPath = await unityHub.Get();
1315
core.exportVariable('UNITY_HUB_PATH', unityHubPath);
16+
1417
if (installPath && installPath.length > 0) {
1518
await unityHub.SetInstallPath(installPath);
1619
}
17-
const editors = [];
20+
21+
const installedEditors: { version: string; path: string }[] = [];
22+
1823
for (const unityVersion of versions) {
1924
const unityEditorPath = await unityHub.UnityEditor(unityVersion, modules);
20-
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath); // always sets the last installed editor path
25+
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath); // always sets to the latest installed editor path
26+
2127
if (modules.includes('android') && unityProjectPath !== undefined) {
2228
await CheckAndroidSdkInstalled(unityEditorPath, unityProjectPath);
2329
}
30+
2431
core.info(`Installed Unity Editor: ${unityVersion.toString()} at ${unityEditorPath}`);
25-
editors.push([unityVersion.version, unityEditorPath]);
32+
installedEditors.push({ version: unityVersion.version, path: unityEditorPath });
2633
}
27-
if (editors.length !== versions.length) {
28-
throw new Error(`Expected to install ${versions.length} Unity versions, but installed ${editors.length}.`);
34+
35+
if (installedEditors.length !== versions.length) {
36+
throw new Error(`Expected to install ${versions.length} Unity versions, but installed ${installedEditors.length}.`);
2937
}
30-
core.exportVariable('UNITY_EDITORS', JSON.stringify(Object.fromEntries(editors)));
38+
39+
core.exportVariable('UNITY_EDITORS', JSON.stringify(Object.fromEntries(installedEditors.map(e => [e.version, e.path]))));
3140
core.info('Unity Setup Complete!');
3241
process.exit(0);
3342
} catch (error) {
3443
core.setFailed(error.stack);
3544
}
36-
}
45+
};
3746

3847
main();

src/install-linux-dependencies.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ fi
1313
echo "::group::Installing additional dependencies for Unity $unityVersion..."
1414

1515
# Unity 2019.{1,2}
16-
if [[ "$unityVersion" =~ ^2019\.[12]\. ]]; then
16+
case "$unityVersion" in
17+
2019.1.*|2019.2.*)
1718
curl -LO https://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb
1819
sudo dpkg -i libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb
1920
rm libssl1.0.0_1.0.2g-1ubuntu4.20_amd64.deb
20-
fi
21+
;;
22+
esac
2123

2224
# Unity 2019.{3,4}/2020.*
23-
if [[ "$unityVersion" =~ ^2019\.[34]\. ]] || [[ "$unityVersion" =~ ^2020\. ]]; then
25+
case "$unityVersion" in
26+
2019.3.*|2019.4.*|2020.*)
2427
curl -LO https://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.0g-2ubuntu4_amd64.deb
2528
sudo dpkg -i libssl1.1_1.1.0g-2ubuntu4_amd64.deb
2629
rm libssl1.1_1.1.0g-2ubuntu4_amd64.deb
27-
fi
30+
;;
31+
esac
2832

2933
echo "::endgroup::"

src/unity-hub.ts

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ async function installUnityHub(): Promise<string> {
137137
case 'darwin':
138138
{
139139
const scriptPath = path.join(__dirname, 'install-unityhub-macos.sh');
140-
exitCode = await exec.exec('sh', [scriptPath]);
140+
// Use bash to respect script shebang and any bash-specific features
141+
exitCode = await exec.exec('bash', [scriptPath]);
141142
if (exitCode !== 0) {
142143
throw new Error(`Failed to install Unity Hub: ${exitCode}`);
143144
}
@@ -148,7 +149,8 @@ async function installUnityHub(): Promise<string> {
148149
{
149150
const scriptPath = path.join(__dirname, 'install-unityhub-linux.sh');
150151
let output = '';
151-
exitCode = await exec.exec('sh', [scriptPath], {
152+
// Use bash to respect script shebang and any bash-specific features
153+
exitCode = await exec.exec('bash', [scriptPath], {
152154
listeners: {
153155
stdout: (data) => {
154156
output += data.toString();
@@ -290,18 +292,26 @@ const retryErrorMessages = [
290292
export async function UnityEditor(unityVersion: UnityVersion, modules: string[]): Promise<string> {
291293
core.info(`Getting release info for Unity ${unityVersion.toString()}...`);
292294
let editorPath = await checkInstalledEditors(unityVersion, false);
293-
if (!unityVersion.isLegacy() && !editorPath) {
295+
296+
// attempt to resolve the full version with the changeset if we don't have one already
297+
if (!unityVersion.isLegacy() && !editorPath && !unityVersion.changeset) {
294298
try {
295299
const releases = await getLatestHubReleases();
296300
unityVersion = unityVersion.findMatch(releases);
297301
const unityReleaseInfo: UnityRelease = await getEditorReleaseInfo(unityVersion);
298302
unityVersion = new UnityVersion(unityReleaseInfo.version, unityReleaseInfo.shortRevision, unityVersion.architecture);
299303
} catch (error) {
300304
core.warning(`Failed to get Unity release info for ${unityVersion.toString()}! falling back to legacy search...\n${error}`);
301-
unityVersion = await fallbackVersionLookup(unityVersion);
305+
try {
306+
unityVersion = await fallbackVersionLookup(unityVersion);
307+
} catch (fallbackError) {
308+
core.warning(`Failed to lookup changeset for Unity ${unityVersion.toString()}!\n${fallbackError}`);
309+
}
302310
}
303311
}
312+
304313
let installPath: string | null = null;
314+
305315
if (!editorPath) {
306316
try {
307317
installPath = await installUnity(unityVersion, modules);
@@ -310,6 +320,7 @@ export async function UnityEditor(unityVersion: UnityVersion, modules: string[])
310320
if (editorPath) {
311321
await RemovePath(editorPath);
312322
}
323+
313324
if (installPath) {
314325
await RemovePath(installPath);
315326
}
@@ -318,25 +329,32 @@ export async function UnityEditor(unityVersion: UnityVersion, modules: string[])
318329
throw error;
319330
}
320331
}
332+
321333
editorPath = await checkInstalledEditors(unityVersion, true, installPath);
322334
}
335+
323336
await fs.promises.access(editorPath, fs.constants.X_OK);
324337
core.info(`Unity Editor Path:\n > "${editorPath}"`);
325338
await patchBeeBackend(editorPath);
339+
326340
if (unityVersion.isLegacy() || modules.length === 0) {
327341
return editorPath;
328342
}
343+
329344
try {
330345
core.startGroup(`Checking installed modules for Unity ${unityVersion.toString()}...`);
331346
const [installedModules, additionalModules] = await checkEditorModules(editorPath, unityVersion, modules);
347+
332348
if (installedModules && installedModules.length > 0) {
333349
core.info(`Installed Modules:`);
350+
334351
for (const module of installedModules) {
335352
core.info(` > ${module}`);
336353
}
337354
}
338355
if (additionalModules && additionalModules.length > 0) {
339356
core.info(`Additional Modules:`);
357+
340358
for (const module of additionalModules) {
341359
core.info(` > ${module}`);
342360
}
@@ -349,6 +367,7 @@ export async function UnityEditor(unityVersion: UnityVersion, modules: string[])
349367
} finally {
350368
core.endGroup();
351369
}
370+
352371
return editorPath;
353372
}
354373

@@ -400,7 +419,7 @@ async function installUnity(unityVersion: UnityVersion, modules: string[]): Prom
400419

401420
if (process.platform === 'linux') {
402421
const installLinuxDepsScript = path.join(__dirname, 'install-linux-dependencies.sh');
403-
const exitCode = await exec.exec('sh', [installLinuxDepsScript, unityVersion.version], {
422+
const exitCode = await exec.exec('bash', [installLinuxDepsScript, unityVersion.version], {
404423
ignoreReturnCode: true
405424
});
406425

@@ -467,7 +486,8 @@ async function installUnity4x(unityVersion: UnityVersion): Promise<string> {
467486

468487
if (!fs.existsSync(installPath)) {
469488
const scriptPath = path.join(__dirname, 'unity-editor-installer.sh');
470-
const exitCode = await exec.exec('sh', [scriptPath, unityVersion.version, installDir], {
489+
// Use bash to respect script shebang and any bash-specific features
490+
const exitCode = await exec.exec('bash', [scriptPath, unityVersion.version, installDir], {
471491
ignoreReturnCode: true
472492
});
473493

@@ -630,7 +650,7 @@ export async function getEditorReleaseInfo(unityVersion: UnityVersion): Promise<
630650
const { data, error } = await releasesClient.api.ReleaseService.getUnityReleases(request);
631651

632652
if (error) {
633-
throw new Error(`Failed to get Unity releases: ${error}`);
653+
throw new Error(`Failed to get Unity releases: ${JSON.stringify(error, null, 2)}`);
634654
}
635655

636656
if (!data || !data.results || data.results.length === 0) {
@@ -681,7 +701,7 @@ async function fallbackVersionLookup(unityVersion: UnityVersion): Promise<UnityV
681701

682702
const responseText = await response.text();
683703

684-
if (core.isDebug()) {
704+
if (core.isDebug() || !response.ok) {
685705
core.info(responseText);
686706
}
687707

0 commit comments

Comments
 (0)