From c6e1eaf37cda223834a06d0bab5b71fe683d0ac6 Mon Sep 17 00:00:00 2001 From: Damian Sobczak Date: Tue, 7 Apr 2020 16:00:10 +0200 Subject: [PATCH 1/4] fix: deploy only once if two projects share the same job --- .../run/jobs-builder/deploy-job-builder.ts | 33 ++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/commands/run/jobs-builder/deploy-job-builder.ts b/src/commands/run/jobs-builder/deploy-job-builder.ts index addd48d..b5bf558 100644 --- a/src/commands/run/jobs-builder/deploy-job-builder.ts +++ b/src/commands/run/jobs-builder/deploy-job-builder.ts @@ -27,7 +27,7 @@ export class DeployJobBuilder { ]); build(projects: Project[], params: ParamsResult): JobDescriptor[] { - return projects + const mappedProjects = projects .filter((project: Project) => this.projectNameMap.has(project)) .map((project: Project) => ({ displayName: project, @@ -36,6 +36,37 @@ export class DeployJobBuilder { parameters: this.mapProjectParams(project, params), }, })); + + return this.mergeDoubledProjects(mappedProjects); + } + + private mergeDoubledProjects(projects: JobDescriptor[]) { + const filteredProjects = new Map(); + + projects.forEach(project => { + const currentProject = filteredProjects.get(project.opts.name); + + if (currentProject) { + Object.keys(project.opts.parameters).forEach(key => { + console.log( + project.opts.parameters[key] !== currentProject.opts.parameters[key], + key, + key.includes(project.displayName), + ); + + if ( + project.opts.parameters[key] !== currentProject.opts.parameters[key] && + key.includes(project.displayName) + ) { + currentProject.opts.parameters[key] = project.opts.parameters[key]; + } + }); + } + + filteredProjects.set(project.opts.name, currentProject || project); + }); + + return [...filteredProjects.values()]; } private mapProjectName(input: Project): string { From 9b936f88549bbec704c4ca48dcfb4c3c217a825b Mon Sep 17 00:00:00 2001 From: Damian Sobczak Date: Tue, 7 Apr 2020 16:15:56 +0200 Subject: [PATCH 2/4] fix: remove debug console.log() call --- src/commands/run/jobs-builder/deploy-job-builder.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/commands/run/jobs-builder/deploy-job-builder.ts b/src/commands/run/jobs-builder/deploy-job-builder.ts index b5bf558..5988cb0 100644 --- a/src/commands/run/jobs-builder/deploy-job-builder.ts +++ b/src/commands/run/jobs-builder/deploy-job-builder.ts @@ -48,12 +48,6 @@ export class DeployJobBuilder { if (currentProject) { Object.keys(project.opts.parameters).forEach(key => { - console.log( - project.opts.parameters[key] !== currentProject.opts.parameters[key], - key, - key.includes(project.displayName), - ); - if ( project.opts.parameters[key] !== currentProject.opts.parameters[key] && key.includes(project.displayName) From 7be6efe1c6f2ea77ac2aa71d887d26f41577c8ea Mon Sep 17 00:00:00 2001 From: Damian Sobczak Date: Thu, 9 Apr 2020 10:24:48 +0200 Subject: [PATCH 3/4] fix: code review changes --- src/commands/run/jobs-builder/deploy-job-builder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/run/jobs-builder/deploy-job-builder.ts b/src/commands/run/jobs-builder/deploy-job-builder.ts index 5988cb0..07a7476 100644 --- a/src/commands/run/jobs-builder/deploy-job-builder.ts +++ b/src/commands/run/jobs-builder/deploy-job-builder.ts @@ -40,7 +40,7 @@ export class DeployJobBuilder { return this.mergeDoubledProjects(mappedProjects); } - private mergeDoubledProjects(projects: JobDescriptor[]) { + private mergeDoubledProjects(projects: JobDescriptor[]): JobDescriptor[] { const filteredProjects = new Map(); projects.forEach(project => { From 28473d9b8c3e71ffa1dd2e5381e39ff6033c00dc Mon Sep 17 00:00:00 2001 From: Damian Bielecki Date: Thu, 9 Apr 2020 12:31:21 +0200 Subject: [PATCH 4/4] chore: add CR suggestion --- .../run/jobs-builder/deploy-job-builder.ts | 50 +++++++++---------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/src/commands/run/jobs-builder/deploy-job-builder.ts b/src/commands/run/jobs-builder/deploy-job-builder.ts index 07a7476..d46c946 100644 --- a/src/commands/run/jobs-builder/deploy-job-builder.ts +++ b/src/commands/run/jobs-builder/deploy-job-builder.ts @@ -19,15 +19,20 @@ interface DeployJobMobileWikiParams { crowdin_branch: string; } +type DeployProject = Project | 'app-ucp'; + export class DeployJobBuilder { - private projectNameMap = new Map([ + private projectNameMap = new Map([ + ['app-ucp', 'mediawiki-deploy-sandbox-ucp'], ['ucp', 'mediawiki-deploy-sandbox-ucp'], ['app', 'mediawiki-deploy-sandbox-ucp'], ['mobile-wiki', 'mobile-wiki-deploy-sandbox'], ]); build(projects: Project[], params: ParamsResult): JobDescriptor[] { - const mappedProjects = projects + const deployProjects = this.parseDeployProject(projects); + + return deployProjects .filter((project: Project) => this.projectNameMap.has(project)) .map((project: Project) => ({ displayName: project, @@ -36,31 +41,13 @@ export class DeployJobBuilder { parameters: this.mapProjectParams(project, params), }, })); - - return this.mergeDoubledProjects(mappedProjects); } - private mergeDoubledProjects(projects: JobDescriptor[]): JobDescriptor[] { - const filteredProjects = new Map(); - - projects.forEach(project => { - const currentProject = filteredProjects.get(project.opts.name); - - if (currentProject) { - Object.keys(project.opts.parameters).forEach(key => { - if ( - project.opts.parameters[key] !== currentProject.opts.parameters[key] && - key.includes(project.displayName) - ) { - currentProject.opts.parameters[key] = project.opts.parameters[key]; - } - }); - } - - filteredProjects.set(project.opts.name, currentProject || project); - }); - - return [...filteredProjects.values()]; + private parseDeployProject(projects: Project[]): DeployProject[] { + if (projects.includes('app') && projects.includes('ucp')) { + return ['app-ucp', ...projects.filter(project => !['app', 'ucp'].includes(project))]; + } + return projects; } private mapProjectName(input: Project): string { @@ -68,10 +55,21 @@ export class DeployJobBuilder { } private mapProjectParams( - project: Project, + project: DeployProject, input: ParamsResult, ): DeployJobAppAndUcpParams | DeployJobMobileWikiParams { switch (project) { + case 'app-ucp': + return { + sandbox: input.sandbox, + ucp_branch: input.branch, + app_branch: input.branch, + config_branch: input.configBranch, + datacenter: input.datacenter, + crowdin_branch: input.crowdinBranch, + debug: input.debug, + }; + case 'ucp': return { sandbox: input.sandbox,