Skip to content

Commit 049ae08

Browse files
add markbaseline and baseline option
1 parent 373420f commit 049ae08

File tree

8 files changed

+29
-8
lines changed

8 files changed

+29
-8
lines changed

src/commander/commander.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ program
1717
.description('CLI to help you run your SmartUI tests on LambdaTest platform')
1818
.version(`v${version}`)
1919
.option('-c --config <filepath>', 'Config file path')
20+
.option('--markBaseline', 'Mark this build baseline')
21+
.option('--baselineBranch <string>', 'Mark this build baseline')
2022
.addCommand(exec)
2123
.addCommand(capture)
2224
.addCommand(configWeb)

src/lib/ctx.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ export default (options: Record<string, string>): Context => {
144144
ignorePattern: ignoreFilePattern,
145145
fetchResults: fetchResultObj,
146146
fetchResultsFileName: fetchResultsFileObj,
147+
baselineBranch: options.baselineBranch || ''
147148
},
148149
cliVersion: version,
149150
totalSnapshots: -1,

src/lib/git.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,27 @@ export function isGitRepo(): boolean {
2727
}
2828

2929
export default (ctx: Context): Git => {
30+
if (ctx.env.SMART_GIT) {
31+
ctx.env.BASELINE_BRANCH = ''
32+
if (ctx.options.baselineBranch !== '') {
33+
ctx.env.SMART_GIT = false
34+
}
35+
}
3036
if (ctx.env.SMARTUI_GIT_INFO_FILEPATH) {
3137
let gitInfo = JSON.parse(fs.readFileSync(ctx.env.SMARTUI_GIT_INFO_FILEPATH, 'utf-8'));
3238

39+
if (ctx.options.markBaseline) {
40+
ctx.env.BASELINE_BRANCH = ctx.env.CURRENT_BRANCH || gitInfo.branch || ''
41+
ctx.env.SMART_GIT = false
42+
}
43+
3344
return {
3445
branch: ctx.env.CURRENT_BRANCH || gitInfo.branch || '',
3546
commitId: gitInfo.commit_id.slice(0,6) || '',
3647
commitMessage: gitInfo.commit_body || '',
3748
commitAuthor: gitInfo.commit_author || '',
3849
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${gitInfo.commit_id}` : '',
39-
baselineBranch: ctx.env.BASELINE_BRANCH || ''
50+
baselineBranch: ctx.options.baselineBranch || ctx.env.BASELINE_BRANCH || ''
4051
}
4152
} else {
4253
const splitCharacter = '<##>';
@@ -52,13 +63,18 @@ export default (ctx: Context): Git => {
5263
var branch = ctx.env.CURRENT_BRANCH || branchAndTags[0];
5364
var tags = branchAndTags.slice(1);
5465

66+
if (ctx.options.markBaseline) {
67+
ctx.env.BASELINE_BRANCH = branch || ''
68+
ctx.env.SMART_GIT = false
69+
}
70+
5571
return {
5672
branch: branch || '',
5773
commitId: res[0] || '',
5874
commitMessage: res[2] || '',
5975
commitAuthor: res[7] || '',
6076
githubURL: (ctx.env.GITHUB_ACTIONS) ? `${constants.GITHUB_API_HOST}/repos/${process.env.GITHUB_REPOSITORY}/statuses/${res[1]}` : '',
61-
baselineBranch: ctx.env.BASELINE_BRANCH || ''
77+
baselineBranch: ctx.options.baselineBranch || ctx.env.BASELINE_BRANCH || ''
6278
};
6379
}
6480
}

src/lib/httpClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ export default class httpClient {
202202
}
203203
}
204204

205-
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean, smartGit: boolean) {
205+
createBuild(git: Git, config: any, log: Logger, buildName: string, isStartExec: boolean, smartGit: boolean, markBaseline: boolean) {
206206
return this.request({
207207
url: '/build',
208208
method: 'POST',
@@ -212,7 +212,8 @@ export default class httpClient {
212212
buildName,
213213
isStartExec,
214214
packageVersion: pkgJSON.version,
215-
smartGit
215+
smartGit,
216+
markBaseline
216217
}
217218
}, log)
218219
}

src/lib/snapshotQueue.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export default class Queue {
350350
} else {
351351
if (!this.ctx.build?.id) {
352352
if (this.ctx.authenticatedInitially) {
353-
let resp = await this.ctx.client.createBuild(this.ctx.git, this.ctx.config, this.ctx.log, this.ctx.build.name);
353+
let resp = await this.ctx.client.createBuild(this.ctx.git, this.ctx.config, this.ctx.log, this.ctx.build.name, false, false, false);
354354
this.ctx.build = {
355355
id: resp.data.buildId,
356356
name: resp.data.buildName,

src/tasks/createBuild.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1010
updateLogContext({task: 'createBuild'});
1111

1212
try {
13-
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT);
13+
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT, ctx.options.markBaseline);
1414
ctx.build = {
1515
id: resp.data.buildId,
1616
name: resp.data.buildName,

src/tasks/createBuildExec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default (ctx: Context): ListrTask<Context, ListrRendererFactory, ListrRen
1212

1313
try {
1414
if (ctx.authenticatedInitially && !ctx.config.skipBuildCreation) {
15-
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT);
15+
let resp = await ctx.client.createBuild(ctx.git, ctx.config, ctx.log, ctx.build.name, ctx.isStartExec, ctx.env.SMART_GIT, ctx.options.markBaseline);
1616
ctx.build = {
1717
id: resp.data.buildId,
1818
name: resp.data.buildName,

src/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ export interface Context {
5959
stripExtension?: boolean,
6060
ignorePattern?: Array<string>,
6161
fetchResults?: boolean,
62-
fetchResultsFileName?: string
62+
fetchResultsFileName?: string,
63+
baselineBranch?: string
6364
}
6465
cliVersion: string;
6566
totalSnapshots: number;

0 commit comments

Comments
 (0)