Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unity-setup@v1.0.8 #9

Merged
merged 7 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 Buildalon: Automate Unity
Copyright (c) 2024 Virtual Maker Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Discord](https://img.shields.io/discord/939721153688264824.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/VM9cWJ9rjH) [![actions](https://github.com/buildalon/unity-setup/actions/workflows/validate.yml/badge.svg?branch=main&event=push)](https://github.com/buildalon/unity-setup/actions/workflows/validate.yml)

A GitHub Action for setting up the [Unity Game Engine](https://unity.com) on GitHub Action Runners.
A GitHub Action for setting up the [Unity Game Engine](https://unity.com) for CI/CD workflows.

## How to use

Expand Down Expand Up @@ -35,7 +35,7 @@ strategy:
steps:
- uses: buildalon/unity-setup@v1
with:
version-file: 'path/to/your/ProjectSettings.ProjectVersion.txt'
version-file: 'path/to/your/unity/project/ProjectSettings/ProjectVersion.txt'
unity-version: ${{ matrix.unity-versions }} # overrides version in version-file
build-targets: ${{ matrix.build-targets }}
modules: ${{ matrix.modules }}
Expand Down
18 changes: 10 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34442,7 +34442,8 @@ async function CheckAndroidSdkInstalled(editorPath, projectPath) {
const rootEditorPath = await (0, utility_1.GetEditorRootPath)(editorPath);
const projectSettingsPath = path.join(projectPath, 'ProjectSettings/ProjectSettings.asset');
const projectSettingsContent = await (0, utility_1.ReadFileContents)(projectSettingsPath);
const androidTargetSdk = parseInt(projectSettingsContent.match(/(?<=AndroidTargetSdkVersion: )\d+/)[0]);
const matchResult = projectSettingsContent.match(/(?<=AndroidTargetSdkVersion: )\d+/);
const androidTargetSdk = matchResult ? parseInt(matchResult[0]) : 0;
core.debug(`AndroidTargetSdkVersion:\n > ${androidTargetSdk}`);
if (androidTargetSdk === undefined || androidTargetSdk === 0) {
return;
Expand Down Expand Up @@ -34711,7 +34712,8 @@ async function getLatestHubVersion() {
}
}
const ignoredLines = [
`This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:`,
`This error originated either by throwing inside of an async function without a catch block`,
`Unexpected error attempting to determine if executable file exists`,
`dri3 extension not supported`,
`Failed to connect to the bus:`
];
Expand All @@ -34736,8 +34738,8 @@ async function execUnityHub(args) {
});
break;
case 'linux':
core.info(`[command]xvfb-run --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
await exec.exec('xvfb-run', ['--auto-servernum', hubPath, '--headless', ...args], {
core.info(`[command]unity-hub --headless ${args.join(' ')}`);
await exec.exec('unity-hub', ['--headless', ...args], {
listeners: {
stdline: (data) => {
const line = data.toString();
Expand Down Expand Up @@ -34787,8 +34789,9 @@ async function Unity(version, changeset, architecture, modules) {
await installUnity(version, changeset, architecture, modules);
editorPath = await checkInstalledEditors(version, architecture);
}
await fs.promises.access(editorPath, fs.constants.R_OK);
await fs.promises.access(editorPath, fs.constants.X_OK);
core.info(`Unity Editor Path:\n > "${editorPath}"`);
core.addPath(editorPath);
try {
core.startGroup(`Checking installed modules for Unity ${version} (${changeset})...`);
const [installedModules, additionalModules] = await checkEditorModules(editorPath, version, architecture, modules);
Expand Down Expand Up @@ -34831,13 +34834,13 @@ async function installUnity(version, changeset, architecture, modules) {
}
}
async function ListInstalledEditors() {
StephenHodgson marked this conversation as resolved.
Show resolved Hide resolved
await execUnityHub(['editors', '-i']);
return await execUnityHub(['editors', '-i']);
}
function isArmCompatible(version) {
return semver.compare(version, '2021.1.0f1', true) >= 0;
}
async function checkInstalledEditors(version, architecture, failOnEmpty = true) {
const output = await execUnityHub(['editors', '-i']);
const output = await ListInstalledEditors();
if (!output || output.trim().length === 0) {
if (failOnEmpty) {
throw new Error('No Unity Editors installed!');
Expand Down Expand Up @@ -45412,7 +45415,6 @@ const main = async () => {
}
const installedEditors = editors.map(([version, path]) => `\"${version}\":\"${path}\"`).join(',');
core.exportVariable('UNITY_EDITORS', `[${installedEditors}]`);
await unityHub.ListInstalledEditors();
core.info('Unity Setup Complete!');
process.exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions dist/install-unityhub-linux.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
set -e
sudo sh -c 'dbus-uuidgen >/etc/machine-id && mkdir -p /var/lib/dbus/ && ln -sf /etc/machine-id /var/lib/dbus/machine-id'
echo "::group::Installing Unity Hub..."
wget -qO - https://hub.unity3d.com/linux/keys/public | gpg --dearmor | sudo tee /usr/share/keyrings/Unity_Technologies_ApS.gpg >/dev/null
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/Unity_Technologies_ApS.gpg] https://hub.unity3d.com/linux/repos/deb stable main" > /etc/apt/sources.list.d/unityhub.list'
sudo apt update
sudo apt install -y unityhub
sudo apt-get update
sudo apt-get install -y --no-install-recommends unityhub
sudo apt-get clean
sudo sed -i 's/^\(.*DISPLAY=:.*XAUTHORITY=.*\)\( "\$@" \)2>&1$/\1\2/' /usr/bin/xvfb-run
sudo printf '#!/bin/bash\nxvfb-run --auto-servernum /opt/unityhub/unityhub "$@" 2>/dev/null' | sudo tee /usr/bin/unity-hub >/dev/null
sudo chmod 777 /usr/bin/unity-hub
hubPath=$(which unityhub)
if [ -z "$hubPath" ]; then
echo "Failed to install Unity Hub"
Expand Down
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.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "unity-setup",
"version": "1.0.7",
"version": "1.0.8",
"description": "A GitHub action for setting up the Unity Game Engine for CI/CD workflows.",
"author": "Buildalon",
"license": "MIT",
Expand Down Expand Up @@ -41,6 +41,6 @@
"scripts": {
"build": "npm run clean && npm run bundle",
"bundle": "ncc build src/index.ts -o dist --source-map --license licenses.txt",
"clean": "shx rm -rf dist/ out/ node_modules/ && npm install && npm ci"
"clean": "npm install && shx rm -rf dist/ out/ node_modules/ && npm ci"
}
}
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const main = async () => {
}
const installedEditors = editors.map(([version, path]) => `\"${version}\":\"${path}\"`).join(',');
core.exportVariable('UNITY_EDITORS', `[${installedEditors}]`);
await unityHub.ListInstalledEditors();
core.info('Unity Setup Complete!');
process.exit(0);
} catch (error) {
Expand Down
9 changes: 7 additions & 2 deletions src/install-unityhub-linux.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
#!/bin/bash
set -e
sudo sh -c 'dbus-uuidgen >/etc/machine-id && mkdir -p /var/lib/dbus/ && ln -sf /etc/machine-id /var/lib/dbus/machine-id'
echo "::group::Installing Unity Hub..."
wget -qO - https://hub.unity3d.com/linux/keys/public | gpg --dearmor | sudo tee /usr/share/keyrings/Unity_Technologies_ApS.gpg >/dev/null
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/Unity_Technologies_ApS.gpg] https://hub.unity3d.com/linux/repos/deb stable main" > /etc/apt/sources.list.d/unityhub.list'
sudo apt update
sudo apt install -y unityhub
sudo apt-get update
sudo apt-get install -y --no-install-recommends unityhub
sudo apt-get clean
sudo sed -i 's/^\(.*DISPLAY=:.*XAUTHORITY=.*\)\( "\$@" \)2>&1$/\1\2/' /usr/bin/xvfb-run
sudo printf '#!/bin/bash\nxvfb-run --auto-servernum /opt/unityhub/unityhub "$@" 2>/dev/null' | sudo tee /usr/bin/unity-hub >/dev/null
sudo chmod 777 /usr/bin/unity-hub
hubPath=$(which unityhub)
if [ -z "$hubPath" ]; then
echo "Failed to install Unity Hub"
Expand Down
18 changes: 10 additions & 8 deletions src/unity-hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ async function getLatestHubVersion(): Promise<semver.SemVer> {
}

const ignoredLines = [
`This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:`,
`This error originated either by throwing inside of an async function without a catch block`,
`Unexpected error attempting to determine if executable file exists`,
`dri3 extension not supported`,
`Failed to connect to the bus:`
];
Expand All @@ -178,9 +179,9 @@ async function execUnityHub(args: string[]): Promise<string> {
ignoreReturnCode: true
});
break;
case 'linux': // xvfb-run --auto-servernum "~/Unity Hub/UnityHub.AppImage" --headless help
core.info(`[command]xvfb-run --auto-servernum "${hubPath}" --headless ${args.join(' ')}`);
await exec.exec('xvfb-run', ['--auto-servernum', hubPath, '--headless', ...args], {
case 'linux': // unity-hub --headless help
core.info(`[command]unity-hub --headless ${args.join(' ')}`);
await exec.exec('unity-hub', ['--headless', ...args], {
listeners: {
stdline: (data) => {
const line = data.toString();
Expand Down Expand Up @@ -231,8 +232,9 @@ async function Unity(version: string, changeset: string, architecture: string, m
await installUnity(version, changeset, architecture, modules);
editorPath = await checkInstalledEditors(version, architecture);
}
await fs.promises.access(editorPath, fs.constants.R_OK);
await fs.promises.access(editorPath, fs.constants.X_OK);
core.info(`Unity Editor Path:\n > "${editorPath}"`);
core.addPath(editorPath);
try {
core.startGroup(`Checking installed modules for Unity ${version} (${changeset})...`);
const [installedModules, additionalModules] = await checkEditorModules(editorPath, version, architecture, modules);
Expand Down Expand Up @@ -274,16 +276,16 @@ async function installUnity(version: string, changeset: string, architecture: st
}
}

async function ListInstalledEditors(): Promise<void> {
await execUnityHub(['editors', '-i']);
async function ListInstalledEditors(): Promise<string> {
return await execUnityHub(['editors', '-i']);
}

function isArmCompatible(version: string): boolean {
return semver.compare(version, '2021.1.0f1', true) >= 0;
}

async function checkInstalledEditors(version: string, architecture: string, failOnEmpty = true): Promise<string> {
const output = await execUnityHub(['editors', '-i']);
const output = await ListInstalledEditors();
if (!output || output.trim().length === 0) {
if (failOnEmpty) {
throw new Error('No Unity Editors installed!');
Expand Down