Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Commit 91194db

Browse files
@xrtk/unity-setup@v5 (#7)
- Add `build-targets` support - Deprecate `modules` - Install module if not already installed
1 parent 5008728 commit 91194db

File tree

9 files changed

+313
-28
lines changed

9 files changed

+313
-28
lines changed

.github/workflows/validate.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ jobs:
1919
runs-on: ${{ matrix.os }}
2020
strategy:
2121
matrix:
22-
os: [ windows-latest, macos-latest, ubuntu-latest ]
22+
include:
23+
- os: ubuntu-latest
24+
build-targets: 'StandaloneLinux64 Android iOS'
25+
- os: windows-latest
26+
build-targets: 'StandaloneWindows64 Android iOS'
27+
- os: macos-latest
28+
build-targets: 'StandaloneOSX Android iOS'
2329

2430
steps:
2531
- name: checkout self
@@ -33,9 +39,10 @@ jobs:
3339
repository: xrtk/com.xrtk.test
3440
path: test-project
3541

36-
- uses: ./
42+
- uses: ./ # xrtk/unity-setup
43+
id: unity-setup
3744
with:
38-
version-file-path: 'test-project/**/ProjectSettings/ProjectVersion.txt'
45+
build-targets: '${{ matrix.build-targets }}'
3946

4047
- run: |
4148
echo "${{ env.UNITY_EDITOR_PATH }}"

README.md

+13-7
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,25 @@ Part of the [Mixed Reality Toolkit (XRTK)](https://github.com/XRTK) open source
2424
jobs:
2525
setup-unity:
2626
strategy:
27-
fail-fast: false
27+
runs-on: ${{ matrix.os }}
28+
strategy:
2829
matrix:
29-
runner: [ ubuntu-latest, windows-latest, macos-latest ]
30-
runs-on: ${{ matrix.runner }}
30+
include:
31+
- os: ubuntu-latest
32+
build-targets: 'StandaloneLinux64 Android iOS'
33+
- os: windows-latest
34+
build-targets: 'StandaloneWindows64 Android iOS'
35+
- os: macos-latest
36+
build-targets: 'StandaloneOSX Android iOS'
3137

3238
steps:
3339
- uses: actions/checkout@v3
3440

3541
- id: unity-setup
36-
uses: xrtk/unity-setup@v4
37-
with:
38-
modules: 'android ios' #Optional, overrides the default platform specific module installs.
39-
#version-file-path: '**/ProjectSettings/ProjectVersion.txt' # Optional
42+
uses: xrtk/unity-setup@v5
43+
with:
44+
modules: '${{ matrix.build-targets }}' #Optional, overrides the default platform specific module installs.
45+
#version-file-path: 'ProjectSettings/ProjectVersion.txt' # Optional
4046

4147
- run: |
4248
echo "${{ env.UNITY_EDITOR_PATH }}"

action.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
name: 'Unity Setup'
22
description: 'Installs the Unity Editor and modules based on the build target and project settings.'
33
inputs:
4+
version-file-path:
5+
description: 'Optional, specify a path to search for the unity project version text file. Use this if step fails to find a valid project version file.'
6+
required: false
7+
default: ''
8+
build-targets:
9+
description: 'Optional, specify the build targets to install for (i.e "StandaloneWindows64 WSAPlayer StandaloneOSX iOS StandaloneLinux64 Android Lumin WebGL")'
10+
required: false
11+
default: ''
412
modules:
13+
deprecationMessage: 'Use build-targets instead'
514
description: 'Optional, Additional modules to install with the editor (i.e "webgl android lumin")'
615
required: false
716
default: ''
8-
version-file-path:
9-
description: 'Optional, specify a path to search for the unity project version text file. Use this if step fails to find a valid project version file.'
10-
required: false
11-
default: '**/ProjectSettings/ProjectVersion.txt'
12-
outputs:
13-
editor-path:
14-
description: 'The path to the Unity Editor'
15-
project-path:
16-
description: 'The path to the unity project'
1717
runs:
1818
using: 'node16'
1919
main: 'dist/index.js'

dist/index.js

+116-3
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,14 @@ module.exports = require("fs");
39953995

39963996
/***/ }),
39973997

3998+
/***/ 292:
3999+
/***/ ((module) => {
4000+
4001+
"use strict";
4002+
module.exports = require("fs/promises");
4003+
4004+
/***/ }),
4005+
39984006
/***/ 685:
39994007
/***/ ((module) => {
40004008

@@ -4112,19 +4120,92 @@ const core = __nccwpck_require__(186);
41124120
const exec = __nccwpck_require__(514);
41134121
const io = __nccwpck_require__(436);
41144122
const path = __nccwpck_require__(17);
4123+
const fs = __nccwpck_require__(147);
4124+
const { readdir } = __nccwpck_require__(292);
4125+
const os = __nccwpck_require__(37);
41154126

41164127
const main = async () => {
41174128
try {
4118-
var modules = core.getInput('modules');
4129+
var modules = '';
4130+
var buildTargets = core.getInput('build-targets');
4131+
core.debug(`buildTargets: ${buildTargets}`);
4132+
4133+
if (!buildTargets) {
4134+
modules = core.getInput('modules');
4135+
core.debug(`modules: ${modules}`);
4136+
} else {
4137+
var moduleMap = undefined;
4138+
4139+
const osType = os.type();
4140+
if (osType == 'Linux') {
4141+
moduleMap = {
4142+
"StandaloneLinux64": "linux-il2cpp",
4143+
"Android": "android",
4144+
"WebGL": "webgl",
4145+
"iOS": "ios",
4146+
};
4147+
} else if (osType == 'Darwin') {
4148+
moduleMap = {
4149+
"StandaloneOSX": "mac-il2cpp",
4150+
"iOS": "ios",
4151+
"Android": "android",
4152+
"tvOS": "appletv",
4153+
"StandaloneLinux64": "linux-il2cpp",
4154+
};
4155+
} else if (osType == 'Windows_NT') {
4156+
moduleMap = {
4157+
"StandaloneWindows64": "windows-il2cpp",
4158+
"WSAPlayer": "universal-windows-platform",
4159+
"Android": "android",
4160+
"iOS": "ios",
4161+
"tvOS": "appletv",
4162+
"StandaloneLinux64": "linux-il2cpp",
4163+
"Lumin": "lumin",
4164+
"WebGL": "webgl",
4165+
};
4166+
} else {
4167+
throw Error(`${osType} not supported`);
4168+
}
4169+
4170+
var targets = buildTargets.split(' ');
4171+
core.debug(`targets: ${targets}`);
4172+
4173+
for (const target of targets) {
4174+
core.debug(`target: ${target}`);
4175+
4176+
var module = moduleMap[target];
4177+
4178+
if (module === undefined) {
4179+
core.warning(`${target} not a valid build-target`);
4180+
continue;
4181+
}
4182+
4183+
modules += `${module} `;
4184+
core.debug(` ${target} -> ${module}`);
4185+
}
4186+
4187+
modules = modules.trim();
4188+
}
4189+
41194190
var versionFilePath = core.getInput('version-file-path');
4191+
4192+
if (!versionFilePath) {
4193+
// search for license file version
4194+
var exeDir = path.resolve(process.cwd());
4195+
core.debug(`exeDir: ${exeDir}`);
4196+
versionFilePath = await findFile(exeDir, 'ProjectVersion.txt');
4197+
core.debug(`version file path: ${versionFilePath}`);
4198+
}
4199+
4200+
core.debug(`modules: ${modules}`);
4201+
core.debug(`versionFilePath: ${versionFilePath}`);
4202+
41204203
var args = `-modulesList \"${modules}\" -versionFilePath \"${versionFilePath}\"`;
41214204
var pwsh = await io.which("pwsh", true);
41224205
var install = __nccwpck_require__.ab + "unity-install.ps1";
41234206
var exitCode = 0;
41244207

4125-
console.log(`::group::Run xrtk/unity-setup`);
41264208
exitCode = await exec.exec(`"${pwsh}" -Command`, `${install} ${args}`);
4127-
console.log(`::endgroup::`);
41284209

41294210
if (exitCode != 0) {
41304211
throw Error(`Unity Installation Failed! exitCode: ${exitCode}`)
@@ -4134,6 +4215,38 @@ const main = async () => {
41344215
}
41354216
}
41364217

4218+
const findFile = async (dir, filePath) => {
4219+
const directories = [];
4220+
const matchedFiles = [];
4221+
const files = await readdir(dir);
4222+
4223+
for (const file of files) {
4224+
const item = path.resolve(dir, file);
4225+
4226+
if (fs.statSync(`${dir}/${file}`).isDirectory()) {
4227+
directories.push(item);
4228+
} else if (file.endsWith(filePath)) {
4229+
core.debug(`--> Found! ${item}`);
4230+
matchedFiles.push(item);
4231+
break;
4232+
}
4233+
}
4234+
4235+
if (matchedFiles.length == 0) {
4236+
for(const subDir of directories) {
4237+
const nestedMatches = await findFile(subDir, filePath);
4238+
4239+
for (const nestedMatch of nestedMatches) {
4240+
matchedFiles.push(nestedMatch);
4241+
break;
4242+
}
4243+
}
4244+
}
4245+
4246+
return matchedFiles;
4247+
};
4248+
4249+
41374250
// Call the main function to run the action
41384251
main();
41394252
})();

dist/unity-install.ps1

+27
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,33 @@ if ( -not (Test-Path -Path $editorPath)) {
167167

168168
$installArgsString = $installArgs -join " "
169169

170+
Write-Host "::group::Run unity-hub $installArgsString"
171+
Invoke-UnityHub $installArgsString
172+
Write-Host ""
173+
Write-Host "::endgroup::"
174+
} else {
175+
Write-Host "Intalling modules for $unityVersion ($unityVersionChangeSet)"
176+
$installArgs = @('install-modules',"--version $unityVersion",'--cm')
177+
178+
$addModules = @()
179+
180+
foreach ($module in $modules) {
181+
if ($module -eq 'android') {
182+
$addmodules += 'android-open-jdk'
183+
$addmodules += 'android-sdk-ndk-tools'
184+
}
185+
}
186+
187+
$modules += $addModules
188+
189+
foreach ($module in $modules) {
190+
$installArgs += '-m'
191+
$installArgs += $module
192+
Write-Host " > with module: $module"
193+
}
194+
195+
$installArgsString = $installArgs -join " "
196+
170197
Write-Host "::group::Run unity-hub $installArgsString"
171198
Invoke-UnityHub $installArgsString
172199
Write-Host ""

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "unity-setup",
3-
"version": "4.0.0",
3+
"version": "5.0.0",
44
"description": "An atomic GitHub action to download and install the Unity Editor for runners.",
55
"main": "src/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)