Skip to content

Commit 7cc5681

Browse files
Merge pull request #443 from LambdaTest/stage
Stage
2 parents 6349ea6 + c30c7dc commit 7cc5681

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdatest/smartui-cli",
3-
"version": "4.1.46",
3+
"version": "4.1.47",
44
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
55
"files": [
66
"dist/**/*"

src/lib/httpClient.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,19 @@ export default class httpClient {
539539
}, ctx.log)
540540
}
541541

542+
getS3PreSignedURLForCaps(ctx: Context, capsBuildId: string, capsProjectToken: string) {
543+
return this.request({
544+
url: `/loguploadurl`,
545+
method: 'POST',
546+
headers: { 'Content-Type': 'application/json',
547+
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken
548+
},
549+
data: {
550+
buildId: capsBuildId
551+
}
552+
}, ctx.log)
553+
}
554+
542555
getS3PresignedURLForSnapshotUpload(ctx: Context, snapshotName: string, snapshotUuid: string) {
543556
return this.request({
544557
url: `/snapshotuploadurl`,
@@ -601,7 +614,7 @@ export default class httpClient {
601614
}
602615

603616
uploadLogs(ctx: Context, uploadURL: string) {
604-
const fileStream = fs.createReadStream(constants.LOG_FILE_PATH);
617+
const logContent = fs.readFileSync(constants.LOG_FILE_PATH);
605618
const { size } = fs.statSync(constants.LOG_FILE_PATH);
606619

607620
return this.request({
@@ -611,7 +624,7 @@ export default class httpClient {
611624
'Content-Type': 'text/plain',
612625
'Content-Length': size,
613626
},
614-
data: fileStream,
627+
data: logContent,
615628
maxBodyLength: Infinity, // prevent axios from limiting the body size
616629
maxContentLength: Infinity, // prevent axios from limiting the content size
617630
}, ctx.log)
@@ -631,6 +644,22 @@ export default class httpClient {
631644
}, ctx.log);
632645
}
633646

647+
sendCliLogsToLSRSForCaps(ctx: Context, capsBuildId: string, capsProjectToken: string) {
648+
const logContent = fs.readFileSync(constants.LOG_FILE_PATH, 'utf-8');
649+
return this.request({
650+
url: `/upload/logs`,
651+
method: 'POST',
652+
headers: { 'Content-Type': 'application/json',
653+
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken
654+
},
655+
data: {
656+
buildId: capsBuildId,
657+
logContent: logContent,
658+
skipLogging: true
659+
}
660+
}, ctx.log);
661+
}
662+
634663
uploadSnapshotToS3(ctx: Context, uploadURL: string, snapshot: Snapshot) {
635664
return this.request({
636665
url: uploadURL,

src/tasks/finalizeBuild.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
3333
ctx.log.debug('Ping polling stopped immediately from Finalize Build');
3434
}
3535

36+
37+
let uploadedCliLogsBuildIds = new Set<string>();
38+
3639
for (const [sessionId, capabilities] of ctx.sessionCapabilitiesMap.entries()) {
3740
try {
3841
const buildId = capabilities?.buildId || '';
@@ -56,6 +59,18 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
5659
}
5760
ctx.log.debug(`Capabilities for sessionId ${sessionId}: ${JSON.stringify(capabilities)}`)
5861
if (buildId && projectToken) {
62+
if (ctx.isSnapshotCaptured && !uploadedCliLogsBuildIds.has(buildId)) {
63+
let uploadCLILogsToS3 = ctx.config.useLambdaInternal || uploadDomToS3ViaEnv;
64+
if (!uploadCLILogsToS3) {
65+
ctx.log.debug(`Log file to be uploaded`)
66+
let resp = await ctx.client.getS3PreSignedURLForCaps(ctx, buildId, projectToken);
67+
await ctx.client.uploadLogs(ctx, resp.data.url);
68+
} else {
69+
ctx.log.debug(`Log file to be uploaded via LSRS`)
70+
ctx.client.sendCliLogsToLSRSForCaps(ctx, buildId, projectToken);
71+
}
72+
uploadedCliLogsBuildIds.add(buildId);
73+
}
5974
await ctx.client.finalizeBuildForCapsWithToken(buildId, totalSnapshots, projectToken, ctx.log);
6075
if (ctx.autoTunnelStarted) {
6176
await startPollingForTunnel(ctx, buildId, false, projectToken, capabilities?.buildName);

0 commit comments

Comments
 (0)