diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index 2b0e69f..4a26599 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -19,7 +19,13 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ windows-latest, macos-latest, ubuntu-latest ] + include: + - os: ubuntu-latest + build-targets: 'StandaloneLinux64 Android iOS' + - os: windows-latest + build-targets: 'StandaloneWindows64 Android iOS' + - os: macos-latest + build-targets: 'StandaloneOSX Android iOS' steps: - name: checkout self @@ -33,9 +39,10 @@ jobs: repository: xrtk/com.xrtk.test path: test-project - - uses: ./ + - uses: ./ # xrtk/unity-setup + id: unity-setup with: - version-file-path: 'test-project/**/ProjectSettings/ProjectVersion.txt' + build-targets: '${{ matrix.build-targets }}' - run: | echo "${{ env.UNITY_EDITOR_PATH }}" diff --git a/README.md b/README.md index d2de48e..cbc2ef1 100644 --- a/README.md +++ b/README.md @@ -24,19 +24,25 @@ Part of the [Mixed Reality Toolkit (XRTK)](https://github.com/XRTK) open source jobs: setup-unity: strategy: - fail-fast: false + runs-on: ${{ matrix.os }} + strategy: matrix: - runner: [ ubuntu-latest, windows-latest, macos-latest ] - runs-on: ${{ matrix.runner }} + include: + - os: ubuntu-latest + build-targets: 'StandaloneLinux64 Android iOS' + - os: windows-latest + build-targets: 'StandaloneWindows64 Android iOS' + - os: macos-latest + build-targets: 'StandaloneOSX Android iOS' steps: - uses: actions/checkout@v3 - id: unity-setup - uses: xrtk/unity-setup@v4 - with: - modules: 'android ios' #Optional, overrides the default platform specific module installs. - #version-file-path: '**/ProjectSettings/ProjectVersion.txt' # Optional + uses: xrtk/unity-setup@v5 + with: + modules: '${{ matrix.build-targets }}' #Optional, overrides the default platform specific module installs. + #version-file-path: 'ProjectSettings/ProjectVersion.txt' # Optional - run: | echo "${{ env.UNITY_EDITOR_PATH }}" diff --git a/action.yml b/action.yml index 2cfa127..3b58ca9 100644 --- a/action.yml +++ b/action.yml @@ -1,19 +1,19 @@ name: 'Unity Setup' description: 'Installs the Unity Editor and modules based on the build target and project settings.' inputs: + version-file-path: + 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.' + required: false + default: '' + build-targets: + description: 'Optional, specify the build targets to install for (i.e "StandaloneWindows64 WSAPlayer StandaloneOSX iOS StandaloneLinux64 Android Lumin WebGL")' + required: false + default: '' modules: + deprecationMessage: 'Use build-targets instead' description: 'Optional, Additional modules to install with the editor (i.e "webgl android lumin")' required: false default: '' - version-file-path: - 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.' - required: false - default: '**/ProjectSettings/ProjectVersion.txt' -outputs: - editor-path: - description: 'The path to the Unity Editor' - project-path: - description: 'The path to the unity project' runs: using: 'node16' main: 'dist/index.js' \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index 0e17aff..aec506a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3995,6 +3995,14 @@ module.exports = require("fs"); /***/ }), +/***/ 292: +/***/ ((module) => { + +"use strict"; +module.exports = require("fs/promises"); + +/***/ }), + /***/ 685: /***/ ((module) => { @@ -4112,19 +4120,92 @@ const core = __nccwpck_require__(186); const exec = __nccwpck_require__(514); const io = __nccwpck_require__(436); const path = __nccwpck_require__(17); +const fs = __nccwpck_require__(147); +const { readdir } = __nccwpck_require__(292); +const os = __nccwpck_require__(37); const main = async () => { try { - var modules = core.getInput('modules'); + var modules = ''; + var buildTargets = core.getInput('build-targets'); + core.debug(`buildTargets: ${buildTargets}`); + + if (!buildTargets) { + modules = core.getInput('modules'); + core.debug(`modules: ${modules}`); + } else { + var moduleMap = undefined; + + const osType = os.type(); + if (osType == 'Linux') { + moduleMap = { + "StandaloneLinux64": "linux-il2cpp", + "Android": "android", + "WebGL": "webgl", + "iOS": "ios", + }; + } else if (osType == 'Darwin') { + moduleMap = { + "StandaloneOSX": "mac-il2cpp", + "iOS": "ios", + "Android": "android", + "tvOS": "appletv", + "StandaloneLinux64": "linux-il2cpp", + }; + } else if (osType == 'Windows_NT') { + moduleMap = { + "StandaloneWindows64": "windows-il2cpp", + "WSAPlayer": "universal-windows-platform", + "Android": "android", + "iOS": "ios", + "tvOS": "appletv", + "StandaloneLinux64": "linux-il2cpp", + "Lumin": "lumin", + "WebGL": "webgl", + }; + } else { + throw Error(`${osType} not supported`); + } + + var targets = buildTargets.split(' '); + core.debug(`targets: ${targets}`); + + for (const target of targets) { + core.debug(`target: ${target}`); + + var module = moduleMap[target]; + + if (module === undefined) { + core.warning(`${target} not a valid build-target`); + continue; + } + + modules += `${module} `; + core.debug(` ${target} -> ${module}`); + } + + modules = modules.trim(); + } + var versionFilePath = core.getInput('version-file-path'); + + if (!versionFilePath) { + // search for license file version + var exeDir = path.resolve(process.cwd()); + core.debug(`exeDir: ${exeDir}`); + versionFilePath = await findFile(exeDir, 'ProjectVersion.txt'); + core.debug(`version file path: ${versionFilePath}`); + } + + core.debug(`modules: ${modules}`); + core.debug(`versionFilePath: ${versionFilePath}`); + var args = `-modulesList \"${modules}\" -versionFilePath \"${versionFilePath}\"`; var pwsh = await io.which("pwsh", true); var install = __nccwpck_require__.ab + "unity-install.ps1"; var exitCode = 0; - console.log(`::group::Run xrtk/unity-setup`); exitCode = await exec.exec(`"${pwsh}" -Command`, `${install} ${args}`); - console.log(`::endgroup::`); if (exitCode != 0) { throw Error(`Unity Installation Failed! exitCode: ${exitCode}`) @@ -4134,6 +4215,38 @@ const main = async () => { } } +const findFile = async (dir, filePath) => { + const directories = []; + const matchedFiles = []; + const files = await readdir(dir); + + for (const file of files) { + const item = path.resolve(dir, file); + + if (fs.statSync(`${dir}/${file}`).isDirectory()) { + directories.push(item); + } else if (file.endsWith(filePath)) { + core.debug(`--> Found! ${item}`); + matchedFiles.push(item); + break; + } + } + + if (matchedFiles.length == 0) { + for(const subDir of directories) { + const nestedMatches = await findFile(subDir, filePath); + + for (const nestedMatch of nestedMatches) { + matchedFiles.push(nestedMatch); + break; + } + } + } + + return matchedFiles; +}; + + // Call the main function to run the action main(); })(); diff --git a/dist/unity-install.ps1 b/dist/unity-install.ps1 index 0dd4f37..c68441a 100644 --- a/dist/unity-install.ps1 +++ b/dist/unity-install.ps1 @@ -167,6 +167,33 @@ if ( -not (Test-Path -Path $editorPath)) { $installArgsString = $installArgs -join " " + Write-Host "::group::Run unity-hub $installArgsString" + Invoke-UnityHub $installArgsString + Write-Host "" + Write-Host "::endgroup::" +} else { + Write-Host "Intalling modules for $unityVersion ($unityVersionChangeSet)" + $installArgs = @('install-modules',"--version $unityVersion",'--cm') + + $addModules = @() + + foreach ($module in $modules) { + if ($module -eq 'android') { + $addmodules += 'android-open-jdk' + $addmodules += 'android-sdk-ndk-tools' + } + } + + $modules += $addModules + + foreach ($module in $modules) { + $installArgs += '-m' + $installArgs += $module + Write-Host " > with module: $module" + } + + $installArgsString = $installArgs -join " " + Write-Host "::group::Run unity-hub $installArgsString" Invoke-UnityHub $installArgsString Write-Host "" diff --git a/package-lock.json b/package-lock.json index 85ec6f0..88cdf45 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "unity-setup", - "version": "1.0.0", + "version": "5.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "unity-setup", - "version": "1.0.0", + "version": "5.0.0", "license": "MIT", "dependencies": { "@actions/core": "^1.10.0", diff --git a/package.json b/package.json index 10cc2e2..c47e844 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "unity-setup", - "version": "4.0.0", + "version": "5.0.0", "description": "An atomic GitHub action to download and install the Unity Editor for runners.", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index aebeae2..285a25f 100644 --- a/src/index.js +++ b/src/index.js @@ -2,19 +2,92 @@ const core = require('@actions/core'); const exec = require('@actions/exec'); const io = require('@actions/io'); const path = require('path'); +const fs = require("fs"); +const { readdir } = require('fs/promises'); +const os = require('os'); const main = async () => { try { - var modules = core.getInput('modules'); + var modules = ''; + var buildTargets = core.getInput('build-targets'); + core.debug(`buildTargets: ${buildTargets}`); + + if (!buildTargets) { + modules = core.getInput('modules'); + core.debug(`modules: ${modules}`); + } else { + var moduleMap = undefined; + + const osType = os.type(); + if (osType == 'Linux') { + moduleMap = { + "StandaloneLinux64": "linux-il2cpp", + "Android": "android", + "WebGL": "webgl", + "iOS": "ios", + }; + } else if (osType == 'Darwin') { + moduleMap = { + "StandaloneOSX": "mac-il2cpp", + "iOS": "ios", + "Android": "android", + "tvOS": "appletv", + "StandaloneLinux64": "linux-il2cpp", + }; + } else if (osType == 'Windows_NT') { + moduleMap = { + "StandaloneWindows64": "windows-il2cpp", + "WSAPlayer": "universal-windows-platform", + "Android": "android", + "iOS": "ios", + "tvOS": "appletv", + "StandaloneLinux64": "linux-il2cpp", + "Lumin": "lumin", + "WebGL": "webgl", + }; + } else { + throw Error(`${osType} not supported`); + } + + var targets = buildTargets.split(' '); + core.debug(`targets: ${targets}`); + + for (const target of targets) { + core.debug(`target: ${target}`); + + var module = moduleMap[target]; + + if (module === undefined) { + core.warning(`${target} not a valid build-target`); + continue; + } + + modules += `${module} `; + core.debug(` ${target} -> ${module}`); + } + + modules = modules.trim(); + } + var versionFilePath = core.getInput('version-file-path'); + + if (!versionFilePath) { + // search for license file version + var exeDir = path.resolve(process.cwd()); + core.debug(`exeDir: ${exeDir}`); + versionFilePath = await findFile(exeDir, 'ProjectVersion.txt'); + core.debug(`version file path: ${versionFilePath}`); + } + + core.debug(`modules: ${modules}`); + core.debug(`versionFilePath: ${versionFilePath}`); + var args = `-modulesList \"${modules}\" -versionFilePath \"${versionFilePath}\"`; var pwsh = await io.which("pwsh", true); var install = path.resolve(__dirname, 'unity-install.ps1'); var exitCode = 0; - console.log(`::group::Run xrtk/unity-setup`); exitCode = await exec.exec(`"${pwsh}" -Command`, `${install} ${args}`); - console.log(`::endgroup::`); if (exitCode != 0) { throw Error(`Unity Installation Failed! exitCode: ${exitCode}`) @@ -24,5 +97,37 @@ const main = async () => { } } +const findFile = async (dir, filePath) => { + const directories = []; + const matchedFiles = []; + const files = await readdir(dir); + + for (const file of files) { + const item = path.resolve(dir, file); + + if (fs.statSync(`${dir}/${file}`).isDirectory()) { + directories.push(item); + } else if (file.endsWith(filePath)) { + core.debug(`--> Found! ${item}`); + matchedFiles.push(item); + break; + } + } + + if (matchedFiles.length == 0) { + for(const subDir of directories) { + const nestedMatches = await findFile(subDir, filePath); + + for (const nestedMatch of nestedMatches) { + matchedFiles.push(nestedMatch); + break; + } + } + } + + return matchedFiles; +}; + + // Call the main function to run the action main(); \ No newline at end of file diff --git a/src/unity-install.ps1 b/src/unity-install.ps1 index 0dd4f37..c68441a 100644 --- a/src/unity-install.ps1 +++ b/src/unity-install.ps1 @@ -167,6 +167,33 @@ if ( -not (Test-Path -Path $editorPath)) { $installArgsString = $installArgs -join " " + Write-Host "::group::Run unity-hub $installArgsString" + Invoke-UnityHub $installArgsString + Write-Host "" + Write-Host "::endgroup::" +} else { + Write-Host "Intalling modules for $unityVersion ($unityVersionChangeSet)" + $installArgs = @('install-modules',"--version $unityVersion",'--cm') + + $addModules = @() + + foreach ($module in $modules) { + if ($module -eq 'android') { + $addmodules += 'android-open-jdk' + $addmodules += 'android-sdk-ndk-tools' + } + } + + $modules += $addModules + + foreach ($module in $modules) { + $installArgs += '-m' + $installArgs += $module + Write-Host " > with module: $module" + } + + $installArgsString = $installArgs -join " " + Write-Host "::group::Run unity-hub $installArgsString" Invoke-UnityHub $installArgsString Write-Host ""