Skip to content

Commit a7cbd00

Browse files
- fix editor path lookup - fix version matching - fix macos hub install on x64 runners
1 parent 84d1973 commit a7cbd00

11 files changed

+150
-92
lines changed

dist/index.js

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35483,7 +35483,7 @@ async function ValidateInputs() {
3548335483
break;
3548435484
}
3548535485
if (architecture) {
35486-
core.info(`architecture:\n > ${architecture.toLocaleLowerCase()}`);
35486+
core.info(`architecture:\n > ${architecture.toLowerCase()}`);
3548735487
}
3548835488
const buildTargets = getArrayInput('build-targets');
3548935489
core.info(`modules:`);
@@ -36115,7 +36115,8 @@ const retryErrorMessages = [
3611536115
];
3611636116
async function UnityEditor(unityVersion, modules) {
3611736117
core.info(`Getting release info for Unity ${unityVersion.toString()}...`);
36118-
if (!unityVersion.isLegacy()) {
36118+
let editorPath = await checkInstalledEditors(unityVersion, false);
36119+
if (!unityVersion.isLegacy() && !editorPath) {
3611936120
try {
3612036121
const releases = await getLatestHubReleases();
3612136122
unityVersion = unityVersion.findMatch(releases);
@@ -36127,7 +36128,6 @@ async function UnityEditor(unityVersion, modules) {
3612736128
unityVersion = await fallbackVersionLookup(unityVersion);
3612836129
}
3612936130
}
36130-
let editorPath = await checkInstalledEditors(unityVersion, false);
3613136131
let installPath = null;
3613236132
if (!editorPath) {
3613336133
try {
@@ -36209,7 +36209,7 @@ async function installUnity(unityVersion, modules) {
3620936209
args.push('--changeset', unityVersion.changeset);
3621036210
}
3621136211
if (unityVersion.architecture) {
36212-
args.push('-a', unityVersion.architecture.toLocaleLowerCase());
36212+
args.push('-a', unityVersion.architecture.toLowerCase());
3621336213
}
3621436214
if (modules.length > 0) {
3621536215
for (const module of modules) {
@@ -36281,20 +36281,26 @@ async function checkInstalledEditors(unityVersion, failOnEmpty, installPath = un
3628136281
if (paths.length !== matches.length) {
3628236282
throw new Error(`Failed to parse all installed Unity Editors!`);
3628336283
}
36284-
const versionMatches = matches.filter(match => unityVersion.satisfies(match.groups.version));
36285-
core.debug(`Version Matches: ${JSON.stringify(versionMatches, null, 2)}`);
36286-
if (versionMatches.length === 0) {
36287-
return undefined;
36284+
const exactMatch = matches.find(match => match.groups.version === unityVersion.version);
36285+
if (exactMatch) {
36286+
editorPath = exactMatch.groups.editorPath;
3628836287
}
36289-
for (const match of versionMatches) {
36290-
if (!unityVersion.architecture || !match.groups.arch) {
36291-
editorPath = match.groups.editorPath;
36292-
}
36293-
else if (archMap[unityVersion.architecture] === match.groups.arch) {
36294-
editorPath = match.groups.editorPath;
36288+
else {
36289+
const versionMatches = matches.filter(match => unityVersion.satisfies(match.groups.version));
36290+
core.debug(`Version Matches: ${JSON.stringify(versionMatches, null, 2)}`);
36291+
if (versionMatches.length === 0) {
36292+
return undefined;
3629536293
}
36296-
else if (unityVersion.architecture && match.groups.editorPath.toLowerCase().includes(`-${unityVersion.architecture.toLowerCase()}`)) {
36297-
editorPath = match.groups.editorPath;
36294+
for (const match of versionMatches) {
36295+
if (!unityVersion.architecture || !match.groups.arch) {
36296+
editorPath = match.groups.editorPath;
36297+
}
36298+
else if (archMap[unityVersion.architecture] === match.groups.arch) {
36299+
editorPath = match.groups.editorPath;
36300+
}
36301+
else if (unityVersion.architecture && match.groups.editorPath.toLowerCase().includes(`-${unityVersion.architecture.toLowerCase()}`)) {
36302+
editorPath = match.groups.editorPath;
36303+
}
3629836304
}
3629936305
}
3630036306
}
@@ -36330,7 +36336,7 @@ async function checkInstalledEditors(unityVersion, failOnEmpty, installPath = un
3633036336
async function checkEditorModules(editorPath, unityVersion, modules) {
3633136337
let args = ['install-modules', '--version', unityVersion.version];
3633236338
if (unityVersion.architecture) {
36333-
args.push('-a', unityVersion.architecture);
36339+
args.push('-a', unityVersion.architecture.toLowerCase());
3633436340
}
3633536341
for (const module of modules) {
3633636342
args.push('-m', module);
@@ -36456,31 +36462,48 @@ class UnityVersion {
3645636462
return semver.compare(this.semVer, '2021.0.0', true) >= 0;
3645736463
}
3645836464
findMatch(versions) {
36459-
const validReleases = versions
36460-
.map(release => semver.coerce(release))
36461-
.filter(release => release && semver.satisfies(release, `^${this.semVer}`))
36462-
.sort((a, b) => semver.compare(b, a));
36463-
core.debug(`Searching for ${this.version}:`);
36464-
validReleases.forEach(release => {
36465-
core.debug(` > ${release}`);
36465+
const exactMatch = versions.find(r => {
36466+
const match = r.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)/);
36467+
return match && match.groups && match.groups.version === this.version;
3646636468
});
36467-
for (const release of validReleases) {
36468-
if (!release) {
36469-
continue;
36470-
}
36471-
const originalRelease = versions.find(r => r.includes(release.version));
36472-
if (!originalRelease) {
36473-
continue;
36474-
}
36475-
const match = originalRelease.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)\s*(?:\((?<arch>Apple silicon|Intel)\))?/);
36476-
if (!(match && match.groups && match.groups.version)) {
36477-
continue;
36478-
}
36479-
if ((this.version.includes('a') && match.groups.version.includes('a')) ||
36480-
(this.version.includes('b') && match.groups.version.includes('b')) ||
36481-
match.groups.version.includes('f')) {
36482-
core.debug(`Found Unity ${match.groups.version}`);
36483-
return new UnityVersion(match.groups.version, null, this.architecture);
36469+
if (exactMatch) {
36470+
core.debug(`Exact match found for ${this.version}`);
36471+
return new UnityVersion(this.version, null, this.architecture);
36472+
}
36473+
const versionParts = this.version.match(/^(\d+)\.(\d+)\.(\d+)/);
36474+
let minorIsZero = false, patchIsZero = false;
36475+
if (versionParts) {
36476+
const [, , minor, patch] = versionParts;
36477+
minorIsZero = minor === '0';
36478+
patchIsZero = patch === '0';
36479+
}
36480+
if (minorIsZero && patchIsZero) {
36481+
const validReleases = versions
36482+
.map(release => semver.coerce(release))
36483+
.filter(release => release && semver.satisfies(release, `^${this.semVer}`))
36484+
.sort((a, b) => semver.compare(b, a));
36485+
core.debug(`Searching for fallback match for ${this.version}:`);
36486+
validReleases.forEach(release => {
36487+
core.debug(` > ${release}`);
36488+
});
36489+
for (const release of validReleases) {
36490+
if (!release) {
36491+
continue;
36492+
}
36493+
const originalRelease = versions.find(r => r.includes(release.version));
36494+
if (!originalRelease) {
36495+
continue;
36496+
}
36497+
const match = originalRelease.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)\s*(?:\((?<arch>Apple silicon|Intel)\))?/);
36498+
if (!(match && match.groups && match.groups.version)) {
36499+
continue;
36500+
}
36501+
if ((this.version.includes('a') && match.groups.version.includes('a')) ||
36502+
(this.version.includes('b') && match.groups.version.includes('b')) ||
36503+
match.groups.version.includes('f')) {
36504+
core.debug(`Found fallback Unity ${match.groups.version}`);
36505+
return new UnityVersion(match.groups.version, null, this.architecture);
36506+
}
3648436507
}
3648536508
}
3648636509
core.debug(`No matching Unity version found for ${this.version}`);

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-unityhub-macos.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ if [ -z "${volumes}" ]; then
2424
fi
2525
echo "Mounted volumes:"
2626
echo "${volumes}"
27-
volume=$(echo "${volumes}" | grep -o "/Volumes/Unity Hub.*-${cpuArch}" | head -n1)
27+
# can be "/Volumes/Unity Hub 3.13.1-arm64" or "/Volumes/Unity Hub 3.13.1"
28+
volume=$(echo "${volumes}" | grep -o "/Volumes/Unity Hub.*" | head -n1)
2829
if [ -z "${volume}" ]; then
29-
echo "Failed to mount ${downloadPath}"
30+
hdiutil unmount "${volumes}" -quiet
31+
echo "Failed to find Unity Hub volume in ${volumes}"
3032
exit 1
3133
fi
3234
appPath=$(find "${volume}" -name "*.app" | head -n1)

dist/unity-editor-installer.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ try {
3939
Get-ChildItem -Path "$targetPath" -Recurse | ForEach-Object {
4040
Write-Host $_.FullName
4141
}
42-
} catch {
42+
}
43+
catch {
4344
Write-Host "Error: Failed to start Unity installer."
4445
exit 1
45-
} finally {
46+
}
47+
finally {
4648
Remove-Item -Path "$installerPath" -Force
4749
Write-Host "::endgroup::"
4850
}

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.1",
3+
"version": "1.2.2",
44
"description": "A GitHub action for setting up the Unity Game Engine for CI/CD workflows.",
55
"author": "RageAgainstThePixel",
66
"license": "MIT",

src/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function ValidateInputs(): Promise<[UnityVersion[], string[], strin
1919
break;
2020
}
2121
if (architecture) {
22-
core.info(`architecture:\n > ${architecture.toLocaleLowerCase()}`);
22+
core.info(`architecture:\n > ${architecture.toLowerCase()}`);
2323
}
2424
const buildTargets = getArrayInput('build-targets');
2525
core.info(`modules:`);

src/install-unityhub-macos.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ if [ -z "${volumes}" ]; then
2424
fi
2525
echo "Mounted volumes:"
2626
echo "${volumes}"
27-
volume=$(echo "${volumes}" | grep -o "/Volumes/Unity Hub.*-${cpuArch}" | head -n1)
27+
# can be "/Volumes/Unity Hub 3.13.1-arm64" or "/Volumes/Unity Hub 3.13.1"
28+
volume=$(echo "${volumes}" | grep -o "/Volumes/Unity Hub.*" | head -n1)
2829
if [ -z "${volume}" ]; then
29-
echo "Failed to mount ${downloadPath}"
30+
hdiutil unmount "${volumes}" -quiet
31+
echo "Failed to find Unity Hub volume in ${volumes}"
3032
exit 1
3133
fi
3234
appPath=$(find "${volume}" -name "*.app" | head -n1)

src/unity-editor-installer.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ try {
3939
Get-ChildItem -Path "$targetPath" -Recurse | ForEach-Object {
4040
Write-Host $_.FullName
4141
}
42-
} catch {
42+
}
43+
catch {
4344
Write-Host "Error: Failed to start Unity installer."
4445
exit 1
45-
} finally {
46+
}
47+
finally {
4648
Remove-Item -Path "$installerPath" -Force
4749
Write-Host "::endgroup::"
4850
}

src/unity-hub.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,8 @@ const retryErrorMessages = [
276276

277277
export async function UnityEditor(unityVersion: UnityVersion, modules: string[]): Promise<string> {
278278
core.info(`Getting release info for Unity ${unityVersion.toString()}...`);
279-
if (!unityVersion.isLegacy()) {
279+
let editorPath = await checkInstalledEditors(unityVersion, false);
280+
if (!unityVersion.isLegacy() && !editorPath) {
280281
try {
281282
const releases = await getLatestHubReleases();
282283
unityVersion = unityVersion.findMatch(releases);
@@ -287,7 +288,6 @@ export async function UnityEditor(unityVersion: UnityVersion, modules: string[])
287288
unityVersion = await fallbackVersionLookup(unityVersion);
288289
}
289290
}
290-
let editorPath: string = await checkInstalledEditors(unityVersion, false);
291291
let installPath: string | null = null;
292292
if (!editorPath) {
293293
try {
@@ -373,7 +373,7 @@ async function installUnity(unityVersion: UnityVersion, modules: string[]): Prom
373373
args.push('--changeset', unityVersion.changeset);
374374
}
375375
if (unityVersion.architecture) {
376-
args.push('-a', unityVersion.architecture.toLocaleLowerCase());
376+
args.push('-a', unityVersion.architecture.toLowerCase());
377377
}
378378
if (modules.length > 0) {
379379
for (const module of modules) {
@@ -449,23 +449,30 @@ async function checkInstalledEditors(unityVersion: UnityVersion, failOnEmpty: bo
449449
if (paths.length !== matches.length) {
450450
throw new Error(`Failed to parse all installed Unity Editors!`);
451451
}
452-
const versionMatches = matches.filter(match => unityVersion.satisfies(match.groups.version));
453-
core.debug(`Version Matches: ${JSON.stringify(versionMatches, null, 2)}`);
454-
if (versionMatches.length === 0) {
455-
return undefined;
456-
}
457-
for (const match of versionMatches) {
458-
// If no architecture is set, or no arch in match, accept the version match
459-
if (!unityVersion.architecture || !match.groups.arch) {
460-
editorPath = match.groups.editorPath;
461-
}
462-
// If architecture is set and present in match, check for match
463-
else if (archMap[unityVersion.architecture] === match.groups.arch) {
464-
editorPath = match.groups.editorPath;
452+
// Prefer exact version match first
453+
const exactMatch = matches.find(match => match.groups.version === unityVersion.version);
454+
if (exactMatch) {
455+
editorPath = exactMatch.groups.editorPath;
456+
} else {
457+
// Fallback: semver satisfies
458+
const versionMatches = matches.filter(match => unityVersion.satisfies(match.groups.version));
459+
core.debug(`Version Matches: ${JSON.stringify(versionMatches, null, 2)}`);
460+
if (versionMatches.length === 0) {
461+
return undefined;
465462
}
466-
// Fallback: check if editorPath includes architecture string (case-insensitive)
467-
else if (unityVersion.architecture && match.groups.editorPath.toLowerCase().includes(`-${unityVersion.architecture.toLowerCase()}`)) {
468-
editorPath = match.groups.editorPath;
463+
for (const match of versionMatches) {
464+
// If no architecture is set, or no arch in match, accept the version match
465+
if (!unityVersion.architecture || !match.groups.arch) {
466+
editorPath = match.groups.editorPath;
467+
}
468+
// If architecture is set and present in match, check for match
469+
else if (archMap[unityVersion.architecture] === match.groups.arch) {
470+
editorPath = match.groups.editorPath;
471+
}
472+
// Fallback: check if editorPath includes architecture string (case-insensitive)
473+
else if (unityVersion.architecture && match.groups.editorPath.toLowerCase().includes(`-${unityVersion.architecture.toLowerCase()}`)) {
474+
editorPath = match.groups.editorPath;
475+
}
469476
}
470477
}
471478
}
@@ -499,7 +506,7 @@ async function checkInstalledEditors(unityVersion: UnityVersion, failOnEmpty: bo
499506
async function checkEditorModules(editorPath: string, unityVersion: UnityVersion, modules: string[]): Promise<[string[], string[]]> {
500507
let args = ['install-modules', '--version', unityVersion.version];
501508
if (unityVersion.architecture) {
502-
args.push('-a', unityVersion.architecture);
509+
args.push('-a', unityVersion.architecture.toLowerCase());
503510
}
504511
for (const module of modules) {
505512
args.push('-m', module);

0 commit comments

Comments
 (0)