Skip to content

Commit ea1ef9f

Browse files
unity-setup@v1.0.18 (#22)
- add support for 2021.x arm unity editor installers - attempt to get changeset for version before installing
1 parent 404cae1 commit ea1ef9f

File tree

6 files changed

+55
-16
lines changed

6 files changed

+55
-16
lines changed

.github/workflows/validate.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ concurrency:
1515
cancel-in-progress: true
1616
jobs:
1717
validate:
18+
permissions:
19+
contents: read
1820
env:
1921
UNITY_EDITORS: '' # set by the unity-setup action
2022
UNITY_HUB_PATH: '' # set by the unity-setup action

dist/index.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34553,14 +34553,18 @@ async function execUnityHub(args) {
3455334553
}
3455434554
async function Unity(version, changeset, architecture, modules) {
3455534555
if (os.arch() == 'arm64' && !isArmCompatible(version)) {
34556-
core.info(`Unity ${version} does not support arm64 architecture, falling back to x86_64`);
34556+
core.warning(`Unity ${version} does not support arm64 architecture, falling back to x86_64`);
3455734557
architecture = 'x86_64';
3455834558
}
3455934559
if (!changeset) {
3456034560
const [latestVersion, latestChangeset] = await getLatestRelease(version, architecture === 'arm64');
3456134561
version = latestVersion;
3456234562
changeset = latestChangeset;
3456334563
}
34564+
if (!changeset) {
34565+
core.debug(`Fetching changeset for Unity ${version}...`);
34566+
changeset = await getChangeset(version);
34567+
}
3456434568
let editorPath = await checkInstalledEditors(version, architecture, false);
3456534569
if (!editorPath) {
3456634570
try {
@@ -34624,7 +34628,7 @@ async function getLatestRelease(version, isSilicon) {
3462434628
return [match.groups.version, undefined];
3462534629
}
3462634630
}
34627-
core.info(`Searching for Unity ${version} release...`);
34631+
core.debug(`Searching for Unity ${version} release from online releases list...`);
3462834632
const baseUrl = `https://public-cdn.cloud.unity3d.com/hub/prod`;
3462934633
const url = isSilicon
3463034634
? `${baseUrl}/releases-silicon.json`
@@ -34646,16 +34650,15 @@ async function parseReleases(version, data) {
3464634650
const match = release.downloadUrl.match(/download_unity\/(?<changeset>[a-zA-Z0-9]+)\//);
3464734651
if (match && match.groups && match.groups.changeset) {
3464834652
const changeset = match.groups.changeset;
34649-
core.info(`Found Unity ${release.version} (${changeset})`);
34653+
core.debug(`Found Unity ${release.version} (${changeset})`);
3465034654
return [release.version, changeset];
3465134655
}
3465234656
}
3465334657
}
3465434658
throw new Error(`Failed to find Unity ${version} release. Please provide a valid changeset.`);
3465534659
}
3465634660
async function installUnity(version, changeset, architecture, modules) {
34657-
const changesetStr = changeset ? ` (${changeset})` : '';
34658-
core.startGroup(`Installing Unity ${version}${changesetStr}...`);
34661+
core.startGroup(`Installing Unity ${version} (${changeset})...`);
3465934662
const args = ['install', '--version', version];
3466034663
if (changeset) {
3466134664
args.push('--changeset', changeset);
@@ -34685,7 +34688,7 @@ function isArmCompatible(version) {
3468534688
if (semVersion.major < 2021) {
3468634689
return false;
3468734690
}
34688-
return semver.compare(semVersion, '2021.1.0f1', true) >= 0;
34691+
return semver.compare(semVersion, '2021.0.0', true) >= 0;
3468934692
}
3469034693
async function checkInstalledEditors(version, architecture, failOnEmpty = true) {
3469134694
const output = await ListInstalledEditors();
@@ -34769,6 +34772,21 @@ async function getModulesContent(modulesPath) {
3476934772
const modulesContent = await (0, utility_1.ReadFileContents)(modulesPath);
3477034773
return JSON.parse(modulesContent);
3477134774
}
34775+
async function getChangeset(version) {
34776+
version = version.split(/[abf]/)[0];
34777+
const url = `https://unity.com/releases/editor/whats-new/${version}`;
34778+
const response = await fetch(url);
34779+
if (!response.ok) {
34780+
throw new Error(`Failed to fetch changeset [${response.status}] "${url}"`);
34781+
}
34782+
const data = await response.text();
34783+
const match = data.match(/unityhub:\/\/(?<version>\d+\.\d+\.\d+[fab]?\d*)\/(?<changeset>[a-zA-Z0-9]+)/);
34784+
if (match && match.groups && match.groups.changeset) {
34785+
return match.groups.changeset;
34786+
}
34787+
core.error(`Failed to find changeset for Unity ${version}`);
34788+
return null;
34789+
}
3477234790
async function removePath(targetPath) {
3477334791
core.startGroup(`deleting ${targetPath}...`);
3477434792
try {

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.0.17",
3+
"version": "1.0.18",
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: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,18 @@ async function execUnityHub(args: string[]): Promise<string> {
226226

227227
export async function Unity(version: string, changeset: string, architecture: string, modules: string[]): Promise<string> {
228228
if (os.arch() == 'arm64' && !isArmCompatible(version)) {
229-
core.info(`Unity ${version} does not support arm64 architecture, falling back to x86_64`);
229+
core.warning(`Unity ${version} does not support arm64 architecture, falling back to x86_64`);
230230
architecture = 'x86_64';
231231
}
232232
if (!changeset) {
233233
const [latestVersion, latestChangeset] = await getLatestRelease(version, architecture === 'arm64');
234234
version = latestVersion;
235235
changeset = latestChangeset
236236
}
237+
if (!changeset) {
238+
core.debug(`Fetching changeset for Unity ${version}...`);
239+
changeset = await getChangeset(version);
240+
}
237241
let editorPath = await checkInstalledEditors(version, architecture, false);
238242
if (!editorPath) {
239243
try {
@@ -293,7 +297,7 @@ async function getLatestRelease(version: string, isSilicon: boolean): Promise<[s
293297
return [match.groups.version, undefined];
294298
}
295299
}
296-
core.info(`Searching for Unity ${version} release...`);
300+
core.debug(`Searching for Unity ${version} release from online releases list...`);
297301
const baseUrl = `https://public-cdn.cloud.unity3d.com/hub/prod`;
298302
const url = isSilicon
299303
? `${baseUrl}/releases-silicon.json`
@@ -316,7 +320,7 @@ async function parseReleases(version: string, data: string): Promise<[string, st
316320
const match = release.downloadUrl.match(/download_unity\/(?<changeset>[a-zA-Z0-9]+)\//);
317321
if (match && match.groups && match.groups.changeset) {
318322
const changeset = match.groups.changeset;
319-
core.info(`Found Unity ${release.version} (${changeset})`);
323+
core.debug(`Found Unity ${release.version} (${changeset})`);
320324
return [release.version, changeset];
321325
}
322326
}
@@ -325,8 +329,7 @@ async function parseReleases(version: string, data: string): Promise<[string, st
325329
}
326330

327331
async function installUnity(version: string, changeset: string, architecture: string, modules: string[]): Promise<void> {
328-
const changesetStr = changeset ? ` (${changeset})` : '';
329-
core.startGroup(`Installing Unity ${version}${changesetStr}...`);
332+
core.startGroup(`Installing Unity ${version} (${changeset})...`);
330333
const args = ['install', '--version', version];
331334
if (changeset) {
332335
args.push('--changeset', changeset);
@@ -355,7 +358,7 @@ export async function ListInstalledEditors(): Promise<string> {
355358
function isArmCompatible(version: string): boolean {
356359
const semVersion = semver.coerce(version);
357360
if (semVersion.major < 2021) { return false; }
358-
return semver.compare(semVersion, '2021.1.0f1', true) >= 0;
361+
return semver.compare(semVersion, '2021.0.0', true) >= 0;
359362
}
360363

361364
async function checkInstalledEditors(version: string, architecture: string, failOnEmpty = true): Promise<string> {
@@ -444,6 +447,22 @@ async function getModulesContent(modulesPath: string): Promise<any> {
444447
return JSON.parse(modulesContent);
445448
}
446449

450+
async function getChangeset(version: string): Promise<string | null> {
451+
version = version.split(/[abf]/)[0];
452+
const url = `https://unity.com/releases/editor/whats-new/${version}`;
453+
const response = await fetch(url);
454+
if (!response.ok) {
455+
throw new Error(`Failed to fetch changeset [${response.status}] "${url}"`);
456+
}
457+
const data = await response.text();
458+
const match = data.match(/unityhub:\/\/(?<version>\d+\.\d+\.\d+[fab]?\d*)\/(?<changeset>[a-zA-Z0-9]+)/);
459+
if (match && match.groups && match.groups.changeset) {
460+
return match.groups.changeset;
461+
}
462+
core.error(`Failed to find changeset for Unity ${version}`);
463+
return null;
464+
}
465+
447466
async function removePath(targetPath: string): Promise<void> {
448467
core.startGroup(`deleting ${targetPath}...`);
449468
try {

0 commit comments

Comments
 (0)