Skip to content

Commit df5fb35

Browse files
unity-setup@v1.2.2 (#29)
- fix version matching
1 parent b984cc9 commit df5fb35

6 files changed

Lines changed: 91 additions & 54 deletions

File tree

dist/index.js

Lines changed: 45 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {
@@ -36330,7 +36330,7 @@ async function checkInstalledEditors(unityVersion, failOnEmpty, installPath = un
3633036330
async function checkEditorModules(editorPath, unityVersion, modules) {
3633136331
let args = ['install-modules', '--version', unityVersion.version];
3633236332
if (unityVersion.architecture) {
36333-
args.push('-a', unityVersion.architecture);
36333+
args.push('-a', unityVersion.architecture.toLowerCase());
3633436334
}
3633536335
for (const module of modules) {
3633636336
args.push('-m', module);
@@ -36456,31 +36456,48 @@ class UnityVersion {
3645636456
return semver.compare(this.semVer, '2021.0.0', true) >= 0;
3645736457
}
3645836458
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}`);
36459+
const exactMatch = versions.find(r => {
36460+
const match = r.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)/);
36461+
return match && match.groups && match.groups.version === this.version;
3646636462
});
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);
36463+
if (exactMatch) {
36464+
core.debug(`Exact match found for ${this.version}`);
36465+
return new UnityVersion(this.version, null, this.architecture);
36466+
}
36467+
const versionParts = this.version.match(/^(\d+)\.(\d+)\.(\d+)/);
36468+
let minorIsZero = false, patchIsZero = false;
36469+
if (versionParts) {
36470+
const [, , minor, patch] = versionParts;
36471+
minorIsZero = minor === '0';
36472+
patchIsZero = patch === '0';
36473+
}
36474+
if (minorIsZero && patchIsZero) {
36475+
const validReleases = versions
36476+
.map(release => semver.coerce(release))
36477+
.filter(release => release && semver.satisfies(release, `^${this.semVer}`))
36478+
.sort((a, b) => semver.compare(b, a));
36479+
core.debug(`Searching for fallback match for ${this.version}:`);
36480+
validReleases.forEach(release => {
36481+
core.debug(` > ${release}`);
36482+
});
36483+
for (const release of validReleases) {
36484+
if (!release) {
36485+
continue;
36486+
}
36487+
const originalRelease = versions.find(r => r.includes(release.version));
36488+
if (!originalRelease) {
36489+
continue;
36490+
}
36491+
const match = originalRelease.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)\s*(?:\((?<arch>Apple silicon|Intel)\))?/);
36492+
if (!(match && match.groups && match.groups.version)) {
36493+
continue;
36494+
}
36495+
if ((this.version.includes('a') && match.groups.version.includes('a')) ||
36496+
(this.version.includes('b') && match.groups.version.includes('b')) ||
36497+
match.groups.version.includes('f')) {
36498+
core.debug(`Found fallback Unity ${match.groups.version}`);
36499+
return new UnityVersion(match.groups.version, null, this.architecture);
36500+
}
3648436501
}
3648536502
}
3648636503
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.

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": "Buildalon",
66
"license": "MIT",

src/unity-hub.ts

Lines changed: 4 additions & 4 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) {
@@ -499,7 +499,7 @@ async function checkInstalledEditors(unityVersion: UnityVersion, failOnEmpty: bo
499499
async function checkEditorModules(editorPath: string, unityVersion: UnityVersion, modules: string[]): Promise<[string[], string[]]> {
500500
let args = ['install-modules', '--version', unityVersion.version];
501501
if (unityVersion.architecture) {
502-
args.push('-a', unityVersion.architecture);
502+
args.push('-a', unityVersion.architecture.toLowerCase());
503503
}
504504
for (const module of modules) {
505505
args.push('-m', module);

src/unity-version.ts

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,45 @@ export class UnityVersion {
3838
}
3939

4040
findMatch(versions: string[]): UnityVersion {
41-
const validReleases = versions
42-
.map(release => semver.coerce(release))
43-
.filter(release => release && semver.satisfies(release, `^${this.semVer}`))
44-
.sort((a, b) => semver.compare(b, a));
45-
core.debug(`Searching for ${this.version}:`);
46-
validReleases.forEach(release => {
47-
core.debug(` > ${release}`);
41+
// Try exact match first
42+
const exactMatch = versions.find(r => {
43+
const match = r.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)/);
44+
return match && match.groups && match.groups.version === this.version;
4845
});
49-
for (const release of validReleases) {
50-
if (!release) { continue; }
51-
const originalRelease = versions.find(r => r.includes(release.version));
52-
if (!originalRelease) { continue; }
53-
const match = originalRelease.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)\s*(?:\((?<arch>Apple silicon|Intel)\))?/);
54-
if (!(match && match.groups && match.groups.version)) { continue; }
55-
if ((this.version.includes('a') && match.groups.version.includes('a')) ||
56-
(this.version.includes('b') && match.groups.version.includes('b')) ||
57-
match.groups.version.includes('f')) {
58-
core.debug(`Found Unity ${match.groups.version}`);
59-
return new UnityVersion(match.groups.version, null, this.architecture);
46+
if (exactMatch) {
47+
core.debug(`Exact match found for ${this.version}`);
48+
return new UnityVersion(this.version, null, this.architecture);
49+
}
50+
51+
// Only fall back to caret range if both minor and patch are 0 (ignoring suffixes)
52+
const versionParts = this.version.match(/^(\d+)\.(\d+)\.(\d+)/);
53+
let minorIsZero = false, patchIsZero = false;
54+
if (versionParts) {
55+
const [, , minor, patch] = versionParts;
56+
minorIsZero = minor === '0';
57+
patchIsZero = patch === '0';
58+
}
59+
if (minorIsZero && patchIsZero) {
60+
const validReleases = versions
61+
.map(release => semver.coerce(release))
62+
.filter(release => release && semver.satisfies(release, `^${this.semVer}`))
63+
.sort((a, b) => semver.compare(b, a));
64+
core.debug(`Searching for fallback match for ${this.version}:`);
65+
validReleases.forEach(release => {
66+
core.debug(` > ${release}`);
67+
});
68+
for (const release of validReleases) {
69+
if (!release) { continue; }
70+
const originalRelease = versions.find(r => r.includes(release.version));
71+
if (!originalRelease) { continue; }
72+
const match = originalRelease.match(/(?<version>\d+\.\d+\.\d+[abcfpx]?\d*)\s*(?:\((?<arch>Apple silicon|Intel)\))?/);
73+
if (!(match && match.groups && match.groups.version)) { continue; }
74+
if ((this.version.includes('a') && match.groups.version.includes('a')) ||
75+
(this.version.includes('b') && match.groups.version.includes('b')) ||
76+
match.groups.version.includes('f')) {
77+
core.debug(`Found fallback Unity ${match.groups.version}`);
78+
return new UnityVersion(match.groups.version, null, this.architecture);
79+
}
6080
}
6181
}
6282
core.debug(`No matching Unity version found for ${this.version}`);

0 commit comments

Comments
 (0)