Skip to content

Commit b1f2ef5

Browse files
unity-cli@v1.0.8 (#9)
- fix intermittent hanging from hub install commands
1 parent 3f84709 commit b1f2ef5

5 files changed

Lines changed: 57 additions & 28 deletions

File tree

.github/workflows/unity-build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ jobs:
2121
runs-on: ${{ matrix.os }}
2222
permissions:
2323
contents: read
24+
timeout-minutes: 25
2425
steps:
2526
- uses: actions/checkout@v4
2627
- uses: actions/setup-node@v4

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": "@rage-against-the-pixel/unity-cli",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "A command line utility for the Unity Game Engine.",
55
"author": "RageAgainstThePixel",
66
"license": "MIT",

src/unity-hub.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,6 @@ export class UnityHub {
6565
let output: string = '';
6666
let exitCode: number = 0;
6767

68-
function processOutput(data: Buffer) {
69-
const chunk = data.toString();
70-
output += chunk;
71-
72-
if (!options.silent) {
73-
process.stdout.write(chunk);
74-
}
75-
}
76-
7768
const filteredArgs = args.filter(arg => arg !== '--headless' && arg !== '--');
7869
const executable = process.platform === 'linux' ? 'unity-hub' : this.executable;
7970
const execArgs = process.platform === 'linux' ? ['--headless', ...filteredArgs] : ['--', '--headless', ...filteredArgs];
@@ -86,16 +77,57 @@ export class UnityHub {
8677
fs.accessSync(this.executable, fs.constants.R_OK | fs.constants.X_OK);
8778
}
8879

80+
const ignoredLines = [
81+
`This error originated either by throwing inside of an async function without a catch block`,
82+
`Unexpected error attempting to determine if executable file exists`,
83+
`dri3 extension not supported`,
84+
`Failed to connect to the bus:`,
85+
`Checking for beta autoupdate feature for deb/rpm distributions`,
86+
`Found package-type: deb`,
87+
`XPC error for connection com.apple.backupd.sandbox.xpc: Connection invalid`
88+
];
89+
8990
try {
9091
exitCode = await new Promise<number>((resolve, reject) => {
92+
const tasksComplete = 'All Tasks Completed Successfully.';
9193
const child = spawn(executable, execArgs, {
9294
stdio: ['ignore', 'pipe', 'pipe'],
9395
});
94-
9596
const sigintHandler = () => child.kill('SIGINT');
9697
const sigtermHandler = () => child.kill('SIGTERM');
9798
process.once('SIGINT', sigintHandler);
9899
process.once('SIGTERM', sigtermHandler);
100+
function processOutput(data: Buffer) {
101+
try {
102+
const chunk = data.toString();
103+
let outputLines: string[] = [];
104+
const lines = chunk.split('\n');
105+
106+
for (const line of lines) {
107+
if (line.trim().length === 0 ||
108+
ignoredLines.some(ignored => line.includes(ignored))) {
109+
continue;
110+
}
111+
112+
outputLines.push(line);
113+
}
114+
115+
const outputLine = outputLines.join('\n');
116+
output += `${outputLine}\n`;
117+
118+
if (!options.silent) {
119+
process.stdout.write(`${outputLine}\n`);
120+
}
121+
122+
if (output.includes(tasksComplete)) {
123+
child.kill('SIGTERM');
124+
}
125+
} catch (error: any) {
126+
if (error.code !== 'EPIPE') {
127+
throw error;
128+
}
129+
}
130+
}
99131
child.stdout.on('data', processOutput);
100132
child.stderr.on('data', processOutput);
101133
child.on('error', (error) => {
@@ -130,16 +162,6 @@ export class UnityHub {
130162
throw new Error(`Failed to execute Unity Hub: [${exitCode}] ${errorMessage}`);
131163
}
132164
}
133-
134-
const ignoredLines = [
135-
`This error originated either by throwing inside of an async function without a catch block`,
136-
`Unexpected error attempting to determine if executable file exists`,
137-
`dri3 extension not supported`,
138-
`Failed to connect to the bus:`,
139-
`Checking for beta autoupdate feature for deb/rpm distributions`,
140-
`Found package-type: deb`,
141-
`XPC error for connection com.apple.backupd.sandbox.xpc: Connection invalid`
142-
];
143165
output = output.split('\n')
144166
.filter(line => line.trim().length > 0)
145167
.filter(line => !ignoredLines.some(ignored => line.includes(ignored)))

src/utilities.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,17 @@ export async function Exec(command: string, args: string[], options: ExecOptions
6969
const mustShowCommand = isDebug ? true : options.showCommand ? options.showCommand : false;
7070

7171
function processOutput(data: Buffer) {
72-
const chunk = data.toString();
73-
output += chunk;
72+
try {
73+
const chunk = data.toString();
74+
output += chunk;
7475

75-
if (!isSilent) {
76-
process.stdout.write(chunk);
76+
if (!isSilent && chunk.trim().length > 0) {
77+
process.stdout.write(chunk);
78+
}
79+
} catch (error: any) {
80+
if (error.code !== 'EPIPE') {
81+
throw error;
82+
}
7783
}
7884
}
7985

@@ -235,7 +241,7 @@ export async function TryKillProcess(procInfo: ProcInfo): Promise<number | undef
235241
try {
236242
pid = procInfo.pid;
237243
logger.ci(`Killing process "${procInfo.name}" with pid: ${pid}`);
238-
process.kill(pid);
244+
process.kill(pid, 'SIGTERM');
239245
} catch (error) {
240246
const nodeJsException = error as NodeJS.ErrnoException;
241247
const errorCode = nodeJsException?.code;

0 commit comments

Comments
 (0)