Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lambdatest/smartui-cli",
"version": "4.1.46",
"version": "4.1.47",
"description": "A command line interface (CLI) to run SmartUI tests on LambdaTest",
"files": [
"dist/**/*"
Expand Down
33 changes: 31 additions & 2 deletions src/lib/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,19 @@ export default class httpClient {
}, ctx.log)
}

getS3PreSignedURLForCaps(ctx: Context, capsBuildId: string, capsProjectToken: string) {
return this.request({
url: `/loguploadurl`,
method: 'POST',
headers: { 'Content-Type': 'application/json',
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken
},
data: {
buildId: capsBuildId
}
}, ctx.log)
}

getS3PresignedURLForSnapshotUpload(ctx: Context, snapshotName: string, snapshotUuid: string) {
return this.request({
url: `/snapshotuploadurl`,
Expand Down Expand Up @@ -598,7 +611,7 @@ export default class httpClient {
}

uploadLogs(ctx: Context, uploadURL: string) {
const fileStream = fs.createReadStream(constants.LOG_FILE_PATH);
const logContent = fs.readFileSync(constants.LOG_FILE_PATH);
const { size } = fs.statSync(constants.LOG_FILE_PATH);

return this.request({
Expand All @@ -608,7 +621,7 @@ export default class httpClient {
'Content-Type': 'text/plain',
'Content-Length': size,
},
data: fileStream,
data: logContent,
maxBodyLength: Infinity, // prevent axios from limiting the body size
maxContentLength: Infinity, // prevent axios from limiting the content size
}, ctx.log)
Expand All @@ -628,6 +641,22 @@ export default class httpClient {
}, ctx.log);
}

sendCliLogsToLSRSForCaps(ctx: Context, capsBuildId: string, capsProjectToken: string) {
const logContent = fs.readFileSync(constants.LOG_FILE_PATH, 'utf-8');
return this.request({
url: `/upload/logs`,
method: 'POST',
headers: { 'Content-Type': 'application/json',
projectToken: capsProjectToken !== '' ? capsProjectToken : this.projectToken
},
data: {
buildId: capsBuildId,
logContent: logContent,
skipLogging: true
}
}, ctx.log);
}

uploadSnapshotToS3(ctx: Context, uploadURL: string, snapshot: Snapshot) {
return this.request({
url: uploadURL,
Expand Down
15 changes: 15 additions & 0 deletions src/tasks/finalizeBuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
ctx.log.debug('Ping polling stopped immediately from Finalize Build');
}


let uploadedCliLogsBuildIds = new Set<string>();

for (const [sessionId, capabilities] of ctx.sessionCapabilitiesMap.entries()) {
try {
const buildId = capabilities?.buildId || '';
Expand All @@ -56,6 +59,18 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
}
ctx.log.debug(`Capabilities for sessionId ${sessionId}: ${JSON.stringify(capabilities)}`)
if (buildId && projectToken) {
if (ctx.isSnapshotCaptured && !uploadedCliLogsBuildIds.has(buildId)) {
let uploadCLILogsToS3 = ctx.config.useLambdaInternal || uploadDomToS3ViaEnv;
if (!uploadCLILogsToS3) {
ctx.log.debug(`Log file to be uploaded`)
let resp = await ctx.client.getS3PreSignedURLForCaps(ctx, buildId, projectToken);
await ctx.client.uploadLogs(ctx, resp.data.url);
} else {
ctx.log.debug(`Log file to be uploaded via LSRS`)
ctx.client.sendCliLogsToLSRSForCaps(ctx, buildId, projectToken);
}
uploadedCliLogsBuildIds.add(buildId);
}
await ctx.client.finalizeBuildForCapsWithToken(buildId, totalSnapshots, projectToken, ctx.log);
if (ctx.autoTunnelStarted) {
await startPollingForTunnel(ctx, buildId, false, projectToken, capabilities?.buildName);
Expand Down