Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- improved `version-file` search, and added `None` option when creating new projects or setting `UNITY_PROJECT_PATH` later
  • Loading branch information
StephenHodgson authored Aug 12, 2024
1 parent 4b5453c commit 28e64f6
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 61 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,10 @@ jobs:
modules: mac-server
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: RageAgainstThePixel/com.utilities.buildpipeine
path: com.utilities.buildpipline
ref: development

- uses: ./ # RageAgainstThePixel/unity-setup
with:
version-file: com.utilities.buildpipline/Utilities.BuildPipeline/ProjectSettings/ProjectVersion.txt
version-file: 'None'
unity-version: ${{ matrix.unity-versions }}
build-targets: ${{ matrix.build-targets }}
modules: ${{ matrix.modules }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ steps:
| name | description | required |
| ----------- | ----------- | ----------- |
| `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 |
| `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 |
| `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 |
| `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 |
| `modules` | Modules to install with the editor. This list can be different per editor version. | false |
Expand Down
7 changes: 5 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: 'unity-setup'
description: 'A GitHub action for setting up the Unity Game Engine for CI/CD workflows.'
description: A GitHub action for setting up the Unity Game Engine for CI/CD workflows.
branding:
icon: 'download'
color: 'blue'
inputs:
version-file:
description: 'Specify a path to search for the unity project version text file. Useful if there are multiple projects in a single repo.'
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.'
required: false
default: ''
unity-version:
Expand Down
53 changes: 31 additions & 22 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34259,20 +34259,22 @@ async function ValidateInputs() {
if (modules.length == 0) {
throw Error('No modules or build-targets provided!');
}
const versionFilePath = await getVersionFilePath();
core.info(`versionFilePath:\n > "${versionFilePath}"`);
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
const versions = getUnityVersionsFromInput();
if (versions.length === 0) {
versions.push([unityVersion, changeset]);
const versionFilePath = await getVersionFilePath();
const unityProjectPath = versionFilePath !== undefined ? path.join(versionFilePath, '..', '..') : undefined;
if (versionFilePath) {
core.info(`versionFilePath:\n > "${versionFilePath}"`);
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
if (versions.length === 0) {
versions.push([unityVersion, changeset]);
}
}
versions.sort(([a], [b]) => semver.compare(a, b, true));
core.info(`Unity Versions:`);
for (const [version, changeset] of versions) {
core.info(` > ${version} (${changeset})`);
}
const unityProjectPath = path.join(versionFilePath, '..', '..');
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
return [versions, architecture, modules, unityProjectPath];
}

Expand Down Expand Up @@ -34351,31 +34353,36 @@ function getDefaultModules() {

async function getVersionFilePath() {
let projectVersionPath = core.getInput('version-file');
if (projectVersionPath) {
} else {
if (projectVersionPath !== undefined && projectVersionPath.toLowerCase() === 'none') {
return undefined;
}
if (!projectVersionPath) {
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
}
try {
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
core.debug(error);
if (projectVersionPath) {
try {
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
core.error(error);
core.debug(error);
try {
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
core.debug(error);
core.error(error);
try {
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
// ignore
}
}
}
throw Error(`Could not find ProjectVersion.txt in ${projectVersionPath}`);
}
core.warning(`Could not find ProjectVersion.txt in ${process.env.GITHUB_WORKSPACE}! UNITY_PROJECT_PATH will not be set.`);
return undefined;
}

function getUnityVersionsFromInput() {
Expand Down Expand Up @@ -34723,7 +34730,7 @@ async function execUnityHub(args) {
});
break;
case 'linux': // xvfb-run --auto-servernum "~/Unity Hub/UnityHub.AppImage" --headless help
core.info(`[command]"xvfb-run" --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
core.info(`[command]xvfb-run --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
await exec.exec('xvfb-run', ['--auto-servernum', hubPath, '--headless', ...args], {
listeners: {
stdline: (data) => {
Expand Down Expand Up @@ -45386,15 +45393,17 @@ const core = __nccwpck_require__(2186);
const main = async () => {
try {
const [versions, architecture, modules, unityProjectPath] = await ValidateInputs();
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
if (unityProjectPath) {
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
}
const unityHubPath = await unityHub.Get();
core.exportVariable('UNITY_HUB_PATH', unityHubPath);
const editors = [];
for (const [version, changeset] of versions) {
const unityEditorPath = await unityHub.Unity(version, changeset, architecture, modules);
// for now just export the highest installed version
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath);
if (modules.includes('android')) {
if (modules.includes('android') && unityProjectPath !== undefined) {
await CheckAndroidSdkInstalled(unityEditorPath, unityProjectPath);
}
editors.push([version, unityEditorPath]);
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/install-unityhub-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Write-Host "Downloading `"$url`" > `"$tempPath`"..."
$wc.DownloadFile($url, $tempPath)
Write-Host "`"$tempPath`" /S"
$process = Start-Process -FilePath $tempPath -ArgumentList '/S' -PassThru -Wait
Write-Host "Unity Hub installation completed with exit code $process.ExitCode"
Write-Host "::endgroup::"
exit $process.ExitCode
exit [int]$process.ExitCode
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.3",
"version": "1.0.4",
"description": "A GitHub action for setting up the Unity Game Engine for CI/CD workflows.",
"author": "RageAgainstThePixel",
"license": "MIT",
Expand Down
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ const core = require('@actions/core');
const main = async () => {
try {
const [versions, architecture, modules, unityProjectPath] = await ValidateInputs();
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
if (unityProjectPath) {
core.exportVariable('UNITY_PROJECT_PATH', unityProjectPath);
}
const unityHubPath = await unityHub.Get();
core.exportVariable('UNITY_HUB_PATH', unityHubPath);
const editors = [];
for (const [version, changeset] of versions) {
const unityEditorPath = await unityHub.Unity(version, changeset, architecture, modules);
// for now just export the highest installed version
core.exportVariable('UNITY_EDITOR_PATH', unityEditorPath);
if (modules.includes('android')) {
if (modules.includes('android') && unityProjectPath !== undefined) {
await CheckAndroidSdkInstalled(unityEditorPath, unityProjectPath);
}
editors.push([version, unityEditorPath]);
Expand Down
45 changes: 26 additions & 19 deletions src/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ async function ValidateInputs() {
if (modules.length == 0) {
throw Error('No modules or build-targets provided!');
}
const versionFilePath = await getVersionFilePath();
core.info(`versionFilePath:\n > "${versionFilePath}"`);
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
const versions = getUnityVersionsFromInput();
if (versions.length === 0) {
versions.push([unityVersion, changeset]);
const versionFilePath = await getVersionFilePath();
const unityProjectPath = versionFilePath !== undefined ? path.join(versionFilePath, '..', '..') : undefined;
if (versionFilePath) {
core.info(`versionFilePath:\n > "${versionFilePath}"`);
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
const [unityVersion, changeset] = await getUnityVersionFromFile(versionFilePath);
if (versions.length === 0) {
versions.push([unityVersion, changeset]);
}
}
versions.sort(([a], [b]) => semver.compare(a, b, true));
core.info(`Unity Versions:`);
for (const [version, changeset] of versions) {
core.info(` > ${version} (${changeset})`);
}
const unityProjectPath = path.join(versionFilePath, '..', '..');
core.info(`Unity Project Path:\n > "${unityProjectPath}"`);
return [versions, architecture, modules, unityProjectPath];
}

Expand Down Expand Up @@ -134,31 +136,36 @@ function getDefaultModules() {

async function getVersionFilePath() {
let projectVersionPath = core.getInput('version-file');
if (projectVersionPath) {
} else {
if (projectVersionPath !== undefined && projectVersionPath.toLowerCase() === 'none') {
return undefined;
}
if (!projectVersionPath) {
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
}
try {
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
core.debug(error);
if (projectVersionPath) {
try {
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
core.error(error);
core.debug(error);
try {
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
projectVersionPath = path.join(process.env.GITHUB_WORKSPACE, projectVersionPath);
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
core.debug(error);
core.error(error);
try {
projectVersionPath = await FindGlobPattern(path.join(process.env.GITHUB_WORKSPACE, '**', 'ProjectVersion.txt'));
await fs.access(projectVersionPath, fs.constants.R_OK);
return projectVersionPath;
} catch (error) {
// ignore
}
}
}
throw Error(`Could not find ProjectVersion.txt in ${projectVersionPath}`);
}
core.warning(`Could not find ProjectVersion.txt in ${process.env.GITHUB_WORKSPACE}! UNITY_PROJECT_PATH will not be set.`);
return undefined;
}

function getUnityVersionsFromInput() {
Expand Down
3 changes: 1 addition & 2 deletions src/install-unityhub-windows.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ Write-Host "Downloading `"$url`" > `"$tempPath`"..."
$wc.DownloadFile($url, $tempPath)
Write-Host "`"$tempPath`" /S"
$process = Start-Process -FilePath $tempPath -ArgumentList '/S' -PassThru -Wait
Write-Host "Unity Hub installation completed with exit code $process.ExitCode"
Write-Host "::endgroup::"
exit $process.ExitCode
exit [int]$process.ExitCode
2 changes: 1 addition & 1 deletion src/unity-hub.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ async function execUnityHub(args) {
});
break;
case 'linux': // xvfb-run --auto-servernum "~/Unity Hub/UnityHub.AppImage" --headless help
core.info(`[command]"xvfb-run" --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
core.info(`[command]xvfb-run --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
await exec.exec('xvfb-run', ['--auto-servernum', hubPath, '--headless', ...args], {
listeners: {
stdline: (data) => {
Expand Down

0 comments on commit 28e64f6

Please sign in to comment.