Skip to content

Commit 282881d

Browse files
refactor terminal outputs
1 parent 8770462 commit 282881d

3 files changed

Lines changed: 93 additions & 137 deletions

File tree

dist/index.js

Lines changed: 45 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -58505,6 +58505,8 @@ const AppStoreConnectClient_1 = __nccwpck_require__(7486);
5850558505
const xcodebuild = '/usr/bin/xcodebuild';
5850658506
const xcrun = '/usr/bin/xcrun';
5850758507
const WORKSPACE = process.env.GITHUB_WORKSPACE || process.cwd();
58508+
const blue = '\u001b[34m';
58509+
const reset = '\u001b[0m';
5850858510
async function GetOrSetXcodeVersion() {
5850958511
let xcodeVersionString = core.getInput('xcode-version');
5851058512
if (xcodeVersionString) {
@@ -59480,17 +59482,23 @@ async function getWhatsNew() {
5948059482
async function execXcodeBuild(xcodeBuildArgs) {
5948159483
let exitCode = 1;
5948259484
let output = '';
59483-
exitCode = await (0, exec_1.exec)(xcodebuild, xcodeBuildArgs, {
59484-
listeners: {
59485-
stdout: (data) => {
59486-
output += data.toString();
59487-
},
59488-
stderr: (data) => {
59489-
output += data.toString();
59485+
core.startGroup(`${blue}xcodebuild ${xcodeBuildArgs.join(' ')}${reset}`);
59486+
try {
59487+
exitCode = await (0, exec_1.exec)(xcodebuild, xcodeBuildArgs, {
59488+
listeners: {
59489+
stdout: (data) => {
59490+
output += data.toString();
59491+
},
59492+
stderr: (data) => {
59493+
output += data.toString();
59494+
},
5949059495
},
59491-
},
59492-
ignoreReturnCode: true
59493-
});
59496+
ignoreReturnCode: true
59497+
});
59498+
}
59499+
finally {
59500+
core.endGroup();
59501+
}
5949459502
if (exitCode !== 0) {
5949559503
await parseBundleLog(output);
5949659504
throw new Error(`xcodebuild exited with code: ${exitCode}`);
@@ -59508,22 +59516,28 @@ async function execWithXcBeautify(xcodeBuildArgs) {
5950859516
const xcBeautifyProcess = (0, child_process_1.spawn)('xcbeautify', ['--quiet', '--is-ci', '--disable-logging'], {
5950959517
stdio: ['pipe', process.stdout, process.stderr]
5951059518
});
59511-
core.info(`[command]${xcodebuild} ${xcodeBuildArgs.join(' ')}`);
59519+
core.startGroup(`${blue}${xcodebuild} ${xcodeBuildArgs.join(' ')}${reset}`);
5951259520
let errorOutput = '';
59513-
const exitCode = await (0, exec_1.exec)(xcodebuild, xcodeBuildArgs, {
59514-
listeners: {
59515-
stdout: (data) => {
59516-
xcBeautifyProcess.stdin.write(data);
59521+
let exitCode = 1;
59522+
try {
59523+
exitCode = await (0, exec_1.exec)(xcodebuild, xcodeBuildArgs, {
59524+
listeners: {
59525+
stdout: (data) => {
59526+
xcBeautifyProcess.stdin.write(data);
59527+
},
59528+
stderr: (data) => {
59529+
xcBeautifyProcess.stdin.write(data);
59530+
errorOutput += data.toString();
59531+
}
5951759532
},
59518-
stderr: (data) => {
59519-
xcBeautifyProcess.stdin.write(data);
59520-
errorOutput += data.toString();
59521-
}
59522-
},
59523-
silent: true,
59524-
ignoreReturnCode: true
59525-
});
59526-
xcBeautifyProcess.stdin.end();
59533+
silent: true,
59534+
ignoreReturnCode: true
59535+
});
59536+
}
59537+
finally {
59538+
xcBeautifyProcess.stdin.end();
59539+
core.endGroup();
59540+
}
5952759541
await new Promise((resolve, reject) => {
5952859542
xcBeautifyProcess.stdin.on('finish', () => {
5952959543
xcBeautifyProcess.on('close', (code) => {
@@ -59546,48 +59560,25 @@ async function execXcRun(args) {
5954659560
let output = '';
5954759561
let errorOutput = '';
5954859562
let isJsonOutput = args.includes('--output-format') && args.includes('json');
59549-
if (!core.isDebug()) {
59550-
core.info(`[command]xcrun ${args.join(' ')}`);
59551-
core.startGroup(`xcrun ${args.join(' ')}`);
59552-
}
59553-
else {
59554-
args.push('--verbose');
59563+
if (core.isDebug()) {
59564+
args.push('-verbose');
5955559565
}
59556-
let partialLine = '';
59566+
core.startGroup(`${blue}xcrun ${args.join(' ')}${reset}`);
5955759567
try {
5955859568
exitCode = await (0, exec_1.exec)(xcrun, args, {
5955959569
listeners: {
5956059570
stdout: (data) => {
59561-
partialLine += data.toString();
59562-
if (partialLine.includes('\n')) {
59563-
const lines = partialLine.split('\n');
59564-
lines.slice(0, -1).forEach(l => {
59565-
output += `${l}\n`;
59566-
if (!core.isDebug()) {
59567-
core.info(l);
59568-
}
59569-
});
59570-
partialLine = lines[lines.length - 1];
59571-
}
59571+
output += data.toString();
5957259572
},
5957359573
stderr: (data) => {
5957459574
errorOutput += data.toString();
5957559575
}
5957659576
},
59577-
silent: !core.isDebug(),
5957859577
ignoreReturnCode: true
5957959578
});
5958059579
}
5958159580
finally {
59582-
if (partialLine.length > 0) {
59583-
output += partialLine + '\n';
59584-
if (!core.isDebug()) {
59585-
core.info(partialLine);
59586-
}
59587-
}
59588-
if (!core.isDebug()) {
59589-
core.endGroup();
59590-
}
59581+
core.endGroup();
5959159582
if (isJsonOutput) {
5959259583
const jsonMatch = output.match(/\{[\s\S]*\}/);
5959359584
if (jsonMatch) {
@@ -59608,30 +59599,19 @@ async function execXcRun(args) {
5960859599
async function execGit(args) {
5960959600
let exitCode = 1;
5961059601
let output = '';
59611-
if (!core.isDebug()) {
59612-
core.info(`[command]git ${args.join(' ')}`);
59613-
core.startGroup(`git ${args.join(' ')}`);
59614-
}
59602+
core.startGroup(`${blue}git ${args.join(' ')}${reset}`);
5961559603
try {
5961659604
exitCode = await (0, exec_1.exec)('git', args, {
5961759605
listeners: {
5961859606
stdout: (data) => {
5961959607
output += data.toString();
59620-
},
59621-
stdline: (data) => {
59622-
if (!core.isDebug()) {
59623-
core.info(data);
59624-
}
5962559608
}
5962659609
},
59627-
silent: !core.isDebug(),
5962859610
ignoreReturnCode: true
5962959611
});
5963059612
}
5963159613
finally {
59632-
if (!core.isDebug()) {
59633-
core.endGroup();
59634-
}
59614+
core.endGroup();
5963559615
}
5963659616
if (exitCode > 0) {
5963759617
(0, utilities_1.log)(output, 'error');

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.

src/xcode.ts

Lines changed: 47 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ const xcodebuild = '/usr/bin/xcodebuild';
3030
const xcrun = '/usr/bin/xcrun';
3131
const WORKSPACE = process.env.GITHUB_WORKSPACE || process.cwd();
3232

33+
const blue = '\u001b[34m';
34+
const reset = '\u001b[0m';
35+
3336
export async function GetOrSetXcodeVersion(): Promise<SemVer> {
3437
let xcodeVersionString = core.getInput('xcode-version');
3538

@@ -1224,17 +1227,23 @@ async function execXcodeBuild(xcodeBuildArgs: string[]): Promise<string> {
12241227
let exitCode: number = 1;
12251228
let output: string = '';
12261229

1227-
exitCode = await exec(xcodebuild, xcodeBuildArgs, {
1228-
listeners: {
1229-
stdout: (data: Buffer) => {
1230-
output += data.toString();
1231-
},
1232-
stderr: (data: Buffer) => {
1233-
output += data.toString();
1230+
core.startGroup(`${blue}xcodebuild ${xcodeBuildArgs.join(' ')}${reset}`);
1231+
1232+
try {
1233+
exitCode = await exec(xcodebuild, xcodeBuildArgs, {
1234+
listeners: {
1235+
stdout: (data: Buffer) => {
1236+
output += data.toString();
1237+
},
1238+
stderr: (data: Buffer) => {
1239+
output += data.toString();
1240+
},
12341241
},
1235-
},
1236-
ignoreReturnCode: true
1237-
});
1242+
ignoreReturnCode: true
1243+
});
1244+
} finally {
1245+
core.endGroup();
1246+
}
12381247

12391248
if (exitCode !== 0) {
12401249
await parseBundleLog(output);
@@ -1256,24 +1265,28 @@ async function execWithXcBeautify(xcodeBuildArgs: string[]) {
12561265
stdio: ['pipe', process.stdout, process.stderr]
12571266
});
12581267

1259-
core.info(`[command]${xcodebuild} ${xcodeBuildArgs.join(' ')}`);
1268+
core.startGroup(`${blue}${xcodebuild} ${xcodeBuildArgs.join(' ')}${reset}`);
1269+
let errorOutput: string = '';
1270+
let exitCode: number = 1;
12601271

1261-
let errorOutput = '';
1262-
const exitCode = await exec(xcodebuild, xcodeBuildArgs, {
1263-
listeners: {
1264-
stdout: (data: Buffer) => {
1265-
xcBeautifyProcess.stdin.write(data);
1272+
try {
1273+
exitCode = await exec(xcodebuild, xcodeBuildArgs, {
1274+
listeners: {
1275+
stdout: (data: Buffer) => {
1276+
xcBeautifyProcess.stdin.write(data);
1277+
},
1278+
stderr: (data: Buffer) => {
1279+
xcBeautifyProcess.stdin.write(data);
1280+
errorOutput += data.toString();
1281+
}
12661282
},
1267-
stderr: (data: Buffer) => {
1268-
xcBeautifyProcess.stdin.write(data);
1269-
errorOutput += data.toString();
1270-
}
1271-
},
1272-
silent: true,
1273-
ignoreReturnCode: true
1274-
});
1275-
1276-
xcBeautifyProcess.stdin.end();
1283+
silent: true,
1284+
ignoreReturnCode: true
1285+
});
1286+
} finally {
1287+
xcBeautifyProcess.stdin.end();
1288+
core.endGroup();
1289+
}
12771290

12781291
await new Promise<void>((resolve, reject) => {
12791292
xcBeautifyProcess.stdin.on('finish', () => {
@@ -1299,52 +1312,26 @@ async function execXcRun(args: string[]): Promise<string> {
12991312
let errorOutput: string = '';
13001313
let isJsonOutput = args.includes('--output-format') && args.includes('json');
13011314

1302-
if (!core.isDebug()) {
1303-
core.info(`[command]xcrun ${args.join(' ')}`);
1304-
core.startGroup(`xcrun ${args.join(' ')}`);
1305-
} else {
1306-
args.push('--verbose');
1315+
if (core.isDebug()) {
1316+
args.push('-verbose');
13071317
}
13081318

1309-
let partialLine = '';
1319+
core.startGroup(`${blue}xcrun ${args.join(' ')}${reset}`);
1320+
13101321
try {
13111322
exitCode = await exec(xcrun, args, {
13121323
listeners: {
13131324
stdout: (data: Buffer) => {
1314-
partialLine += data.toString();
1315-
1316-
if (partialLine.includes('\n')) {
1317-
const lines = partialLine.split('\n');
1318-
lines.slice(0, -1).forEach(l => {
1319-
output += `${l}\n`;
1320-
1321-
if (!core.isDebug()) {
1322-
core.info(l);
1323-
}
1324-
});
1325-
partialLine = lines[lines.length - 1];
1326-
}
1325+
output += data.toString();
13271326
},
13281327
stderr: (data: Buffer) => {
13291328
errorOutput += data.toString();
13301329
}
13311330
},
1332-
silent: !core.isDebug(),
13331331
ignoreReturnCode: true
13341332
});
13351333
} finally {
1336-
// process any remaining partial line
1337-
if (partialLine.length > 0) {
1338-
output += partialLine + '\n';
1339-
1340-
if (!core.isDebug()) {
1341-
core.info(partialLine);
1342-
}
1343-
}
1344-
1345-
if (!core.isDebug()) {
1346-
core.endGroup();
1347-
}
1334+
core.endGroup();
13481335

13491336
if (isJsonOutput) { // pretty print json output
13501337
// Use regex to extract the first JSON object from the output
@@ -1372,30 +1359,19 @@ async function execGit(args: string[]): Promise<string> {
13721359
let exitCode: number = 1;
13731360
let output: string = '';
13741361

1375-
if (!core.isDebug()) {
1376-
core.info(`[command]git ${args.join(' ')}`);
1377-
core.startGroup(`git ${args.join(' ')}`);
1378-
}
1362+
core.startGroup(`${blue}git ${args.join(' ')}${reset}`);
13791363

13801364
try {
13811365
exitCode = await exec('git', args, {
13821366
listeners: {
13831367
stdout: (data: Buffer) => {
13841368
output += data.toString();
1385-
},
1386-
stdline: (data: string) => {
1387-
if (!core.isDebug()) {
1388-
core.info(data);
1389-
}
13901369
}
13911370
},
1392-
silent: !core.isDebug(),
13931371
ignoreReturnCode: true
13941372
});
13951373
} finally {
1396-
if (!core.isDebug()) {
1397-
core.endGroup();
1398-
}
1374+
core.endGroup();
13991375
}
14001376

14011377
if (exitCode > 0) {

0 commit comments

Comments
 (0)