From cc745e885148c210b41cd8c8779424e22b0469bc Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Thu, 30 Nov 2023 17:29:29 -0500 Subject: [PATCH 01/27] working locally with hardcoded values --- .../src/helpers/dependency-helpers.ts | 27 ++++++++++++++++++- src/entrypoints/localApp.ts | 11 +++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index f6a8f27f9..5259705b5 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -33,12 +33,37 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: } } -export async function prepareBuildAndGetDependencies(repoName: string, projectName: string, baseUrl: string) { +//TODO: define buildDependencies type +async function downloadBuildDependencies(buildDependencies, repoDir: string) { + console.log('STARTING DOWNLOADING BUILD DEPENDENCIES'); + console.log('buildDependencies:', buildDependencies); + const buildDir = buildDependencies.buildDirectory ?? repoDir; + console.log('buildDirectory', buildDir); + const dependencies = buildDependencies.dependencies; + dependencies.map((dependency) => { + console.log(`CURLING ${dependency.url} to ${buildDir}/${dependency.filename}`); + executeCliCommand({ + command: 'curl', + args: [dependency.url, '-o', `${buildDir}/${dependency.filename}`], + }); + console.log(`DONE CURLING ${dependency.url}`); + }); + console.log('FINISHED DOWNLOADING BUILD DEPENDENCIES'); +} + +export async function prepareBuildAndGetDependencies( + repoName: string, + projectName: string, + baseUrl: string, + buildDependencies +) { // before we get build dependencies, we need to clone the repo await cloneRepo(repoName); const repoDir = getRepoDir(repoName); + downloadBuildDependencies(buildDependencies, repoDir); + // doing these in parallel const commandPromises = [ getCommitHash(repoDir), diff --git a/src/entrypoints/localApp.ts b/src/entrypoints/localApp.ts index 46e32e530..01f35b8eb 100644 --- a/src/entrypoints/localApp.ts +++ b/src/entrypoints/localApp.ts @@ -15,11 +15,20 @@ async function localApp() { const baseUrl = 'https://www.mongodb.com'; const bucket = 'docs-java-dotcomstg'; const mutPrefix = 'docs/drivers/java/sync'; + const buildDependencies = { + dependencies: [ + { + url: 'https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/publishedbranches/docs-java.yaml', + filename: 'published-branches.yaml', + }, + ], + }; const { commitHash, patchId, bundlePath, commitBranch, hasRedirects, repoDir } = await prepareBuildAndGetDependencies( repoName, projectName, - baseUrl + baseUrl, + buildDependencies ); console.log('Begin snooty build...'); From ee70cf908dd9d1cdf79cf3f5862fc0b147e6fa76 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Fri, 1 Dec 2023 13:41:19 -0500 Subject: [PATCH 02/27] ading to github push --- api/controllers/v2/github.ts | 2 ++ src/commands/src/helpers/dependency-helpers.ts | 4 ++-- src/entities/job.ts | 11 +++++++++++ src/repositories/repoBranchesRepository.ts | 9 +++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/api/controllers/v2/github.ts b/api/controllers/v2/github.ts index ccb205f6e..6044f81b0 100644 --- a/api/controllers/v2/github.ts +++ b/api/controllers/v2/github.ts @@ -26,6 +26,7 @@ async function prepGithubPushPayload( branch_name, repoInfo.project ); + const build_dependencies = await repoBranchesRepository.getBuildDependencies(githubEvent.repository.name); const urlSlug = branch_info.aliasObject?.urlSlug ?? branch_name; const project = repoInfo?.project ?? githubEvent.repository.name; @@ -46,6 +47,7 @@ async function prepGithubPushPayload( action: 'push', repoName: githubEvent.repository.name, branchName: githubEvent.ref.split('/')[2], + buildDependencies: build_dependencies, isFork: githubEvent.repository.fork, repoOwner: githubEvent.repository.owner.login, url: githubEvent.repository.clone_url, diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 5259705b5..8978160cc 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -2,6 +2,7 @@ import path from 'path'; import fs from 'fs'; import { executeCliCommand, getCommitBranch, getCommitHash, getPatchId, getRepoDir } from '.'; import { promisify } from 'util'; +import { BuildDependencies } from '../../../entities/job'; const existsAsync = promisify(fs.exists); const writeFileAsync = promisify(fs.writeFile); @@ -33,8 +34,7 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: } } -//TODO: define buildDependencies type -async function downloadBuildDependencies(buildDependencies, repoDir: string) { +async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoDir: string) { console.log('STARTING DOWNLOADING BUILD DEPENDENCIES'); console.log('buildDependencies:', buildDependencies); const buildDir = buildDependencies.buildDirectory ?? repoDir; diff --git a/src/entities/job.ts b/src/entities/job.ts index d09ca1c96..184be583c 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -17,6 +17,16 @@ export enum JobStatus { // regression = 'regression', // } +export type BuildDependencies = { + buildDirectory?: string; + dependencies: Dependency[]; +}; + +type Dependency = { + url: string; + filename: string; +}; + export type Payload = { jobType: string; source: string; @@ -72,6 +82,7 @@ export type EnhancedPayload = { prefix: string; project: string; includeInGlobalSearch?: boolean; + buildDependencies?: BuildDependencies | null; }; export type Job = { diff --git a/src/repositories/repoBranchesRepository.ts b/src/repositories/repoBranchesRepository.ts index dbd811fa6..31bcedbcb 100644 --- a/src/repositories/repoBranchesRepository.ts +++ b/src/repositories/repoBranchesRepository.ts @@ -8,6 +8,15 @@ export class RepoBranchesRepository extends BaseRepository { super(config, logger, 'RepoBranchesRepository', db.collection(config.get('repoBranchesCollection'))); } + async getBuildDependencies(repoName: string) { + const query = { repoName: repoName }; + const repo = await this.findOne( + query, + `Mongo Timeout Error: Timedout while retrieving build dependencies for ${repoName}` + ); + return repo?.optionalBuildSteps?.buildDependencies; + } + async getRepoBranches(repoName: string, directoryPath?: string): Promise { const query = { repoName: repoName }; if (directoryPath) query['directories.snooty_toml'] = `/${directoryPath}`; From e60c4f825170ebbc5d3f6ec5ed0fe114625cf194 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 10:20:24 -0500 Subject: [PATCH 03/27] adding to build function --- src/entities/job.ts | 3 ++- src/job/jobHandler.ts | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/entities/job.ts b/src/entities/job.ts index 184be583c..e8f453e4a 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -54,6 +54,7 @@ export type Payload = { project: string; includeInGlobalSearch: boolean; directory?: string; + buildDependencies: BuildDependencies | null; }; export type EnhancedPayload = { @@ -82,7 +83,7 @@ export type EnhancedPayload = { prefix: string; project: string; includeInGlobalSearch?: boolean; - buildDependencies?: BuildDependencies | null; + buildDependencies: BuildDependencies | null; }; export type Job = { diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 5b0454224..8e139341b 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -480,6 +480,9 @@ export abstract class JobHandler { this._logger.save(this._currJob._id, 'Checked Commit'); await this.pullRepo(); this._logger.save(this._currJob._id, 'Pulled Repo'); + let str = 'null'; + if (this._currJob.payload.buildDependencies) str = String(this._currJob.payload.buildDependencies); + this._logger.save('build dependencies', str); this.prepBuildCommands(); this._logger.save(this._currJob._id, 'Prepared Build commands'); await this.prepNextGenBuild(); From 2880e32888dadabb674e4f59acf543a13808fb78 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 10:57:40 -0500 Subject: [PATCH 04/27] trying again --- src/job/jobHandler.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 8e139341b..ed513210d 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -481,8 +481,9 @@ export abstract class JobHandler { await this.pullRepo(); this._logger.save(this._currJob._id, 'Pulled Repo'); let str = 'null'; - if (this._currJob.payload.buildDependencies) str = String(this._currJob.payload.buildDependencies); - this._logger.save('build dependencies', str); + if (this._currJob.payload.buildDependencies) str = JSON.stringify(this._currJob.payload.buildDependencies); + this._logger.save(this._currJob._id, 'HELLO'); + this._logger.save(this._currJob._id, str); this.prepBuildCommands(); this._logger.save(this._currJob._id, 'Prepared Build commands'); await this.prepNextGenBuild(); From af03f92907a2124710e0a0c2c909f7b748c00426 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 12:28:08 -0500 Subject: [PATCH 05/27] updating structure --- src/entities/job.ts | 6 ++---- src/job/jobHandler.ts | 2 ++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/entities/job.ts b/src/entities/job.ts index e8f453e4a..47ef10a50 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -17,14 +17,12 @@ export enum JobStatus { // regression = 'regression', // } -export type BuildDependencies = { - buildDirectory?: string; - dependencies: Dependency[]; -}; +export type BuildDependencies = Dependency[]; type Dependency = { url: string; filename: string; + buildDir: string; }; export type Payload = { diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index ed513210d..259e147a9 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -13,6 +13,7 @@ import { IJobValidator } from './jobValidator'; import { RepoEntitlementsRepository } from '../repositories/repoEntitlementsRepository'; import { DocsetsRepository } from '../repositories/docsetsRepository'; import { MONOREPO_NAME } from '../monorepo/utils/monorepo-constants'; +import { downloadBuildDependencies } from '../commands/src/helpers/dependency-helpers'; require('fs'); export abstract class JobHandler { @@ -484,6 +485,7 @@ export abstract class JobHandler { if (this._currJob.payload.buildDependencies) str = JSON.stringify(this._currJob.payload.buildDependencies); this._logger.save(this._currJob._id, 'HELLO'); this._logger.save(this._currJob._id, str); + // await downloadBuildDependencies(this._currJob.payload.buildDependencies, this._currJob.payload.repoName); this.prepBuildCommands(); this._logger.save(this._currJob._id, 'Prepared Build commands'); await this.prepNextGenBuild(); From 02a3f0a5b29a4880ac463fd6ce2acc0911fba531 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 13:27:32 -0500 Subject: [PATCH 06/27] editing errors --- .../src/helpers/dependency-helpers.ts | 27 ++++++++++--------- src/entrypoints/localApp.ts | 8 ++---- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 8978160cc..8956bfbd8 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -34,21 +34,22 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: } } -async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoDir: string) { +export async function downloadBuildDependencies(buildDependencies: BuildDependencies | null, repoName: string) { console.log('STARTING DOWNLOADING BUILD DEPENDENCIES'); console.log('buildDependencies:', buildDependencies); - const buildDir = buildDependencies.buildDirectory ?? repoDir; - console.log('buildDirectory', buildDir); - const dependencies = buildDependencies.dependencies; - dependencies.map((dependency) => { - console.log(`CURLING ${dependency.url} to ${buildDir}/${dependency.filename}`); - executeCliCommand({ - command: 'curl', - args: [dependency.url, '-o', `${buildDir}/${dependency.filename}`], + const repoDir = getRepoDir(repoName); + if (buildDependencies) { + buildDependencies.map((dependency) => { + console.log(`CURLING ${dependency.url} to ${dependency.buildDir}/${dependency.filename}`); + const buildDir = dependency.buildDir ?? repoDir; + executeCliCommand({ + command: 'curl', + args: [dependency.url, '-o', `${buildDir}/${dependency.filename}`], + }); + console.log(`DONE CURLING ${dependency.url}`); }); - console.log(`DONE CURLING ${dependency.url}`); - }); - console.log('FINISHED DOWNLOADING BUILD DEPENDENCIES'); + console.log('FINISHED DOWNLOADING BUILD DEPENDENCIES'); + } } export async function prepareBuildAndGetDependencies( @@ -62,7 +63,7 @@ export async function prepareBuildAndGetDependencies( const repoDir = getRepoDir(repoName); - downloadBuildDependencies(buildDependencies, repoDir); + downloadBuildDependencies(buildDependencies, repoName); // doing these in parallel const commandPromises = [ diff --git a/src/entrypoints/localApp.ts b/src/entrypoints/localApp.ts index 01f35b8eb..642eb9e3f 100644 --- a/src/entrypoints/localApp.ts +++ b/src/entrypoints/localApp.ts @@ -16,12 +16,8 @@ async function localApp() { const bucket = 'docs-java-dotcomstg'; const mutPrefix = 'docs/drivers/java/sync'; const buildDependencies = { - dependencies: [ - { - url: 'https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/publishedbranches/docs-java.yaml', - filename: 'published-branches.yaml', - }, - ], + url: 'https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/publishedbranches/docs-java.yaml', + filename: 'published-branches.yaml', }; const { commitHash, patchId, bundlePath, commitBranch, hasRedirects, repoDir } = await prepareBuildAndGetDependencies( From 2f7e349c4ce50a7098bae074427be1a6054cab89 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 13:48:13 -0500 Subject: [PATCH 07/27] fianlly curling --- src/commands/src/helpers/dependency-helpers.ts | 9 +++++---- src/job/jobHandler.ts | 6 +++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 8956bfbd8..0237d11bc 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -39,16 +39,17 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen console.log('buildDependencies:', buildDependencies); const repoDir = getRepoDir(repoName); if (buildDependencies) { - buildDependencies.map((dependency) => { - console.log(`CURLING ${dependency.url} to ${dependency.buildDir}/${dependency.filename}`); + const ret = buildDependencies.map((dependency) => { const buildDir = dependency.buildDir ?? repoDir; executeCliCommand({ command: 'curl', args: [dependency.url, '-o', `${buildDir}/${dependency.filename}`], }); - console.log(`DONE CURLING ${dependency.url}`); + return `curl ${dependency.url} -o ${dependency.buildDir}/${dependency.filename}`; }); - console.log('FINISHED DOWNLOADING BUILD DEPENDENCIES'); + return ret; + } else { + return []; } } diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 259e147a9..1ed6394c8 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -485,7 +485,11 @@ export abstract class JobHandler { if (this._currJob.payload.buildDependencies) str = JSON.stringify(this._currJob.payload.buildDependencies); this._logger.save(this._currJob._id, 'HELLO'); this._logger.save(this._currJob._id, str); - // await downloadBuildDependencies(this._currJob.payload.buildDependencies, this._currJob.payload.repoName); + const buildDeps = await downloadBuildDependencies( + this._currJob.payload.buildDependencies, + this._currJob.payload.repoName + ); + this._logger.save(this._currJob._id, buildDeps.join('\n')); this.prepBuildCommands(); this._logger.save(this._currJob._id, 'Prepared Build commands'); await this.prepNextGenBuild(); From 0a3e5bc77639ad525cd0d4ddb419dd23bdc14bf6 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 14:13:15 -0500 Subject: [PATCH 08/27] curl errors --- src/commands/src/helpers/dependency-helpers.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 0237d11bc..bf1a62fb1 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -37,15 +37,16 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies | null, repoName: string) { console.log('STARTING DOWNLOADING BUILD DEPENDENCIES'); console.log('buildDependencies:', buildDependencies); - const repoDir = getRepoDir(repoName); + if (buildDependencies) { const ret = buildDependencies.map((dependency) => { + const repoDir = getRepoDir(repoName); const buildDir = dependency.buildDir ?? repoDir; executeCliCommand({ command: 'curl', args: [dependency.url, '-o', `${buildDir}/${dependency.filename}`], }); - return `curl ${dependency.url} -o ${dependency.buildDir}/${dependency.filename}`; + return `1 ${dependency.buildDir} 2 ${repoDir} curl ${dependency.url} -o ${dependency.buildDir}/${dependency.filename}`; }); return ret; } else { From 4759edb20f067ee0b5f63dbf7f9097cb88f626de Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 14:38:47 -0500 Subject: [PATCH 09/27] cleaning up --- src/commands/src/helpers/dependency-helpers.ts | 2 +- src/job/jobHandler.ts | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index bf1a62fb1..1b83a40a6 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -46,7 +46,7 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen command: 'curl', args: [dependency.url, '-o', `${buildDir}/${dependency.filename}`], }); - return `1 ${dependency.buildDir} 2 ${repoDir} curl ${dependency.url} -o ${dependency.buildDir}/${dependency.filename}`; + return `curl ${dependency.url} -o ${buildDir}/${dependency.filename}`; }); return ret; } else { diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 1ed6394c8..d2385489e 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -481,15 +481,12 @@ export abstract class JobHandler { this._logger.save(this._currJob._id, 'Checked Commit'); await this.pullRepo(); this._logger.save(this._currJob._id, 'Pulled Repo'); - let str = 'null'; - if (this._currJob.payload.buildDependencies) str = JSON.stringify(this._currJob.payload.buildDependencies); - this._logger.save(this._currJob._id, 'HELLO'); - this._logger.save(this._currJob._id, str); const buildDeps = await downloadBuildDependencies( this._currJob.payload.buildDependencies, this._currJob.payload.repoName ); this._logger.save(this._currJob._id, buildDeps.join('\n')); + this._logger.save(this._currJob._id, 'Downloaded build dependencies'); this.prepBuildCommands(); this._logger.save(this._currJob._id, 'Prepared Build commands'); await this.prepNextGenBuild(); From 5273873da58f21e5e9033a0688de0e2e1a3ee698 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 16:17:51 -0500 Subject: [PATCH 10/27] changing structurea gain --- .../src/helpers/dependency-helpers.ts | 25 +++++++++++-------- src/entities/job.ts | 8 ++++-- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 1b83a40a6..55f8a64a1 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -35,23 +35,26 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: } export async function downloadBuildDependencies(buildDependencies: BuildDependencies | null, repoName: string) { - console.log('STARTING DOWNLOADING BUILD DEPENDENCIES'); - console.log('buildDependencies:', buildDependencies); - + const commands: string[] = []; if (buildDependencies) { - const ret = buildDependencies.map((dependency) => { + buildDependencies.map((dependencyInfo) => { const repoDir = getRepoDir(repoName); - const buildDir = dependency.buildDir ?? repoDir; + const buildDir = dependencyInfo.buildDir ?? repoDir; executeCliCommand({ - command: 'curl', - args: [dependency.url, '-o', `${buildDir}/${dependency.filename}`], + command: 'mkdir', + args: ['-p', buildDir], + }); + commands.push(`mkdir -p ${buildDir}`); + dependencyInfo.dependencies.map((dep) => { + executeCliCommand({ + command: 'curl', + args: [dep.url, '-o', `${buildDir}/${dep.filename}`], + }); + commands.push(`curl ${dep.url} -o ${buildDir}/${dep.filename}`); }); - return `curl ${dependency.url} -o ${buildDir}/${dependency.filename}`; }); - return ret; - } else { - return []; } + return commands; } export async function prepareBuildAndGetDependencies( diff --git a/src/entities/job.ts b/src/entities/job.ts index 47ef10a50..1fb8b7320 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -17,12 +17,16 @@ export enum JobStatus { // regression = 'regression', // } -export type BuildDependencies = Dependency[]; +export type BuildDependencies = DependencyInfo[]; type Dependency = { url: string; filename: string; - buildDir: string; +}; + +type DependencyInfo = { + buildDir?: string; + dependencies: Dependency[]; }; export type Payload = { From 707e090553bb5497c0d04a4ccc811dd8f68044e2 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Mon, 4 Dec 2023 17:09:29 -0500 Subject: [PATCH 11/27] adding curl options --- src/commands/src/helpers/dependency-helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 55f8a64a1..424930492 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -48,9 +48,9 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen dependencyInfo.dependencies.map((dep) => { executeCliCommand({ command: 'curl', - args: [dep.url, '-o', `${buildDir}/${dep.filename}`], + args: ['-SfL', dep.url, '-o', `${buildDir}/${dep.filename}`], }); - commands.push(`curl ${dep.url} -o ${buildDir}/${dep.filename}`); + commands.push(`curl -SfL ${dep.url} -o ${buildDir}/${dep.filename}`); }); }); } From 60de805be41d64d4163c09310e19bdccff8f8dc0 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 10:25:57 -0500 Subject: [PATCH 12/27] testing removing from github.ts --- api/controllers/v2/github.ts | 4 ++-- src/entities/job.ts | 4 ++-- src/job/jobHandler.ts | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/api/controllers/v2/github.ts b/api/controllers/v2/github.ts index 6044f81b0..0471be65e 100644 --- a/api/controllers/v2/github.ts +++ b/api/controllers/v2/github.ts @@ -26,7 +26,7 @@ async function prepGithubPushPayload( branch_name, repoInfo.project ); - const build_dependencies = await repoBranchesRepository.getBuildDependencies(githubEvent.repository.name); + // const build_dependencies = await repoBranchesRepository.getBuildDependencies(githubEvent.repository.name); const urlSlug = branch_info.aliasObject?.urlSlug ?? branch_name; const project = repoInfo?.project ?? githubEvent.repository.name; @@ -47,7 +47,7 @@ async function prepGithubPushPayload( action: 'push', repoName: githubEvent.repository.name, branchName: githubEvent.ref.split('/')[2], - buildDependencies: build_dependencies, + // buildDependencies: build_dependencies, isFork: githubEvent.repository.fork, repoOwner: githubEvent.repository.owner.login, url: githubEvent.repository.clone_url, diff --git a/src/entities/job.ts b/src/entities/job.ts index 1fb8b7320..34aa221a0 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -56,7 +56,7 @@ export type Payload = { project: string; includeInGlobalSearch: boolean; directory?: string; - buildDependencies: BuildDependencies | null; + // buildDependencies: BuildDependencies | null; }; export type EnhancedPayload = { @@ -85,7 +85,7 @@ export type EnhancedPayload = { prefix: string; project: string; includeInGlobalSearch?: boolean; - buildDependencies: BuildDependencies | null; + // buildDependencies: BuildDependencies | null; }; export type Job = { diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index d2385489e..6ef6d5ae6 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -203,6 +203,12 @@ export abstract class JobHandler { } } + @throwIfJobInterupted() + private async getAndBuildDependencies() { + const buildDependencies = await this._repoBranchesRepo.getBuildDependencies(this.currJob.payload.repoName); + return await downloadBuildDependencies(buildDependencies, this.currJob.payload.repoName); + } + @throwIfJobInterupted() private async downloadMakeFile(): Promise { try { @@ -481,10 +487,7 @@ export abstract class JobHandler { this._logger.save(this._currJob._id, 'Checked Commit'); await this.pullRepo(); this._logger.save(this._currJob._id, 'Pulled Repo'); - const buildDeps = await downloadBuildDependencies( - this._currJob.payload.buildDependencies, - this._currJob.payload.repoName - ); + const buildDeps = await this.getAndBuildDependencies(); this._logger.save(this._currJob._id, buildDeps.join('\n')); this._logger.save(this._currJob._id, 'Downloaded build dependencies'); this.prepBuildCommands(); From e3731d74a980873f642db3cadfc23d751205960b Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 10:52:13 -0500 Subject: [PATCH 13/27] moving logic --- src/job/jobHandler.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 6ef6d5ae6..e5d379244 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -206,7 +206,8 @@ export abstract class JobHandler { @throwIfJobInterupted() private async getAndBuildDependencies() { const buildDependencies = await this._repoBranchesRepo.getBuildDependencies(this.currJob.payload.repoName); - return await downloadBuildDependencies(buildDependencies, this.currJob.payload.repoName); + const commands = await downloadBuildDependencies(buildDependencies, this.currJob.payload.repoName); + this._logger.save(this._currJob._id, commands.join('\n')); } @throwIfJobInterupted() @@ -487,9 +488,8 @@ export abstract class JobHandler { this._logger.save(this._currJob._id, 'Checked Commit'); await this.pullRepo(); this._logger.save(this._currJob._id, 'Pulled Repo'); - const buildDeps = await this.getAndBuildDependencies(); - this._logger.save(this._currJob._id, buildDeps.join('\n')); - this._logger.save(this._currJob._id, 'Downloaded build dependencies'); + await this.getAndBuildDependencies(); + this._logger.save(this._currJob._id, 'Downloaded Build dependencies'); this.prepBuildCommands(); this._logger.save(this._currJob._id, 'Prepared Build commands'); await this.prepNextGenBuild(); From c4dbc63f04160ab1c49133877cd42d533409fd28 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 10:55:44 -0500 Subject: [PATCH 14/27] cleaning up --- api/controllers/v2/github.ts | 2 -- src/commands/src/helpers/dependency-helpers.ts | 2 +- src/entities/job.ts | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/api/controllers/v2/github.ts b/api/controllers/v2/github.ts index 0471be65e..ccb205f6e 100644 --- a/api/controllers/v2/github.ts +++ b/api/controllers/v2/github.ts @@ -26,7 +26,6 @@ async function prepGithubPushPayload( branch_name, repoInfo.project ); - // const build_dependencies = await repoBranchesRepository.getBuildDependencies(githubEvent.repository.name); const urlSlug = branch_info.aliasObject?.urlSlug ?? branch_name; const project = repoInfo?.project ?? githubEvent.repository.name; @@ -47,7 +46,6 @@ async function prepGithubPushPayload( action: 'push', repoName: githubEvent.repository.name, branchName: githubEvent.ref.split('/')[2], - // buildDependencies: build_dependencies, isFork: githubEvent.repository.fork, repoOwner: githubEvent.repository.owner.login, url: githubEvent.repository.clone_url, diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 424930492..6b5a02c99 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -61,7 +61,7 @@ export async function prepareBuildAndGetDependencies( repoName: string, projectName: string, baseUrl: string, - buildDependencies + buildDependencies: BuildDependencies ) { // before we get build dependencies, we need to clone the repo await cloneRepo(repoName); diff --git a/src/entities/job.ts b/src/entities/job.ts index 34aa221a0..2cb40514f 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -56,7 +56,6 @@ export type Payload = { project: string; includeInGlobalSearch: boolean; directory?: string; - // buildDependencies: BuildDependencies | null; }; export type EnhancedPayload = { @@ -85,7 +84,6 @@ export type EnhancedPayload = { prefix: string; project: string; includeInGlobalSearch?: boolean; - // buildDependencies: BuildDependencies | null; }; export type Job = { From 48ea2933fb41d51ce4437e3539cbb3bdd4468cb2 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 11:10:37 -0500 Subject: [PATCH 15/27] fixing localapp error --- src/entrypoints/localApp.ts | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/entrypoints/localApp.ts b/src/entrypoints/localApp.ts index 642eb9e3f..753f34904 100644 --- a/src/entrypoints/localApp.ts +++ b/src/entrypoints/localApp.ts @@ -15,10 +15,29 @@ async function localApp() { const baseUrl = 'https://www.mongodb.com'; const bucket = 'docs-java-dotcomstg'; const mutPrefix = 'docs/drivers/java/sync'; - const buildDependencies = { - url: 'https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/publishedbranches/docs-java.yaml', - filename: 'published-branches.yaml', - }; + const buildDependencies = [ + { + dependencies: [ + { + url: 'https://raw.githubusercontent.com/mongodb/docs-worker-pool/meta/publishedbranches/docs-mongodb-internal.yaml', + filename: 'published-branches.yaml', + }, + ], + }, + { + buildDir: 'source/driver-examples', + dependencies: [ + { + url: 'https://raw.githubusercontent.com/mongodb/mongo-python-driver/master/test/test_examples.py', + filename: 'test_examples.py', + }, + { + url: 'https://raw.githubusercontent.com/mongodb/motor/master/test/asyncio_tests/test_examples.py', + filename: 'test_examples_motor.py', + }, + ], + }, + ]; const { commitHash, patchId, bundlePath, commitBranch, hasRedirects, repoDir } = await prepareBuildAndGetDependencies( repoName, From 6b1c4274c999f56c7737b4836b705033d31d64b5 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 13:45:27 -0500 Subject: [PATCH 16/27] addressing comments and renaming buildDir to targetDir --- .../src/helpers/dependency-helpers.ts | 27 ++++++++++--------- src/entities/job.ts | 2 +- src/job/jobHandler.ts | 1 + 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 6b5a02c99..fac29634a 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -34,26 +34,29 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: } } -export async function downloadBuildDependencies(buildDependencies: BuildDependencies | null, repoName: string) { +export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; - if (buildDependencies) { - buildDependencies.map((dependencyInfo) => { + buildDependencies.map(async (dependencyInfo) => { + try { const repoDir = getRepoDir(repoName); - const buildDir = dependencyInfo.buildDir ?? repoDir; - executeCliCommand({ + const targetDir = dependencyInfo.targetDir ?? repoDir; + await executeCliCommand({ command: 'mkdir', - args: ['-p', buildDir], + args: ['-p', targetDir], }); - commands.push(`mkdir -p ${buildDir}`); + commands.push(`mkdir -p ${targetDir}`); dependencyInfo.dependencies.map((dep) => { executeCliCommand({ command: 'curl', - args: ['-SfL', dep.url, '-o', `${buildDir}/${dep.filename}`], + args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], }); - commands.push(`curl -SfL ${dep.url} -o ${buildDir}/${dep.filename}`); + commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); }); - }); - } + } catch (error) { + console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); + throw error; + } + }); return commands; } @@ -68,7 +71,7 @@ export async function prepareBuildAndGetDependencies( const repoDir = getRepoDir(repoName); - downloadBuildDependencies(buildDependencies, repoName); + await downloadBuildDependencies(buildDependencies, repoName); // doing these in parallel const commandPromises = [ diff --git a/src/entities/job.ts b/src/entities/job.ts index 2cb40514f..e5cd1aec7 100644 --- a/src/entities/job.ts +++ b/src/entities/job.ts @@ -25,7 +25,7 @@ type Dependency = { }; type DependencyInfo = { - buildDir?: string; + targetDir?: string; dependencies: Dependency[]; }; diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index e5d379244..1dcec009b 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -206,6 +206,7 @@ export abstract class JobHandler { @throwIfJobInterupted() private async getAndBuildDependencies() { const buildDependencies = await this._repoBranchesRepo.getBuildDependencies(this.currJob.payload.repoName); + if (!buildDependencies) return; const commands = await downloadBuildDependencies(buildDependencies, this.currJob.payload.repoName); this._logger.save(this._currJob._id, commands.join('\n')); } From dff22d4f666c93495550ff757b743c6782803918 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 14:01:40 -0500 Subject: [PATCH 17/27] addressing comments part 2 --- .../src/helpers/dependency-helpers.ts | 42 ++++++++++--------- src/repositories/repoBranchesRepository.ts | 3 +- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index fac29634a..bfc0e4e7d 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -36,27 +36,29 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; - buildDependencies.map(async (dependencyInfo) => { - try { - const repoDir = getRepoDir(repoName); - const targetDir = dependencyInfo.targetDir ?? repoDir; - await executeCliCommand({ - command: 'mkdir', - args: ['-p', targetDir], - }); - commands.push(`mkdir -p ${targetDir}`); - dependencyInfo.dependencies.map((dep) => { - executeCliCommand({ - command: 'curl', - args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], + Promise.all( + buildDependencies.map(async (dependencyInfo) => { + try { + const repoDir = getRepoDir(repoName); + const targetDir = dependencyInfo.targetDir ?? repoDir; + await executeCliCommand({ + command: 'mkdir', + args: ['-p', targetDir], }); - commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); - }); - } catch (error) { - console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); - throw error; - } - }); + commands.push(`mkdir -p ${targetDir}`); + dependencyInfo.dependencies.map((dep) => { + executeCliCommand({ + command: 'curl', + args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], + }); + commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); + }); + } catch (error) { + console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); + throw error; + } + }) + ); return commands; } diff --git a/src/repositories/repoBranchesRepository.ts b/src/repositories/repoBranchesRepository.ts index 31bcedbcb..cf8cb1cd4 100644 --- a/src/repositories/repoBranchesRepository.ts +++ b/src/repositories/repoBranchesRepository.ts @@ -2,13 +2,14 @@ import { Db } from 'mongodb'; import { BaseRepository } from './baseRepository'; import { ILogger } from '../services/logger'; import { IConfig } from 'config'; +import { BuildDependencies } from '../entities/job'; export class RepoBranchesRepository extends BaseRepository { constructor(db: Db, config: IConfig, logger: ILogger) { super(config, logger, 'RepoBranchesRepository', db.collection(config.get('repoBranchesCollection'))); } - async getBuildDependencies(repoName: string) { + async getBuildDependencies(repoName: string): Promise { const query = { repoName: repoName }; const repo = await this.findOne( query, From 8e0c8c9f9c9a9630582403ec04fe20adbc4c63c9 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 15:09:38 -0500 Subject: [PATCH 18/27] debugging empty array --- .../src/helpers/dependency-helpers.ts | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index bfc0e4e7d..fac29634a 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -36,29 +36,27 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; - Promise.all( - buildDependencies.map(async (dependencyInfo) => { - try { - const repoDir = getRepoDir(repoName); - const targetDir = dependencyInfo.targetDir ?? repoDir; - await executeCliCommand({ - command: 'mkdir', - args: ['-p', targetDir], + buildDependencies.map(async (dependencyInfo) => { + try { + const repoDir = getRepoDir(repoName); + const targetDir = dependencyInfo.targetDir ?? repoDir; + await executeCliCommand({ + command: 'mkdir', + args: ['-p', targetDir], + }); + commands.push(`mkdir -p ${targetDir}`); + dependencyInfo.dependencies.map((dep) => { + executeCliCommand({ + command: 'curl', + args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], }); - commands.push(`mkdir -p ${targetDir}`); - dependencyInfo.dependencies.map((dep) => { - executeCliCommand({ - command: 'curl', - args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], - }); - commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); - }); - } catch (error) { - console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); - throw error; - } - }) - ); + commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); + }); + } catch (error) { + console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); + throw error; + } + }); return commands; } From 1345027ef931236bdc7e6a238b665f4e25bac090 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 15:31:54 -0500 Subject: [PATCH 19/27] debugging --- .../src/helpers/dependency-helpers.ts | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index fac29634a..dbce006b2 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -37,25 +37,25 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; buildDependencies.map(async (dependencyInfo) => { - try { - const repoDir = getRepoDir(repoName); - const targetDir = dependencyInfo.targetDir ?? repoDir; - await executeCliCommand({ - command: 'mkdir', - args: ['-p', targetDir], + // try { + const repoDir = getRepoDir(repoName); + const targetDir = dependencyInfo.targetDir ?? repoDir; + await executeCliCommand({ + command: 'mkdir', + args: ['-p', targetDir], + }); + commands.push(`mkdir -p ${targetDir}`); + dependencyInfo.dependencies.map((dep) => { + executeCliCommand({ + command: 'curl', + args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], }); - commands.push(`mkdir -p ${targetDir}`); - dependencyInfo.dependencies.map((dep) => { - executeCliCommand({ - command: 'curl', - args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], - }); - commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); - }); - } catch (error) { - console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); - throw error; - } + commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); + }); + // } catch (error) { + // console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); + // throw error; + // } }); return commands; } From 4e7eb13d83c886c055defda3979265e8c8cddc35 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 15:54:15 -0500 Subject: [PATCH 20/27] debugging still --- src/commands/src/helpers/dependency-helpers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index dbce006b2..4b786d4c4 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -36,11 +36,11 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; - buildDependencies.map(async (dependencyInfo) => { + buildDependencies.map((dependencyInfo) => { // try { const repoDir = getRepoDir(repoName); const targetDir = dependencyInfo.targetDir ?? repoDir; - await executeCliCommand({ + executeCliCommand({ command: 'mkdir', args: ['-p', targetDir], }); From 573690805daea0acec9740a49c2c8c7978f150b3 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 16:13:40 -0500 Subject: [PATCH 21/27] adding try catch --- .../src/helpers/dependency-helpers.ts | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 4b786d4c4..0223bf32a 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -37,25 +37,25 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; buildDependencies.map((dependencyInfo) => { - // try { - const repoDir = getRepoDir(repoName); - const targetDir = dependencyInfo.targetDir ?? repoDir; - executeCliCommand({ - command: 'mkdir', - args: ['-p', targetDir], - }); - commands.push(`mkdir -p ${targetDir}`); - dependencyInfo.dependencies.map((dep) => { + try { + const repoDir = getRepoDir(repoName); + const targetDir = dependencyInfo.targetDir ?? repoDir; executeCliCommand({ - command: 'curl', - args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], + command: 'mkdir', + args: ['-p', targetDir], }); - commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); - }); - // } catch (error) { - // console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); - // throw error; - // } + commands.push(`mkdir -p ${targetDir}`); + dependencyInfo.dependencies.map((dep) => { + executeCliCommand({ + command: 'curl', + args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], + }); + commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); + }); + } catch (error) { + console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); + throw error; + } }); return commands; } From fe73f5233c74ee5bd1c3a2b45cb45c605cb6e909 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Tue, 5 Dec 2023 17:12:46 -0500 Subject: [PATCH 22/27] adding promise.all --- .../src/helpers/dependency-helpers.ts | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 0223bf32a..88b12ca31 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -36,27 +36,29 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; - buildDependencies.map((dependencyInfo) => { - try { - const repoDir = getRepoDir(repoName); - const targetDir = dependencyInfo.targetDir ?? repoDir; - executeCliCommand({ - command: 'mkdir', - args: ['-p', targetDir], - }); - commands.push(`mkdir -p ${targetDir}`); - dependencyInfo.dependencies.map((dep) => { + Promise.all( + buildDependencies.map((dependencyInfo) => { + try { + const repoDir = getRepoDir(repoName); + const targetDir = dependencyInfo.targetDir ?? repoDir; executeCliCommand({ - command: 'curl', - args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], + command: 'mkdir', + args: ['-p', targetDir], }); - commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); - }); - } catch (error) { - console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); - throw error; - } - }); + commands.push(`mkdir -p ${targetDir}`); + dependencyInfo.dependencies.map((dep) => { + executeCliCommand({ + command: 'curl', + args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], + }); + commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); + }); + } catch (error) { + console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); + throw error; + } + }) + ); return commands; } From 0f1b37645455b45c62604b37e9211559e73f3038 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Wed, 6 Dec 2023 10:32:00 -0500 Subject: [PATCH 23/27] adding async --- src/commands/src/helpers/dependency-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 88b12ca31..32ed748fd 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -37,7 +37,7 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; Promise.all( - buildDependencies.map((dependencyInfo) => { + buildDependencies.map(async (dependencyInfo) => { try { const repoDir = getRepoDir(repoName); const targetDir = dependencyInfo.targetDir ?? repoDir; From 5e87b6a5dbcc955c6ca5c734913187659ca5bd50 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Wed, 6 Dec 2023 10:54:52 -0500 Subject: [PATCH 24/27] adding await --- src/commands/src/helpers/dependency-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 32ed748fd..bfc0e4e7d 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -41,7 +41,7 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen try { const repoDir = getRepoDir(repoName); const targetDir = dependencyInfo.targetDir ?? repoDir; - executeCliCommand({ + await executeCliCommand({ command: 'mkdir', args: ['-p', targetDir], }); From 5382aac20a9e8f73de9aa19b1b265aa685bb7e46 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Wed, 6 Dec 2023 11:53:53 -0500 Subject: [PATCH 25/27] testing await --- src/commands/src/helpers/dependency-helpers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index bfc0e4e7d..12f7ad547 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -36,7 +36,7 @@ async function createEnvProdFile(repoDir: string, projectName: string, baseUrl: export async function downloadBuildDependencies(buildDependencies: BuildDependencies, repoName: string) { const commands: string[] = []; - Promise.all( + await Promise.all( buildDependencies.map(async (dependencyInfo) => { try { const repoDir = getRepoDir(repoName); From 50cd8f5aa226a855a13ae02c59e4d30f6c4ef00e Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Thu, 7 Dec 2023 12:05:24 -0500 Subject: [PATCH 26/27] refining try-catch, adding await promise.all --- .../src/helpers/dependency-helpers.ts | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index 12f7ad547..f2eacee2a 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -38,25 +38,35 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen const commands: string[] = []; await Promise.all( buildDependencies.map(async (dependencyInfo) => { + const repoDir = getRepoDir(repoName); + const targetDir = dependencyInfo.targetDir ?? repoDir; try { - const repoDir = getRepoDir(repoName); - const targetDir = dependencyInfo.targetDir ?? repoDir; await executeCliCommand({ command: 'mkdir', args: ['-p', targetDir], }); - commands.push(`mkdir -p ${targetDir}`); - dependencyInfo.dependencies.map((dep) => { - executeCliCommand({ - command: 'curl', - args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], - }); - commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); - }); } catch (error) { - console.error(`ERROR! Could not download the following dependencies: ${JSON.stringify(dependencyInfo)}`); + console.error( + `ERROR! Could not create target directory ${targetDir}. Dependency information: ${dependencyInfo}` + ); throw error; } + commands.push(`mkdir -p ${targetDir}`); + await Promise.all( + dependencyInfo.dependencies.map((dep) => { + try { + executeCliCommand({ + command: 'curl', + args: ['-SfL', dep.url, '-o', `${targetDir}/${dep.filename}`], + }); + } catch (error) { + console.error( + `ERROR! Could not curl ${dep.url} into ${targetDir}/${dep.filename}. Dependency information: ${dependencyInfo}` + ); + } + commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`); + }) + ); }) ); return commands; From 83f5e77d430b3baf11d3378bb353fc7a08005b99 Mon Sep 17 00:00:00 2001 From: Maya Raman Date: Thu, 7 Dec 2023 16:25:37 -0500 Subject: [PATCH 27/27] dependency info logging --- src/commands/src/helpers/dependency-helpers.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/commands/src/helpers/dependency-helpers.ts b/src/commands/src/helpers/dependency-helpers.ts index f2eacee2a..5e15be23b 100644 --- a/src/commands/src/helpers/dependency-helpers.ts +++ b/src/commands/src/helpers/dependency-helpers.ts @@ -47,7 +47,8 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen }); } catch (error) { console.error( - `ERROR! Could not create target directory ${targetDir}. Dependency information: ${dependencyInfo}` + `ERROR! Could not create target directory ${targetDir}. Dependency information: `, + dependencyInfo ); throw error; } @@ -61,7 +62,8 @@ export async function downloadBuildDependencies(buildDependencies: BuildDependen }); } catch (error) { console.error( - `ERROR! Could not curl ${dep.url} into ${targetDir}/${dep.filename}. Dependency information: ${dependencyInfo}` + `ERROR! Could not curl ${dep.url} into ${targetDir}/${dep.filename}. Dependency information: `, + dependencyInfo ); } commands.push(`curl -SfL ${dep.url} -o ${targetDir}/${dep.filename}`);