Skip to content

Commit 7a22fd6

Browse files
unity-action@v2.0.1 (#11)
- added `-force-graphics` override for when `-nographics` is auto added - updated auto added `-nographics` rules to only auto add for unity 2019+
1 parent 73d6ab7 commit 7a22fd6

File tree

8 files changed

+86
-9
lines changed

8 files changed

+86
-9
lines changed

.github/workflows/validate.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
name: validate
22
on:
3+
schedule:
4+
- cron: '0 0 * * 0' # Every Sunday at midnight
35
push:
46
branches: ['main']
57
pull_request:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ jobs:
4040
| `editor-path` | The path to the unity editor installation you want to use to execute the arguments with. | If `UNITY_EDITOR_PATH` environment variable is not set. | `env.UNITY_EDITOR_PATH` |
4141
| `project-path` | The path to the unity project you want to use when executing arguments. | If `UNITY_PROJECT_PATH` environment variable is not set, or if it isn't required for the command. | `env.UNITY_PROJECT_PATH` |
4242
| `build-target` | The build target to use when executing arguments. | false | |
43-
| `args` | The [arguments](https://docs.unity3d.com/Manual/EditorCommandLineArguments.html) to use when executing commands to the editor. | true | `-quit -batchmode -nographics` |
43+
| `args` | The [arguments](https://docs.unity3d.com/Manual/EditorCommandLineArguments.html) to use when executing commands to the editor. (Note: use `-force-graphics` to override auto-added `-nographics` argument) | true | `-quit -batchmode -nographics` |
4444
| `log-name` | The name of the log file to create when running the commands. | false | `Unity-yyyyMMddTHHmmss` |

dist/index.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25658,6 +25658,7 @@ const WORKSPACE = process.env.GITHUB_WORKSPACE;
2565825658
const UNITY_EDITOR_PATH = process.env.UNITY_EDITOR_PATH;
2565925659
const UNITY_PROJECT_PATH = process.env.UNITY_PROJECT_PATH;
2566025660
async function ValidateInputs() {
25661+
var _a;
2566125662
let editorPath = core.getInput(`editor-path`) || UNITY_EDITOR_PATH;
2566225663
if (!editorPath) {
2566325664
throw Error(`Missing editor-path or UNITY_EDITOR_PATH`);
@@ -25673,7 +25674,16 @@ async function ValidateInputs() {
2567325674
if (!inputArgs.includes(`-batchmode`)) {
2567425675
args.push(`-batchmode`);
2567525676
}
25676-
if (!inputArgs.includes(`-nographics`)) {
25677+
const match = editorPath.match(/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/);
25678+
if (!match) {
25679+
throw Error(`Invalid Unity Editor Path: ${editorPath}`);
25680+
}
25681+
const unityMajorVersion = (_a = match.groups) === null || _a === void 0 ? void 0 : _a.major;
25682+
if (!unityMajorVersion) {
25683+
throw Error(`Invalid Unity Major Version: ${editorPath}`);
25684+
}
25685+
const autoAddNographics = parseInt(unityMajorVersion, 10) > 2018;
25686+
if (autoAddNographics && !inputArgs.includes(`-nographics`) && !inputArgs.includes(`-force-graphics`)) {
2567725687
args.push(`-nographics`);
2567825688
}
2567925689
if (!inputArgs.includes(`-buildTarget`)) {
@@ -25788,7 +25798,30 @@ async function exec(command, onPid) {
2578825798
if (!logPath) {
2578925799
throw Error('Log file path not specified in command arguments');
2579025800
}
25791-
const unityProcess = (0, child_process_1.spawn)(command.editorPath, command.args, { stdio: ['ignore', 'ignore', 'ignore'], detached: true });
25801+
let unityProcess;
25802+
if (process.platform === 'linux' && !command.args.includes('-nographics')) {
25803+
const io = __nccwpck_require__(7436);
25804+
const xvfbRun = await io.which('xvfb-run', true);
25805+
unityProcess = (0, child_process_1.spawn)(xvfbRun, [command.editorPath, ...command.args], {
25806+
stdio: ['ignore', 'ignore', 'ignore'],
25807+
detached: true,
25808+
env: {
25809+
...process.env,
25810+
DISPLAY: ':99',
25811+
UNITY_THISISABUILDMACHINE: '1'
25812+
}
25813+
});
25814+
}
25815+
else {
25816+
unityProcess = (0, child_process_1.spawn)(command.editorPath, command.args, {
25817+
stdio: ['ignore', 'ignore', 'ignore'],
25818+
detached: true,
25819+
env: {
25820+
...process.env,
25821+
UNITY_THISISABUILDMACHINE: '1'
25822+
}
25823+
});
25824+
}
2579225825
const processId = unityProcess.pid;
2579325826
if (!processId) {
2579425827
throw new Error('Failed to start Unity process!');
@@ -25834,6 +25867,7 @@ async function exec(command, onPid) {
2583425867
}
2583525868
await new Promise(res => setTimeout(res, logPollingInterval));
2583625869
}
25870+
process.stdout.write('\n');
2583725871
};
2583825872
const timeout = 10000;
2583925873
const tailPromise = tailLog();

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.

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-action",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "A Github Action to execute Unity Editor command line arguments.",
55
"author": "buildalon",
66
"repository": {

src/inputs.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,16 @@ export async function ValidateInputs(): Promise<UnityCommand> {
2424
if (!inputArgs.includes(`-batchmode`)) {
2525
args.push(`-batchmode`);
2626
}
27-
if (!inputArgs.includes(`-nographics`)) {
27+
const match = editorPath.match(/(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/);
28+
if (!match) {
29+
throw Error(`Invalid Unity Editor Path: ${editorPath}`);
30+
}
31+
const unityMajorVersion = match.groups?.major;
32+
if (!unityMajorVersion) {
33+
throw Error(`Invalid Unity Major Version: ${editorPath}`);
34+
}
35+
const autoAddNographics = parseInt(unityMajorVersion, 10) > 2018;
36+
if (autoAddNographics && !inputArgs.includes(`-nographics`) && !inputArgs.includes(`-force-graphics`)) {
2837
args.push(`-nographics`);
2938
}
3039
if (!inputArgs.includes(`-buildTarget`)) {

src/unity.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import core = require('@actions/core');
22
import path = require('path');
33
import fs = require('fs');
44
import {
5+
ChildProcessByStdio,
56
spawn
67
} from 'child_process';
78
import {
@@ -58,7 +59,35 @@ async function exec(command: UnityCommand, onPid: (pid: ProcInfo) => void): Prom
5859
if (!logPath) {
5960
throw Error('Log file path not specified in command arguments');
6061
}
61-
const unityProcess = spawn(command.editorPath, command.args, { stdio: ['ignore', 'ignore', 'ignore'], detached: true });
62+
let unityProcess: ChildProcessByStdio<null, null, null>;
63+
if (process.platform === 'linux' && !command.args.includes('-nographics')) {
64+
const io = require('@actions/io');
65+
const xvfbRun = await io.which('xvfb-run', true);
66+
unityProcess = spawn(
67+
xvfbRun,
68+
[command.editorPath, ...command.args],
69+
{
70+
stdio: ['ignore', 'ignore', 'ignore'],
71+
detached: true,
72+
env: {
73+
...process.env,
74+
DISPLAY: ':99',
75+
UNITY_THISISABUILDMACHINE: '1'
76+
}
77+
});
78+
} else {
79+
unityProcess = spawn(
80+
command.editorPath,
81+
command.args,
82+
{
83+
stdio: ['ignore', 'ignore', 'ignore'],
84+
detached: true,
85+
env: {
86+
...process.env,
87+
UNITY_THISISABUILDMACHINE: '1'
88+
}
89+
});
90+
}
6291
const processId = unityProcess.pid;
6392
if (!processId) {
6493
throw new Error('Failed to start Unity process!');
@@ -107,6 +136,9 @@ async function exec(command: UnityCommand, onPid: (pid: ProcInfo) => void): Prom
107136
}
108137
await new Promise(res => setTimeout(res, logPollingInterval));
109138
}
139+
// Write a newline at the end of the log tail
140+
// prevents appending logs from being printed on the same line
141+
process.stdout.write('\n');
110142
};
111143
const timeout = 10000; // 10 seconds
112144
// Start log tailing in background

0 commit comments

Comments
 (0)