Skip to content

Commit 19734fa

Browse files
authored
Merge pull request #20 from devicecloud-dev/fix-output-logging
fix output logging and version fix
2 parents db0578b + b36ed8d commit 19734fa

File tree

3 files changed

+86
-23
lines changed

3 files changed

+86
-23
lines changed

dist/index.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32570,18 +32570,46 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
3257032570
const core_1 = __nccwpck_require__(2186);
3257132571
const params_1 = __nccwpck_require__(5966);
3257232572
const child_process_1 = __nccwpck_require__(2081);
32573+
const dcdVersionString = '@devicecloud.dev/dcd@>=3.3.6';
3257332574
const escapeShellValue = (value) => {
3257432575
// Escape special characters that could cause shell interpretation issues
3257532576
return value.replace(/(["\\'$`!\s\[\]{}()&|;<>*?#^~])/g, '\\$1');
3257632577
};
32578+
const executeCommand = (command, log = true) => {
32579+
return new Promise((resolve, reject) => {
32580+
const [cmd, ...args] = command.split(' ');
32581+
let output = '';
32582+
const process = (0, child_process_1.spawn)(cmd, args, { shell: true });
32583+
process.stdout.on('data', (data) => {
32584+
const chunk = data.toString();
32585+
output += chunk;
32586+
if (log) {
32587+
console.info(chunk);
32588+
}
32589+
});
32590+
process.stderr.on('data', (data) => {
32591+
const chunk = data.toString();
32592+
output += chunk;
32593+
if (log) {
32594+
console.error(chunk);
32595+
}
32596+
});
32597+
process.on('close', (code) => {
32598+
resolve({ output, exitCode: code !== null && code !== void 0 ? code : 0 });
32599+
});
32600+
process.on('error', (err) => {
32601+
reject(err);
32602+
});
32603+
});
32604+
};
3257732605
const getTestStatus = (uploadId, apiKey, apiUrl) => __awaiter(void 0, void 0, void 0, function* () {
3257832606
try {
32579-
let command = `npx --yes @devicecloud.dev/dcd status --json --upload-id ${uploadId} --api-key ${escapeShellValue(apiKey)}`;
32607+
let command = `npx --yes "${dcdVersionString}" status --json --upload-id ${uploadId} --api-key ${escapeShellValue(apiKey)}`;
3258032608
if (apiUrl) {
3258132609
command += ` --api-url ${escapeShellValue(apiUrl)}`;
3258232610
}
32583-
const statusOutput = (0, child_process_1.execSync)(command, { encoding: 'utf-8' });
32584-
return JSON.parse(statusOutput);
32611+
const { output } = yield executeCommand(command, false);
32612+
return JSON.parse(output);
3258532613
}
3258632614
catch (error) {
3258732615
console.warn('Failed to get test status:', error);
@@ -32640,13 +32668,10 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
3264032668
}
3264132669
// Execute the test command and capture the upload ID
3264232670
let uploadId = null;
32643-
let testOutput;
32671+
let testOutput = '';
3264432672
try {
32645-
testOutput = (0, child_process_1.execSync)(`npx --yes --no-cache @devicecloud.dev/dcd cloud ${paramsString} --quiet`, { encoding: 'utf-8' });
32646-
}
32647-
catch (e) {
32648-
testOutput = e.output[1].toString();
32649-
const exitCode = e.status || 1;
32673+
const { output, exitCode } = yield executeCommand(`npx --yes "${dcdVersionString}" cloud ${paramsString} --quiet`);
32674+
testOutput = output;
3265032675
if (exitCode === 1) {
3265132676
throw new Error('DeviceCloud CLI failed to run - check your parameters or contact support');
3265232677
}
@@ -32675,7 +32700,7 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
3267532700
console.info('Successfully completed test run.');
3267632701
}
3267732702
else if (result.status === 'FAILED') {
32678-
(0, core_1.setFailed)('Test run failed. Check flow results for details.');
32703+
(0, core_1.setFailed)(`Test run failed. Check flow results for details: ${result.consoleUrl}`);
3267932704
}
3268032705
}
3268132706
else {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "dcd-github-action",
33
"description": "run maestro tests on devicecloud.dev",
44
"author": "devicecloud.dev",
5-
"version": "1.3.1",
5+
"version": "1.3.2",
66
"main": "src/index.ts",
77
"license": "MIT",
88
"engines": {

src/index.ts

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { setFailed, setOutput } from '@actions/core';
22
import { getParameters } from './methods/params';
3-
import { execSync } from 'child_process';
3+
import { spawn } from 'child_process';
4+
5+
const dcdVersionString = '@devicecloud.dev/dcd@>=3.3.6';
46

57
const escapeShellValue = (value: string): string => {
68
// Escape special characters that could cause shell interpretation issues
@@ -19,20 +21,56 @@ interface StatusResponse {
1921
appBinaryId?: string;
2022
}
2123

24+
const executeCommand = (
25+
command: string,
26+
log: boolean = true
27+
): Promise<{ output: string; exitCode: number }> => {
28+
return new Promise((resolve, reject) => {
29+
const [cmd, ...args] = command.split(' ');
30+
let output = '';
31+
32+
const process = spawn(cmd, args, { shell: true });
33+
34+
process.stdout.on('data', (data) => {
35+
const chunk = data.toString();
36+
output += chunk;
37+
if (log) {
38+
console.info(chunk);
39+
}
40+
});
41+
42+
process.stderr.on('data', (data) => {
43+
const chunk = data.toString();
44+
output += chunk;
45+
if (log) {
46+
console.error(chunk);
47+
}
48+
});
49+
50+
process.on('close', (code) => {
51+
resolve({ output, exitCode: code ?? 0 });
52+
});
53+
54+
process.on('error', (err) => {
55+
reject(err);
56+
});
57+
});
58+
};
59+
2260
const getTestStatus = async (
2361
uploadId: string,
2462
apiKey: string,
2563
apiUrl?: string
2664
): Promise<StatusResponse | null> => {
2765
try {
28-
let command = `npx --yes @devicecloud.dev/dcd status --json --upload-id ${uploadId} --api-key ${escapeShellValue(
66+
let command = `npx --yes "${dcdVersionString}" status --json --upload-id ${uploadId} --api-key ${escapeShellValue(
2967
apiKey
3068
)}`;
3169
if (apiUrl) {
3270
command += ` --api-url ${escapeShellValue(apiUrl)}`;
3371
}
34-
const statusOutput = execSync(command, { encoding: 'utf-8' });
35-
return JSON.parse(statusOutput);
72+
const { output } = await executeCommand(command, false);
73+
return JSON.parse(output);
3674
} catch (error) {
3775
console.warn('Failed to get test status:', error);
3876
return null;
@@ -121,16 +159,14 @@ const run = async (): Promise<void> => {
121159

122160
// Execute the test command and capture the upload ID
123161
let uploadId: string | null = null;
162+
let testOutput = '';
124163

125-
let testOutput;
126164
try {
127-
testOutput = execSync(
128-
`npx --yes --no-cache @devicecloud.dev/dcd cloud ${paramsString} --quiet`,
129-
{ encoding: 'utf-8' }
165+
const { output, exitCode } = await executeCommand(
166+
`npx --yes "${dcdVersionString}" cloud ${paramsString} --quiet`
130167
);
131-
} catch (e: any) {
132-
testOutput = e.output[1].toString();
133-
const exitCode = e.status || 1;
168+
testOutput = output;
169+
134170
if (exitCode === 1) {
135171
throw new Error(
136172
'DeviceCloud CLI failed to run - check your parameters or contact support'
@@ -169,7 +205,9 @@ const run = async (): Promise<void> => {
169205
if (result.status === 'PASSED') {
170206
console.info('Successfully completed test run.');
171207
} else if (result.status === 'FAILED') {
172-
setFailed('Test run failed. Check flow results for details.');
208+
setFailed(
209+
`Test run failed. Check flow results for details: ${result.consoleUrl}`
210+
);
173211
}
174212
} else {
175213
setOutput('DEVICE_CLOUD_UPLOAD_STATUS', 'ERROR');

0 commit comments

Comments
 (0)