Skip to content
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

unity-setup@v1.0.9 #10

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-13, macos-latest]
unity-versions:
- 'None'
- None
- 2019.4.40f1 (ffc62b691db5)
- 2020.3.48f1 (b805b124c6b7)
- 2021.3.41f1 (6c5a9e20c022)
- 2022.3.40f1 (cbdda657d2f0)
- 6000.0.13f1 (53a692e3fca9)
- 2020.x
- 2021.3.x
- 2022.3
- 6000
include:
- os: ubuntu-latest
build-targets: StandaloneLinux64, Android, iOS
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-13, macos-latest]
unity-versions:
- 'in version file'
- None
- 2019.4.40f1 (ffc62b691db5)
- 2020.3.48f1 (b805b124c6b7)
- 2021.3.41f1 (6c5a9e20c022)
- 2022.3.40f1 (cbdda657d2f0)
- 6000.0.13f1 (53a692e3fca9)
- 2020.x
- 2021.3.x
- 2022.3
- 6000
include:
- os: ubuntu-latest
build-targets: StandaloneLinux64, Android, iOS
Expand Down
82 changes: 74 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34278,7 +34278,8 @@ async function ValidateInputs() {
versions.sort(([a], [b]) => semver.compare(a, b, true));
core.info(`Unity Versions:`);
for (const [version, changeset] of versions) {
core.info(` > ${version} (${changeset})`);
const changesetStr = changeset ? ` (${changeset})` : '';
core.info(` > ${version}${changesetStr}`);
}
return [versions, architecture, modules, unityProjectPath];
}
Expand Down Expand Up @@ -34397,10 +34398,15 @@ function getUnityVersionsFromInput() {
if (!inputVersions || inputVersions.length == 0) {
return versions;
}
const versionRegEx = new RegExp(/(?<version>(?:(?<major>\d+)\.)?(?:(?<minor>\d+)\.)?(?:(?<patch>\d+[fab]\d+)\b))\s?(?:\((?<changeset>\w+)\))?/g);
const versionRegEx = new RegExp(/(?<version>(?:(?<major>\d+)\.?)(?:(?<minor>\d+)\.?)?(?:(?<patch>\d+[fab]\d+)?\b))\s?(?:\((?<changeset>\w+)\))?/g);
const matches = Array.from(inputVersions.matchAll(versionRegEx));
core.debug(`Unity Versions from input:`);
for (const match of matches) {
versions.push([match.groups.version, match.groups.changeset]);
const version = match.groups.version.replace(/\.$/, '');
const changeset = match.groups.changeset;
const changesetStr = changeset ? ` (${changeset})` : '';
core.debug(`${version}${changesetStr}`);
versions.push([version, changeset]);
}
return versions;
}
Expand Down Expand Up @@ -34784,6 +34790,11 @@ async function Unity(version, changeset, architecture, modules) {
core.info(`Unity ${version} does not support arm64 architecture, falling back to x86_64`);
architecture = 'x86_64';
}
if (!changeset) {
const [latestVersion, latestChangeset] = await getLatestRelease(version, architecture === 'arm64');
version = latestVersion;
changeset = latestChangeset;
}
let editorPath = await checkInstalledEditors(version, architecture, false);
if (!editorPath) {
await installUnity(version, changeset, architecture, modules);
Expand All @@ -34793,7 +34804,8 @@ async function Unity(version, changeset, architecture, modules) {
core.info(`Unity Editor Path:\n > "${editorPath}"`);
core.addPath(editorPath);
try {
core.startGroup(`Checking installed modules for Unity ${version} (${changeset})...`);
const changesetStr = changeset ? ` (${changeset})` : '';
core.startGroup(`Checking installed modules for Unity ${version}${changesetStr}...`);
const [installedModules, additionalModules] = await checkEditorModules(editorPath, version, architecture, modules);
if (installedModules && installedModules.length > 0) {
core.info(`Installed Modules:`);
Expand All @@ -34813,9 +34825,59 @@ async function Unity(version, changeset, architecture, modules) {
}
return editorPath;
}
async function getLatestRelease(version, isSilicon) {
const releases = (await execUnityHub([`editors`, `--releases`])).split('\n');
for (const release of releases) {
if (!release || release.trim().length === 0) {
continue;
}
const semVersion = semver.coerce(version);
const semVerRelease = semver.coerce(release);
core.debug(`Checking ${semVersion} against ${semVerRelease}`);
if (semver.satisfies(semVerRelease, `^${semVersion}`)) {
const match = release.match(/(?<version>\d+\.\d+\.\d+[fab]?\d*)\s*(?:\((?<arch>Apple silicon|Intel)\))?/);
if (match && match.groups && match.groups.version) {
core.info(`Found Unity ${match.groups.version}`);
return [match.groups.version, undefined];
}
}
}
core.info(`Searching for Unity ${version} release...`);
const baseUrl = `https://public-cdn.cloud.unity3d.com/hub/prod`;
const url = isSilicon
? `${baseUrl}/releases-silicon.json`
: `${baseUrl}/releases-${process.platform}.json`;
const response = await fetch(url);
const data = await response.text();
return await parseReleases(version, data);
}
async function parseReleases(version, data) {
const releases = JSON.parse(data);
core.debug(`Found ${releases.official.length} official releases...`);
releases.official.sort((a, b) => semver.compare(a.version, b.version, true));
for (const release of releases.official) {
const semVersion = semver.coerce(version);
const semVerRelease = semver.coerce(release.version);
core.debug(`Checking ${semVersion} against ${semVerRelease}`);
if (semver.satisfies(semVerRelease, `^${semVersion}`)) {
core.debug(`Found Unity ${release.version} release.`);
const match = release.downloadUrl.match(/download_unity\/(?<changeset>[a-zA-Z0-9]+)\//);
if (match && match.groups && match.groups.changeset) {
const changeset = match.groups.changeset;
core.info(`Found Unity ${release.version} (${changeset})`);
return [release.version, changeset];
}
}
}
throw new Error(`Failed to find Unity ${version} release. Please provide a valid changeset.`);
}
async function installUnity(version, changeset, architecture, modules) {
core.startGroup(`Installing Unity ${version} (${changeset})...`);
const args = ['install', '--version', version, '--changeset', changeset];
const changesetStr = changeset ? ` (${changeset})` : '';
core.startGroup(`Installing Unity ${version}${changesetStr}...`);
const args = ['install', '--version', version];
if (changeset) {
args.push('--changeset', changeset);
}
if (architecture) {
args.push('-a', architecture);
}
Expand All @@ -34837,7 +34899,11 @@ async function ListInstalledEditors() {
return await execUnityHub(['editors', '-i']);
}
function isArmCompatible(version) {
return semver.compare(version, '2021.1.0f1', true) >= 0;
const semVersion = semver.coerce(version);
if (semVersion.major < 2021) {
return false;
}
return semver.compare(semVersion, '2021.1.0f1', true) >= 0;
}
async function checkInstalledEditors(version, architecture, failOnEmpty = true) {
const output = await ListInstalledEditors();
Expand Down Expand Up @@ -45419,7 +45485,7 @@ const main = async () => {
process.exit(0);
}
catch (error) {
core.setFailed(error);
core.setFailed(error.stack);
StephenHodgson marked this conversation as resolved.
Show resolved Hide resolved
}
};
main();
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-setup",
"version": "1.0.8",
"version": "1.0.9",
"description": "A GitHub action for setting up the Unity Game Engine for CI/CD workflows.",
"author": "Buildalon",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const main = async () => {
core.info('Unity Setup Complete!');
process.exit(0);
} catch (error) {
core.setFailed(error);
core.setFailed(error.stack);
}
}

Expand Down
12 changes: 9 additions & 3 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ async function ValidateInputs(): Promise<[string[][], string | undefined, string
versions.sort(([a], [b]) => semver.compare(a, b, true));
core.info(`Unity Versions:`);
for (const [version, changeset] of versions) {
core.info(` > ${version} (${changeset})`);
const changesetStr = changeset ? ` (${changeset})` : '';
core.info(` > ${version}${changesetStr}`);
}
return [versions, architecture, modules, unityProjectPath];
}
Expand Down Expand Up @@ -174,10 +175,15 @@ function getUnityVersionsFromInput(): string[][] {
if (!inputVersions || inputVersions.length == 0) {
return versions;
}
const versionRegEx = new RegExp(/(?<version>(?:(?<major>\d+)\.)?(?:(?<minor>\d+)\.)?(?:(?<patch>\d+[fab]\d+)\b))\s?(?:\((?<changeset>\w+)\))?/g);
const versionRegEx = new RegExp(/(?<version>(?:(?<major>\d+)\.?)(?:(?<minor>\d+)\.?)?(?:(?<patch>\d+[fab]\d+)?\b))\s?(?:\((?<changeset>\w+)\))?/g);
const matches = Array.from(inputVersions.matchAll(versionRegEx));
core.debug(`Unity Versions from input:`);
for (const match of matches) {
versions.push([match.groups.version, match.groups.changeset]);
const version = match.groups.version.replace(/\.$/, '');
const changeset = match.groups.changeset;
const changesetStr = changeset ? ` (${changeset})` : '';
core.debug(`${version}${changesetStr}`);
versions.push([version, changeset]);
}
return versions;
}
Expand Down
66 changes: 62 additions & 4 deletions src/unity-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ async function Unity(version: string, changeset: string, architecture: string, m
core.info(`Unity ${version} does not support arm64 architecture, falling back to x86_64`);
architecture = 'x86_64';
}
if (!changeset) {
const [latestVersion, latestChangeset] = await getLatestRelease(version, architecture === 'arm64');
version = latestVersion;
changeset = latestChangeset
}
let editorPath = await checkInstalledEditors(version, architecture, false);
if (!editorPath) {
await installUnity(version, changeset, architecture, modules);
Expand All @@ -236,7 +241,8 @@ async function Unity(version: string, changeset: string, architecture: string, m
core.info(`Unity Editor Path:\n > "${editorPath}"`);
core.addPath(editorPath);
try {
core.startGroup(`Checking installed modules for Unity ${version} (${changeset})...`);
const changesetStr = changeset ? ` (${changeset})` : '';
core.startGroup(`Checking installed modules for Unity ${version}${changesetStr}...`);
const [installedModules, additionalModules] = await checkEditorModules(editorPath, version, architecture, modules);
if (installedModules && installedModules.length > 0) {
core.info(`Installed Modules:`);
Expand All @@ -256,9 +262,59 @@ async function Unity(version: string, changeset: string, architecture: string, m
return editorPath;
}

async function getLatestRelease(version: string, isSilicon: boolean): Promise<[string, string]> {
const releases = (await execUnityHub([`editors`, `--releases`])).split('\n');
for (const release of releases) {
if (!release || release.trim().length === 0) { continue; }
const semVersion = semver.coerce(version);
const semVerRelease = semver.coerce(release);
core.debug(`Checking ${semVersion} against ${semVerRelease}`);
if (semver.satisfies(semVerRelease, `^${semVersion}`)) {
const match = release.match(/(?<version>\d+\.\d+\.\d+[fab]?\d*)\s*(?:\((?<arch>Apple silicon|Intel)\))?/);
if (match && match.groups && match.groups.version) {
core.info(`Found Unity ${match.groups.version}`);
return [match.groups.version, undefined];
}
}
}
core.info(`Searching for Unity ${version} release...`);
const baseUrl = `https://public-cdn.cloud.unity3d.com/hub/prod`;
const url = isSilicon
? `${baseUrl}/releases-silicon.json`
: `${baseUrl}/releases-${process.platform}.json`;
const response = await fetch(url);
const data = await response.text();
return await parseReleases(version, data);
}

async function parseReleases(version: string, data: string): Promise<[string, string]> {
const releases = JSON.parse(data);
core.debug(`Found ${releases.official.length} official releases...`);
releases.official.sort((a, b) => semver.compare(a.version, b.version, true));
for (const release of releases.official) {
const semVersion = semver.coerce(version);
const semVerRelease = semver.coerce(release.version);
core.debug(`Checking ${semVersion} against ${semVerRelease}`);
if (semver.satisfies(semVerRelease, `^${semVersion}`)) {
core.debug(`Found Unity ${release.version} release.`);
const match = release.downloadUrl.match(/download_unity\/(?<changeset>[a-zA-Z0-9]+)\//);
if (match && match.groups && match.groups.changeset) {
const changeset = match.groups.changeset;
core.info(`Found Unity ${release.version} (${changeset})`);
return [release.version, changeset];
}
}
}
throw new Error(`Failed to find Unity ${version} release. Please provide a valid changeset.`);
}

async function installUnity(version: string, changeset: string, architecture: string, modules: string[]): Promise<void> {
core.startGroup(`Installing Unity ${version} (${changeset})...`);
const args = ['install', '--version', version, '--changeset', changeset];
const changesetStr = changeset ? ` (${changeset})` : '';
core.startGroup(`Installing Unity ${version}${changesetStr}...`);
const args = ['install', '--version', version];
if (changeset) {
args.push('--changeset', changeset);
}
if (architecture) {
args.push('-a', architecture);
}
Expand All @@ -281,7 +337,9 @@ async function ListInstalledEditors(): Promise<string> {
}

function isArmCompatible(version: string): boolean {
return semver.compare(version, '2021.1.0f1', true) >= 0;
const semVersion = semver.coerce(version);
if (semVersion.major < 2021) { return false; }
return semver.compare(semVersion, '2021.1.0f1', true) >= 0;
}

async function checkInstalledEditors(version: string, architecture: string, failOnEmpty = true): Promise<string> {
Expand Down