Skip to content

Commit 0b71929

Browse files
StephenHodgsonjs6pak
authored andcommitted
1 parent dee7efb commit 0b71929

13 files changed

+385
-93
lines changed

.github/workflows/validate.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ jobs:
2727
os: [ubuntu-latest, windows-latest, macos-latest]
2828
unity-version:
2929
- None
30+
- 4.7.2
3031
- 5.6.7f1 (e80cc3114ac1)
3132
- 2020.3
3233
- 2021.3.x
@@ -56,6 +57,9 @@ jobs:
5657
# Exclude Unity 5.x for linux as it is not supported
5758
- os: ubuntu-latest
5859
unity-version: '5.6.7f1 (e80cc3114ac1)'
60+
- os: ubuntu-latest
61+
unity-version: '4.7.2'
62+
modules: None
5963
steps:
6064
- uses: actions/checkout@v4
6165

dist/index.js

Lines changed: 121 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34121,10 +34121,10 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3412134121
exports.ValidateInputs = ValidateInputs;
3412234122
const utility_1 = __nccwpck_require__(5418);
3412334123
const core = __nccwpck_require__(2186);
34124-
const semver = __nccwpck_require__(1383);
3412534124
const path = __nccwpck_require__(1017);
3412634125
const os = __nccwpck_require__(2037);
3412734126
const fs = __nccwpck_require__(7147);
34127+
const unity_version_1 = __nccwpck_require__(5988);
3412834128
async function ValidateInputs() {
3412934129
const modules = [];
3413034130
const architecture = core.getInput('architecture') || getInstallationArch();
@@ -34168,16 +34168,15 @@ async function ValidateInputs() {
3416834168
if (versionFilePath) {
3416934169
core.info(`versionFilePath:\n > "${versionFilePath}"`);
3417034170
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
34171-
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
34171+
const unityVersion = await getUnityVersionFromFile(versionFilePath);
3417234172
if (versions.length === 0) {
34173-
versions.push([unityVersion, changeset]);
34173+
versions.push(unityVersion);
3417434174
}
3417534175
}
34176-
versions.sort(([a], [b]) => semver.compare(a, b, true));
34176+
versions.sort(unity_version_1.UnityVersion.compare);
3417734177
core.info(`Unity Versions:`);
34178-
for (const [version, changeset] of versions) {
34179-
const changesetStr = changeset ? ` (${changeset})` : '';
34180-
core.info(` > ${version}${changesetStr}`);
34178+
for (const unityVersion of versions) {
34179+
core.info(` > ${unityVersion.toString()}`);
3418134180
}
3418234181
let installPath = core.getInput('install-path');
3418334182
if (installPath) {
@@ -34317,7 +34316,7 @@ function getUnityVersionsFromInput() {
3431734316
const changeset = match.groups.changeset;
3431834317
const changesetStr = changeset ? ` (${changeset})` : '';
3431934318
core.debug(`${version}${changesetStr}`);
34320-
versions.push([version, changeset]);
34319+
versions.push(new unity_version_1.UnityVersion(version, changeset));
3432134320
}
3432234321
return versions;
3432334322
}
@@ -34334,7 +34333,7 @@ async function getUnityVersionFromFile(versionFilePath) {
3433434333
if (!match.groups.changeset) {
3433534334
throw Error(`No changeset group found!`);
3433634335
}
34337-
return [match.groups.version, match.groups.changeset];
34336+
return new unity_version_1.UnityVersion(match.groups.version, match.groups.changeset);
3433834337
}
3433934338

3434034339

@@ -34479,6 +34478,7 @@ exports.SetInstallPath = SetInstallPath;
3447934478
exports.Unity = Unity;
3448034479
exports.ListInstalledEditors = ListInstalledEditors;
3448134480
const utility_1 = __nccwpck_require__(5418);
34481+
const unity_version_1 = __nccwpck_require__(5988);
3448234482
const asar = __nccwpck_require__(6561);
3448334483
const core = __nccwpck_require__(2186);
3448434484
const exec = __nccwpck_require__(1514);
@@ -34559,6 +34559,10 @@ async function SetInstallPath(installPath) {
3455934559
await fs.promises.mkdir(installPath, { recursive: true });
3456034560
await execUnityHub(["install-path", "--set", installPath]);
3456134561
}
34562+
async function getInstallPath() {
34563+
const result = await execUnityHub(["install-path", "--get"]);
34564+
return result.trim();
34565+
}
3456234566
async function installUnityHub() {
3456334567
let exitCode = undefined;
3456434568
switch (process.platform) {
@@ -34724,34 +34728,33 @@ const retryErrorMessages = [
3472434728
'Editor already installed in this location',
3472534729
'failed to download. Error given: Request timeout'
3472634730
];
34727-
async function Unity(version, changeset, architecture, modules) {
34728-
if (os.arch() == 'arm64' && !isArmCompatible(version)) {
34729-
core.warning(`Unity ${version} does not support arm64 architecture, falling back to x86_64`);
34731+
async function Unity(unityVersion, architecture, modules) {
34732+
if (os.arch() == 'arm64' && !isArmCompatible(unityVersion.version)) {
34733+
core.info(`Unity ${unityVersion.toString()} does not support arm64 architecture, falling back to x86_64`);
3473034734
architecture = 'x86_64';
3473134735
}
34732-
if (!changeset) {
34733-
core.debug(`Fetching changeset for Unity ${version}...`);
34734-
changeset = await getChangeset(version);
34736+
if (!unityVersion.changeset) {
34737+
core.debug(`Fetching changeset for Unity ${unityVersion.toString()}...`);
34738+
unityVersion = await getChangeset(unityVersion);
3473534739
}
34736-
let editorPath = await checkInstalledEditors(version, architecture, false);
34740+
let editorPath = await checkInstalledEditors(unityVersion.version, architecture, false);
3473734741
if (!editorPath) {
3473834742
try {
34739-
await installUnity(version, changeset, architecture, modules);
34743+
await installUnity(unityVersion, architecture, modules);
3474034744
}
3474134745
catch (error) {
3474234746
if (retryErrorMessages.some(msg => error.message.includes(msg))) {
3474334747
await removePath(editorPath);
34744-
await installUnity(version, changeset, architecture, modules);
34748+
await installUnity(unityVersion, architecture, modules);
3474534749
}
3474634750
}
34747-
editorPath = await checkInstalledEditors(version, architecture);
34751+
editorPath = await checkInstalledEditors(unityVersion.version, architecture);
3474834752
}
3474934753
await fs.promises.access(editorPath, fs.constants.X_OK);
3475034754
core.info(`Unity Editor Path:\n > "${editorPath}"`);
3475134755
try {
34752-
const changesetStr = changeset ? ` (${changeset})` : '';
34753-
core.startGroup(`Checking installed modules for Unity ${version}${changesetStr}...`);
34754-
const [installedModules, additionalModules] = await checkEditorModules(editorPath, version, architecture, modules);
34756+
core.startGroup(`Checking installed modules for Unity ${unityVersion.toString()}...`);
34757+
const [installedModules, additionalModules] = await checkEditorModules(editorPath, unityVersion.version, architecture, modules);
3475534758
if (installedModules && installedModules.length > 0) {
3475634759
core.info(`Installed Modules:`);
3475734760
for (const module of installedModules) {
@@ -34779,37 +34782,89 @@ async function Unity(version, changeset, architecture, modules) {
3477934782
catch (error) {
3478034783
if (error.message.includes(`No modules found`)) {
3478134784
removePath(editorPath);
34782-
await Unity(version, changeset, architecture, modules);
34785+
await Unity(unityVersion, architecture, modules);
3478334786
}
3478434787
}
3478534788
finally {
3478634789
core.endGroup();
3478734790
}
3478834791
return editorPath;
3478934792
}
34790-
async function installUnity(version, changeset, architecture, modules) {
34791-
core.startGroup(`Installing Unity ${version} (${changeset})...`);
34792-
const args = ['install', '--version', version];
34793-
if (changeset) {
34794-
args.push('--changeset', changeset);
34793+
async function parseReleases(version, data) {
34794+
const releases = JSON.parse(data);
34795+
core.debug(`Found ${releases.official.length} official releases...`);
34796+
releases.official.sort((a, b) => semver.compare(a.version, b.version, true));
34797+
for (const release of releases.official) {
34798+
const semVersion = semver.coerce(version);
34799+
const semVerRelease = semver.coerce(release.version);
34800+
core.debug(`Checking ${semVersion} against ${semVerRelease}`);
34801+
if (semver.satisfies(semVerRelease, `^${semVersion}`)) {
34802+
core.debug(`Found Unity ${release.version} release.`);
34803+
const match = release.downloadUrl.match(/download_unity\/(?<changeset>[a-zA-Z0-9]+)\//);
34804+
if (match && match.groups && match.groups.changeset) {
34805+
const changeset = match.groups.changeset;
34806+
core.debug(`Found Unity ${release.version} (${changeset})`);
34807+
return new unity_version_1.UnityVersion(release.version, changeset);
34808+
}
34809+
}
34810+
}
34811+
throw new Error(`Failed to find Unity ${version} release. Please provide a valid changeset.`);
34812+
}
34813+
async function installUnity(unityVersion, architecture, modules) {
34814+
if (semver.major(unityVersion.version, { loose: true }) === 4) {
34815+
return await installUnity4x(unityVersion);
34816+
}
34817+
core.startGroup(`Installing Unity ${unityVersion.toString()}...`);
34818+
const args = ['install', '--version', unityVersion.version];
34819+
if (unityVersion.changeset) {
34820+
args.push('--changeset', unityVersion.changeset);
3479534821
}
3479634822
if (architecture) {
3479734823
args.push('-a', architecture);
3479834824
}
34799-
for (const module of modules) {
34800-
core.info(` > with module: ${module}`);
34801-
args.push('-m', module);
34825+
if (modules.length > 0) {
34826+
for (const module of modules) {
34827+
core.info(` > with module: ${module}`);
34828+
args.push('-m', module);
34829+
}
34830+
args.push('--cm');
3480234831
}
3480334832
try {
34804-
const output = await execUnityHub([...args, '--cm']);
34833+
const output = await execUnityHub(args);
3480534834
if (output.includes(`Error while installing an editor or a module from changeset`)) {
34806-
throw new Error(`Failed to install Unity ${version} (${changeset})`);
34835+
throw new Error(`Failed to install Unity ${unityVersion.toString()}`);
3480734836
}
3480834837
}
3480934838
finally {
3481034839
core.endGroup();
3481134840
}
3481234841
}
34842+
async function installUnity4x(unityVersion) {
34843+
const installPath = await getInstallPath();
34844+
switch (process.platform) {
34845+
case 'linux':
34846+
throw new Error(`Unity ${unityVersion.toString()} is not supported on Linux!`);
34847+
case 'win32':
34848+
{
34849+
const scriptPath = __nccwpck_require__.ab + "unity-editor-installer.ps1";
34850+
const exitCode = await exec.exec('pwsh', [__nccwpck_require__.ab + "unity-editor-installer.ps1", unityVersion.version, installPath]);
34851+
if (exitCode !== 0) {
34852+
throw new Error(`Failed to install Unity ${unityVersion.toString()}: ${exitCode}`);
34853+
}
34854+
break;
34855+
}
34856+
case 'darwin':
34857+
{
34858+
const scriptPath = __nccwpck_require__.ab + "unity-editor-installer.sh";
34859+
await fs.promises.chmod(__nccwpck_require__.ab + "unity-editor-installer.sh", 0o755);
34860+
const exitCode = await exec.exec('sh', [__nccwpck_require__.ab + "unity-editor-installer.sh", unityVersion.version, installPath]);
34861+
if (exitCode !== 0) {
34862+
throw new Error(`Failed to install Unity ${unityVersion.toString()}: ${exitCode}`);
34863+
}
34864+
break;
34865+
}
34866+
}
34867+
}
3481334868
async function ListInstalledEditors() {
3481434869
return await execUnityHub(['editors', '-i']);
3481534870
}
@@ -34902,20 +34957,20 @@ async function getModulesContent(modulesPath) {
3490234957
const modulesContent = await (0, utility_1.ReadFileContents)(modulesPath);
3490334958
return JSON.parse(modulesContent);
3490434959
}
34905-
async function getChangeset(version) {
34906-
version = version.split(/[abf]/)[0];
34907-
const url = `https://unity.com/releases/editor/whats-new/${version}`;
34960+
async function getChangeset(unityVersion) {
34961+
const splitVersion = unityVersion.version.split(/[abf]/)[0];
34962+
const url = `https://unity.com/releases/editor/whats-new/${splitVersion}`;
3490834963
const response = await fetch(url);
3490934964
if (!response.ok) {
3491034965
throw new Error(`Failed to fetch changeset [${response.status}] "${url}"`);
3491134966
}
3491234967
const data = await response.text();
3491334968
const match = data.match(/unityhub:\/\/(?<version>\d+\.\d+\.\d+[fab]?\d*)\/(?<changeset>[a-zA-Z0-9]+)/);
3491434969
if (match && match.groups && match.groups.changeset) {
34915-
return match.groups.changeset;
34970+
return new unity_version_1.UnityVersion(match.groups.version, match.groups.changeset);
3491634971
}
34917-
core.error(`Failed to find changeset for Unity ${version}`);
34918-
return null;
34972+
core.error(`Failed to find changeset for Unity ${unityVersion.toString()}`);
34973+
return unityVersion;
3491934974
}
3492034975
async function removePath(targetPath) {
3492134976
if (targetPath && targetPath.length > 0) {
@@ -34930,6 +34985,30 @@ async function removePath(targetPath) {
3493034985
}
3493134986

3493234987

34988+
/***/ }),
34989+
34990+
/***/ 5988:
34991+
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
34992+
34993+
"use strict";
34994+
34995+
Object.defineProperty(exports, "__esModule", ({ value: true }));
34996+
exports.UnityVersion = void 0;
34997+
const semver = __nccwpck_require__(1383);
34998+
class UnityVersion {
34999+
constructor(version, changeset) {
35000+
this.version = version;
35001+
this.changeset = changeset;
35002+
}
35003+
static compare(a, b) {
35004+
const vA = a.version;
35005+
const vB = b.version;
35006+
return semver.compare(vA, vB) || vA.localeCompare(vB);
35007+
}
35008+
}
35009+
exports.UnityVersion = UnityVersion;
35010+
35011+
3493335012
/***/ }),
3493435013

3493535014
/***/ 5418:
@@ -45547,13 +45626,13 @@ const main = async () => {
4554745626
await unityHub.SetInstallPath(installPath);
4554845627
}
4554945628
const editors = [];
45550-
for (const [version, changeset] of versions) {
45551-
const unityEditorPath = await unityHub.Unity(version, changeset, architecture, modules);
45629+
for (const unityVersion of versions) {
45630+
const unityEditorPath = await unityHub.Unity(unityVersion, architecture, modules);
4555245631
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath);
4555345632
if (modules.includes('android') && unityProjectPath !== undefined) {
4555445633
await (0, install_android_sdk_1.CheckAndroidSdkInstalled)(unityEditorPath, unityProjectPath);
4555545634
}
45556-
editors.push([version, unityEditorPath]);
45635+
editors.push([unityVersion.version, unityEditorPath]);
4555745636
}
4555845637
const installedEditors = editors.map(([version, path]) => `\"${version}\":\"${path}\"`).join(',');
4555945638
core.exportVariable('UNITY_EDITORS', `[${installedEditors}]`);

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/unity-editor-installer.ps1

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This script is used to download and install older unity versions.
2+
# https://discussions.unity.com/t/early-unity-versions-downloads/927331
3+
# input arguments:
4+
# 1. Unity Editor Version (Required)
5+
# 2. Install Directory (Required)
6+
# url example: https://beta.unity3d.com/download/UnitySetup-4.7.2.exe
7+
$version = $args[0]
8+
$installDir = $args[1]
9+
if (-not $version) {
10+
Write-Host "Error: Unity version is required."
11+
exit 1
12+
}
13+
if (-not $installDir) {
14+
Write-Host "Error: Install directory is required."
15+
exit 1
16+
}
17+
Write-Host "::group::Installing Unity $version..."
18+
$installerUrl = "https://beta.unity3d.com/download/UnitySetup-$version.exe"
19+
$installerPath = "$env:TEMP\UnitySetup-$version.exe"
20+
Invoke-WebRequest -Uri $installerUrl -OutFile $installerPath
21+
Start-Process -FilePath $installerPath -ArgumentList "/S /D=$installDir/Unity $version" -Wait -NoNewWindow
22+
Remove-Item -Path $installerPath -Force
23+
Write-Host "::endgroup::"

dist/unity-editor-installer.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/bash
2+
set -e
3+
# This script is used to download and install older unity versions.
4+
# https://discussions.unity.com/t/early-unity-versions-downloads/927331
5+
# input arguments:
6+
# 1. Unity Editor Version (Required)
7+
# 2. Install Directory (Required)
8+
# url example: https://beta.unity3d.com/download/unity-4.7.2.dmg
9+
VERSION="$1"
10+
INSTALL_DIR="$2"
11+
if [ -z "$VERSION" ] || [ -z "$INSTALL_DIR" ]; then
12+
echo "Usage: $0 <Unity Version> <Install Directory>"
13+
exit 1
14+
fi
15+
if [ ! -d "$INSTALL_DIR" ]; then
16+
mkdir -p "$INSTALL_DIR"
17+
fi
18+
URL="https://beta.unity3d.com/download/unity-${VERSION}.dmg"
19+
echo "::group::Installing Unity ${VERSION}..."
20+
curl -L -o "unity-${VERSION}.dmg" "$URL"
21+
echo "Mounting DMG..."
22+
hdiutil attach "unity-${VERSION}.dmg"
23+
echo "Installing Unity ${VERSION}..."
24+
mkdir -p "$INSTALL_DIR/Unity ${VERSION}"
25+
sudo cp -R "/Volumes/Unity ${VERSION}/Unity.app" "$INSTALL_DIR/Unity ${VERSION}/Unity.app"
26+
echo "Unmounting DMG..."
27+
hdiutil detach "/Volumes/Unity ${VERSION}"
28+
echo "::endgroup::"

0 commit comments

Comments
 (0)