Skip to content

Commit 16d593f

Browse files
committed
finalise output changes
1 parent ca4c026 commit 16d593f

File tree

2 files changed

+63
-24
lines changed

2 files changed

+63
-24
lines changed

dist/index.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32574,9 +32574,13 @@ const escapeShellValue = (value) => {
3257432574
// Escape special characters that could cause shell interpretation issues
3257532575
return value.replace(/(["\\'$`!\s\[\]{}()&|;<>*?#^~])/g, '\\$1');
3257632576
};
32577-
const getTestStatus = (uploadId) => __awaiter(void 0, void 0, void 0, function* () {
32577+
const getTestStatus = (uploadId, apiKey, apiUrl) => __awaiter(void 0, void 0, void 0, function* () {
3257832578
try {
32579-
const statusOutput = (0, child_process_1.execSync)(`npx --yes @devicecloud.dev/dcd status --json ${uploadId}`, { encoding: 'utf-8' });
32579+
let command = `npx --yes @devicecloud.dev/dcd status --json --upload-id ${uploadId} --api-key ${escapeShellValue(apiKey)}`;
32580+
if (apiUrl) {
32581+
command += ` --api-url ${escapeShellValue(apiUrl)}`;
32582+
}
32583+
const statusOutput = (0, child_process_1.execSync)(command, { encoding: 'utf-8' });
3258032584
return JSON.parse(statusOutput);
3258132585
}
3258232586
catch (error) {
@@ -32585,6 +32589,7 @@ const getTestStatus = (uploadId) => __awaiter(void 0, void 0, void 0, function*
3258532589
}
3258632590
});
3258732591
const run = () => __awaiter(void 0, void 0, void 0, function* () {
32592+
var _a;
3258832593
try {
3258932594
const { additionalAppBinaryIds, additionalAppFiles, androidApiLevel, androidDevice, apiKey, apiUrl, appBinaryId, appFilePath, async, deviceLocale, downloadArtifacts, env, excludeFlows, excludeTags, googlePlay, ignoreShaCheck, includeTags, iOSVersion, iosDevice, maestroVersion, name, orientation, report, retry, workspaceFolder, x86Arch, } = yield (0, params_1.getParameters)();
3259032595
const params = {
@@ -32634,15 +32639,28 @@ const run = () => __awaiter(void 0, void 0, void 0, function* () {
3263432639
});
3263532640
}
3263632641
// Execute the test command and capture the upload ID
32637-
const testOutput = (0, child_process_1.execSync)(`npx --yes @devicecloud.dev/dcd cloud ${paramsString} --quiet`, { encoding: 'utf-8' });
32638-
// Extract upload ID from the console URL in the output
32639-
const urlMatch = testOutput.match(/https:\/\/console\.devicecloud\.dev\/results\?upload=([a-zA-Z0-9-]+)/);
32640-
const uploadId = urlMatch ? urlMatch[1] : '';
32642+
let uploadId = null;
32643+
let testOutput;
32644+
try {
32645+
testOutput = (0, child_process_1.execSync)(`npx --yes @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;
32650+
if (exitCode === 1) {
32651+
throw new Error('DeviceCloud CLI failed to run - check your parameters or contact support');
32652+
}
32653+
}
32654+
finally {
32655+
console.log('test output', testOutput);
32656+
uploadId =
32657+
((_a = testOutput === null || testOutput === void 0 ? void 0 : testOutput.match(/https:\/\/console\.devicecloud\.dev\/results\?upload=([a-zA-Z0-9-]+)/)) === null || _a === void 0 ? void 0 : _a[1]) || null;
32658+
}
3264132659
if (!uploadId) {
3264232660
throw new Error('Failed to get upload ID from console URL');
3264332661
}
3264432662
// Get the test status and results
32645-
const result = yield getTestStatus(uploadId);
32663+
const result = yield getTestStatus(uploadId, apiKey, apiUrl);
3264632664
if (result) {
3264732665
// Set outputs based on the status results
3264832666
(0, core_1.setOutput)('DEVICE_CLOUD_CONSOLE_URL', result.consoleUrl || '');

src/index.ts

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ interface StatusResponse {
2020
}
2121

2222
const getTestStatus = async (
23-
uploadId: string
23+
uploadId: string,
24+
apiKey: string,
25+
apiUrl?: string
2426
): Promise<StatusResponse | null> => {
2527
try {
26-
const statusOutput = execSync(
27-
`npx --yes @devicecloud.dev/dcd status --json ${uploadId}`,
28-
{ encoding: 'utf-8' }
29-
);
28+
let command = `npx --yes @devicecloud.dev/dcd status --json --upload-id ${uploadId} --api-key ${escapeShellValue(
29+
apiKey
30+
)}`;
31+
if (apiUrl) {
32+
command += ` --api-url ${escapeShellValue(apiUrl)}`;
33+
}
34+
const statusOutput = execSync(command, { encoding: 'utf-8' });
3035
return JSON.parse(statusOutput);
3136
} catch (error) {
3237
console.warn('Failed to get test status:', error);
@@ -115,23 +120,36 @@ const run = async (): Promise<void> => {
115120
}
116121

117122
// Execute the test command and capture the upload ID
118-
const testOutput = execSync(
119-
`npx --yes @devicecloud.dev/dcd cloud ${paramsString} --quiet`,
120-
{ encoding: 'utf-8' }
121-
);
122-
123-
// Extract upload ID from the console URL in the output
124-
const urlMatch = testOutput.match(
125-
/https:\/\/console\.devicecloud\.dev\/results\?upload=([a-zA-Z0-9-]+)/
126-
);
127-
const uploadId = urlMatch ? urlMatch[1] : '';
123+
let uploadId: string | null = null;
124+
125+
let testOutput;
126+
try {
127+
testOutput = execSync(
128+
`npx --yes @devicecloud.dev/dcd cloud ${paramsString} --quiet`,
129+
{ encoding: 'utf-8' }
130+
);
131+
} catch (e: any) {
132+
testOutput = e.output[1].toString();
133+
const exitCode = e.status || 1;
134+
if (exitCode === 1) {
135+
throw new Error(
136+
'DeviceCloud CLI failed to run - check your parameters or contact support'
137+
);
138+
}
139+
} finally {
140+
console.log('test output', testOutput);
141+
uploadId =
142+
testOutput?.match(
143+
/https:\/\/console\.devicecloud\.dev\/results\?upload=([a-zA-Z0-9-]+)/
144+
)?.[1] || null;
145+
}
128146

129147
if (!uploadId) {
130148
throw new Error('Failed to get upload ID from console URL');
131149
}
132150

133151
// Get the test status and results
134-
const result = await getTestStatus(uploadId);
152+
const result = await getTestStatus(uploadId, apiKey, apiUrl);
135153

136154
if (result) {
137155
// Set outputs based on the status results
@@ -144,7 +162,10 @@ const run = async (): Promise<void> => {
144162
name: test.name,
145163
status: test.status,
146164
}));
147-
setOutput('DEVICE_CLOUD_FLOW_RESULTS', JSON.stringify(flowResults));
165+
setOutput(
166+
'DEVICE_CLOUD_FLOW_RESULTS',
167+
JSON.stringify(flowResults, null, 2)
168+
);
148169

149170
if (result.status === 'PASSED') {
150171
console.info('Successfully completed test run.');

0 commit comments

Comments
 (0)