Skip to content

Commit 28e64f6

Browse files
unity-setup@v1.0.4 (#9)
- improved `version-file` search, and added `None` option when creating new projects or setting `UNITY_PROJECT_PATH` later
1 parent 4b5453c commit 28e64f6

File tree

12 files changed

+75
-61
lines changed

12 files changed

+75
-61
lines changed

.github/workflows/validate.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,10 @@ jobs:
4747
modules: mac-server
4848
steps:
4949
- uses: actions/checkout@v4
50-
- uses: actions/checkout@v4
51-
with:
52-
repository: RageAgainstThePixel/com.utilities.buildpipeine
53-
path: com.utilities.buildpipline
54-
ref: development
5550

5651
- uses: ./ # RageAgainstThePixel/unity-setup
5752
with:
58-
version-file: com.utilities.buildpipline/Utilities.BuildPipeline/ProjectSettings/ProjectVersion.txt
53+
version-file: 'None'
5954
unity-version: ${{ matrix.unity-versions }}
6055
build-targets: ${{ matrix.build-targets }}
6156
modules: ${{ matrix.modules }}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ steps:
4949
5050
| name | description | required |
5151
| ----------- | ----------- | ----------- |
52-
| `version-file` | Specify a path to search for the unity project version text file. Useful if there are multiple projects in a single repo. | false |
52+
| `version-file` | Specify a path to search for the unity project version text file. Useful if there are multiple projects in a single repo. Pass `None` if creating a new project to skip file search. | false |
5353
| `unity-version` | Specify the Unity version(s) to install. You must include the changeset! i.e `2019.4.13f1 (518737b1de84)`. ***This will override any version specified in the `version-file`!*** | false |
5454
| `build-targets` | Specify the build targets to install for. Remaps to corresponding module. One or more of `StandaloneWindows64` `WSAPlayer` `StandaloneOSX` `iOS` `StandaloneLinux64` `Android` `Lumin` `WebGL` `VisionOS`. | false |
5555
| `modules` | Modules to install with the editor. This list can be different per editor version. | false |

action.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
name: 'unity-setup'
2-
description: 'A GitHub action for setting up the Unity Game Engine for CI/CD workflows.'
2+
description: A GitHub action for setting up the Unity Game Engine for CI/CD workflows.
3+
branding:
4+
icon: 'download'
5+
color: 'blue'
36
inputs:
47
version-file:
5-
description: 'Specify a path to search for the unity project version text file. Useful if there are multiple projects in a single repo.'
8+
description: 'Specify a path to search for the unity project version text file. Useful if there are multiple projects in a single repo. Pass `None` if creating a new project to skip file search.'
69
required: false
710
default: ''
811
unity-version:

dist/index.js

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34259,20 +34259,22 @@ async function ValidateInputs() {
3425934259
if (modules.length == 0) {
3426034260
throw Error('No modules or build-targets provided!');
3426134261
}
34262-
const versionFilePath = await getVersionFilePath();
34263-
core.info(`versionFilePath:\n > "${versionFilePath}"`);
34264-
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
3426534262
const versions = getUnityVersionsFromInput();
34266-
if (versions.length === 0) {
34267-
versions.push([unityVersion, changeset]);
34263+
const versionFilePath = await getVersionFilePath();
34264+
const unityProjectPath = versionFilePath !== undefined ? path.join(versionFilePath, '..', '..') : undefined;
34265+
if (versionFilePath) {
34266+
core.info(`versionFilePath:\n > "${versionFilePath}"`);
34267+
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
34268+
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
34269+
if (versions.length === 0) {
34270+
versions.push([unityVersion, changeset]);
34271+
}
3426834272
}
3426934273
versions.sort(([a], [b]) => semver.compare(a, b, true));
3427034274
core.info(`Unity Versions:`);
3427134275
for (const [version, changeset] of versions) {
3427234276
core.info(` > ${version} (${changeset})`);
3427334277
}
34274-
const unityProjectPath = path.join(versionFilePath, '..', '..');
34275-
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
3427634278
return [versions, architecture, modules, unityProjectPath];
3427734279
}
3427834280

@@ -34351,31 +34353,36 @@ function getDefaultModules() {
3435134353

3435234354
async function getVersionFilePath() {
3435334355
let projectVersionPath = core.getInput('version-file');
34354-
if (projectVersionPath) {
34355-
} else {
34356+
if (projectVersionPath !== undefined && projectVersionPath.toLowerCase() === 'none') {
34357+
return undefined;
34358+
}
34359+
if (!projectVersionPath) {
3435634360
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
3435734361
}
34358-
try {
34359-
await fs.access(projectVersionPath, fs.constants.R_OK);
34360-
return projectVersionPath;
34361-
} catch (error) {
34362-
core.debug(error);
34362+
if (projectVersionPath) {
3436334363
try {
34364-
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
3436534364
await fs.access(projectVersionPath, fs.constants.R_OK);
3436634365
return projectVersionPath;
3436734366
} catch (error) {
34368-
core.error(error);
34367+
core.debug(error);
3436934368
try {
34370-
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
34369+
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
3437134370
await fs.access(projectVersionPath, fs.constants.R_OK);
3437234371
return projectVersionPath;
3437334372
} catch (error) {
34374-
core.debug(error);
34373+
core.error(error);
34374+
try {
34375+
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
34376+
await fs.access(projectVersionPath, fs.constants.R_OK);
34377+
return projectVersionPath;
34378+
} catch (error) {
34379+
// ignore
34380+
}
3437534381
}
3437634382
}
34377-
throw Error(`Could not find ProjectVersion.txt in ${projectVersionPath}`);
3437834383
}
34384+
core.warning(`Could not find ProjectVersion.txt in ${process.env.GITHUB_WORKSPACE}! UNITY_PROJECT_PATH will not be set.`);
34385+
return undefined;
3437934386
}
3438034387

3438134388
function getUnityVersionsFromInput() {
@@ -34723,7 +34730,7 @@ async function execUnityHub(args) {
3472334730
});
3472434731
break;
3472534732
case 'linux': // xvfb-run --auto-servernum "~/Unity Hub/UnityHub.AppImage" --headless help
34726-
core.info(`[command]"xvfb-run" --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
34733+
core.info(`[command]xvfb-run --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
3472734734
await exec.exec('xvfb-run', ['--auto-servernum', hubPath, '--headless', ...args], {
3472834735
listeners: {
3472934736
stdline: (data) => {
@@ -45386,15 +45393,17 @@ const core = __nccwpck_require__(2186);
4538645393
const main = async () => {
4538745394
try {
4538845395
const [versions, architecture, modules, unityProjectPath] = await ValidateInputs();
45389-
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
45396+
if (unityProjectPath) {
45397+
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
45398+
}
4539045399
const unityHubPath = await unityHub.Get();
4539145400
core.exportVariable('UNITY_HUB_PATH', unityHubPath);
4539245401
const editors = [];
4539345402
for (const [version, changeset] of versions) {
4539445403
const unityEditorPath = await unityHub.Unity(version, changeset, architecture, modules);
4539545404
// for now just export the highest installed version
4539645405
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath);
45397-
if (modules.includes('android')) {
45406+
if (modules.includes('android') && unityProjectPath !== undefined) {
4539845407
await CheckAndroidSdkInstalled(unityEditorPath, unityProjectPath);
4539945408
}
4540045409
editors.push([version, unityEditorPath]);

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/install-unityhub-windows.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@ Write-Host "Downloading `"$url`" > `"$tempPath`"..."
66
$wc.DownloadFile($url, $tempPath)
77
Write-Host "`"$tempPath`" /S"
88
$process = Start-Process -FilePath $tempPath -ArgumentList '/S' -PassThru -Wait
9-
Write-Host "Unity Hub installation completed with exit code $process.ExitCode"
109
Write-Host "::endgroup::"
11-
exit $process.ExitCode
10+
exit [int]$process.ExitCode

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.3",
3+
"version": "1.0.4",
44
"description": "A GitHub action for setting up the Unity Game Engine for CI/CD workflows.",
55
"author": "RageAgainstThePixel",
66
"license": "MIT",

src/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ const core = require('@actions/core');
66
const main = async () => {
77
try {
88
const [versions, architecture, modules, unityProjectPath] = await ValidateInputs();
9-
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
9+
if (unityProjectPath) {
10+
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
11+
}
1012
const unityHubPath = await unityHub.Get();
1113
core.exportVariable('UNITY_HUB_PATH', unityHubPath);
1214
const editors = [];
1315
for (const [version, changeset] of versions) {
1416
const unityEditorPath = await unityHub.Unity(version, changeset, architecture, modules);
1517
// for now just export the highest installed version
1618
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath);
17-
if (modules.includes('android')) {
19+
if (modules.includes('android') && unityProjectPath !== undefined) {
1820
await CheckAndroidSdkInstalled(unityEditorPath, unityProjectPath);
1921
}
2022
editors.push([version, unityEditorPath]);

src/inputs.js

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,22 @@ async function ValidateInputs() {
4242
if (modules.length == 0) {
4343
throw Error('No modules or build-targets provided!');
4444
}
45-
const versionFilePath = await getVersionFilePath();
46-
core.info(`versionFilePath:\n > "${versionFilePath}"`);
47-
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
4845
const versions = getUnityVersionsFromInput();
49-
if (versions.length === 0) {
50-
versions.push([unityVersion, changeset]);
46+
const versionFilePath = await getVersionFilePath();
47+
const unityProjectPath = versionFilePath !== undefined ? path.join(versionFilePath, '..', '..') : undefined;
48+
if (versionFilePath) {
49+
core.info(`versionFilePath:\n > "${versionFilePath}"`);
50+
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
51+
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
52+
if (versions.length === 0) {
53+
versions.push([unityVersion, changeset]);
54+
}
5155
}
5256
versions.sort(([a], [b]) => semver.compare(a, b, true));
5357
core.info(`Unity Versions:`);
5458
for (const [version, changeset] of versions) {
5559
core.info(` > ${version} (${changeset})`);
5660
}
57-
const unityProjectPath = path.join(versionFilePath, '..', '..');
58-
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
5961
return [versions, architecture, modules, unityProjectPath];
6062
}
6163

@@ -134,31 +136,36 @@ function getDefaultModules() {
134136

135137
async function getVersionFilePath() {
136138
let projectVersionPath = core.getInput('version-file');
137-
if (projectVersionPath) {
138-
} else {
139+
if (projectVersionPath !== undefined && projectVersionPath.toLowerCase() === 'none') {
140+
return undefined;
141+
}
142+
if (!projectVersionPath) {
139143
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
140144
}
141-
try {
142-
await fs.access(projectVersionPath, fs.constants.R_OK);
143-
return projectVersionPath;
144-
} catch (error) {
145-
core.debug(error);
145+
if (projectVersionPath) {
146146
try {
147-
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
148147
await fs.access(projectVersionPath, fs.constants.R_OK);
149148
return projectVersionPath;
150149
} catch (error) {
151-
core.error(error);
150+
core.debug(error);
152151
try {
153-
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
152+
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
154153
await fs.access(projectVersionPath, fs.constants.R_OK);
155154
return projectVersionPath;
156155
} catch (error) {
157-
core.debug(error);
156+
core.error(error);
157+
try {
158+
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
159+
await fs.access(projectVersionPath, fs.constants.R_OK);
160+
return projectVersionPath;
161+
} catch (error) {
162+
// ignore
163+
}
158164
}
159165
}
160-
throw Error(`Could not find ProjectVersion.txt in ${projectVersionPath}`);
161166
}
167+
core.warning(`Could not find ProjectVersion.txt in ${process.env.GITHUB_WORKSPACE}! UNITY_PROJECT_PATH will not be set.`);
168+
return undefined;
162169
}
163170

164171
function getUnityVersionsFromInput() {

0 commit comments

Comments
 (0)