From ac8a104ce12546db98ab883b5039b308f9b13676 Mon Sep 17 00:00:00 2001 From: Allison Reinheimer Moore Date: Thu, 7 Sep 2023 10:25:17 -0400 Subject: [PATCH 1/7] =?UTF-8?q?DOP-3977:=20encourage=20writers=20to=20swit?= =?UTF-8?q?ch=20webhooks=20=F0=9F=A5=95=20(#902)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * DOP-3977: encourage writers to switch webhooks 🥕 * more newlines * revert v2 changes --- api/controllers/v1/jobs.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/api/controllers/v1/jobs.ts b/api/controllers/v1/jobs.ts index 96ca8eb74..652b6d226 100644 --- a/api/controllers/v1/jobs.ts +++ b/api/controllers/v1/jobs.ts @@ -166,13 +166,22 @@ function prepProgressMessage( jobId: string, jobTitle: string, status: string, - errorReason: string + errorReason: string, + jobType?: string ): string { const msg = `Your Job (<${jobUrl}${jobId}|${jobTitle}>) `; const env = c.get('env'); switch (status) { case 'inQueue': - return msg + 'has successfully been added to the ' + env + ' queue.'; + // Encourage writers to update to new webhook on githubPush jobs + let inQueueMsg = msg; + if (jobType == 'githubPush') { + const webhookWikiUrl = + 'https://wiki.corp.mongodb.com/display/DE/How-To%3A+Use+Snooty%27s+Autobuilder+to+Build+Your+Content'; + const updatePlease = `:exclamation: You used the old webhook for this build. <${webhookWikiUrl}|Update to the new webhook> in your fork of this repo to save 90s per build.`; + inQueueMsg = updatePlease + '\n\n' + msg; + } + return inQueueMsg + 'has successfully been added to the ' + env + ' queue.'; case 'inProgress': return msg + 'is now being processed.'; case 'completed': @@ -213,7 +222,8 @@ async function NotifyBuildProgress(jobId: string): Promise { jobId, jobTitle, fullDocument.status as string, - fullDocument?.error?.reason || '' + fullDocument?.error?.reason || '', + fullDocument?.payload.jobType ), entitlement['slack_user_id'] ); From 99f917169bae325b37e1dfb5262bc46d859d27d5 Mon Sep 17 00:00:00 2001 From: Cassidy Schaufele Date: Thu, 7 Sep 2023 10:53:35 -0600 Subject: [PATCH 2/7] Update Dockerfile --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index d0f4838e8..94305a712 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,8 +22,8 @@ RUN cd ./modules/oas-page-builder \ # where repo work will happen FROM ubuntu:20.04 ARG WORK_DIRECTORY=/home/docsworker-xlarge -ARG SNOOTY_PARSER_VERSION=0.14.6 -ARG SNOOTY_FRONTEND_VERSION=0.14.13 +ARG SNOOTY_PARSER_VERSION=0.14.7 +ARG SNOOTY_FRONTEND_VERSION=0.14.14 ARG MUT_VERSION=0.10.3 ARG REDOC_CLI_VERSION=1.2.2 ARG NPM_BASE_64_AUTH From a746745556e4b039601a956b8edab0490bb5aed4 Mon Sep 17 00:00:00 2001 From: Cassidy Schaufele Date: Thu, 7 Sep 2023 12:20:39 -0600 Subject: [PATCH 3/7] Update Dockerfile --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 94305a712..0554f2afc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,7 @@ RUN cd ./modules/oas-page-builder \ # where repo work will happen FROM ubuntu:20.04 ARG WORK_DIRECTORY=/home/docsworker-xlarge -ARG SNOOTY_PARSER_VERSION=0.14.7 +ARG SNOOTY_PARSER_VERSION=0.14.8 ARG SNOOTY_FRONTEND_VERSION=0.14.14 ARG MUT_VERSION=0.10.3 ARG REDOC_CLI_VERSION=1.2.2 From a7642af68340f04890816c206153ec133409632f Mon Sep 17 00:00:00 2001 From: anabellabuckvar <41971124+anabellabuckvar@users.noreply.github.com> Date: Thu, 7 Sep 2023 16:05:07 -0400 Subject: [PATCH 4/7] DOP-3999 Exclude oldgen jobs from "don't send notifications of non-GC builds" logic (#904) * DOP-3999 notify oldgen jobs * DOP-3999 autobuilder php-library * DOP-3999 rollback last change * DOP-3999 undid package-lock changes * DOP-3999 undid package-lock.json changes * DOP-3999 use isNextGen field * DOP-3999 fixed if statement --- src/job/jobHandler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index accb96f2d..357bd2c27 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -105,7 +105,7 @@ export abstract class JobHandler { // completed after the Gatsby Cloud build via the SnootyBuildComplete lambda. const { _id: jobId, user } = this.currJob; const gatsbyCloudSiteId = await this._repoEntitlementsRepo.getGatsbySiteIdByGithubUsername(user); - if (gatsbyCloudSiteId && this.currJob.payload.jobType === 'githubPush') { + if (this.currJob.payload.isNextGen && gatsbyCloudSiteId && this.currJob.payload.jobType === 'githubPush') { this.logger.info( jobId, `User ${user} has a Gatsby Cloud site. The Autobuilder will not mark the build as completed right now.` From ce592fc5ef2af5be77a9ff4d4f15e7b42cc24771 Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Thu, 7 Sep 2023 15:47:37 -0500 Subject: [PATCH 5/7] [DOP-3911]: Check project path for monorepo (#894) * [DOP-3911]: Add way to check file changes and determine what projects have been changed if head_commit is included * [DOP-3911]: Add some comments * [DOP-3911]: Add checks for snooty.toml in monorepo * [DOP-3911]: Add commit info and simplify files * [DOP-3911]: Add unit tests * [DOP-3911]: Update tests * [DOP-3911]: Update comments * [DOP-3911]: Remove extra comment * [DOP-3911]: Remove unused code * [DOP-3911]: Remove unused property in job payload * [DOP-3911]: Remove unused import * [DOP-3911]: Remove log and irrelevant comments * [DOP-3911]: Refactor to start using tree approach and create new directories for organization * [DOP-3911]: Refactor set to be called from parent function * [DOP-3911]: More refactoring, update tests to use set * [DOP-3911]: Clean up * [DOP-3911]: Resolve merge conflicts * [DOP-3911]: Resolve merge conflicts * [DOP-3911]: Add types and add comments * [DOP-3911]: Add feature * [DOP-3911]: Add feature flag for testing monorepo path * [DOP-3911]: Fix typo * [DOP-3911]: Remove get snooty.toml * [DOP-3911]: Remove use of config library, and clean up code * [DOP-3911]: Add parameter store flag for ease of testing * [DOP-3911]: Comment update * [DOP-3911]: Properly name test --- .github/workflows/update-feature-branch.yml | 2 +- api/controllers/v2/github.ts | 22 ++++- .../constructs/api/webhook-env-construct.ts | 7 ++ src/clients/githubClient.ts | 19 ++++ src/monorepo/index.ts | 42 ++++++++ src/monorepo/services/get-paths.ts | 36 +++++++ src/monorepo/types/atlas-types.ts | 25 +++++ src/monorepo/types/github-types.ts | 5 + src/monorepo/utils/monorepo-constants.ts | 2 + src/monorepo/utils/path-utils.ts | 50 ++++++++++ src/repositories/docSetRepository.ts | 45 +++++++++ tests/unit/monorepo/monorepo.test.ts | 98 +++++++++++++++++++ 12 files changed, 350 insertions(+), 3 deletions(-) create mode 100644 src/clients/githubClient.ts create mode 100644 src/monorepo/index.ts create mode 100644 src/monorepo/services/get-paths.ts create mode 100644 src/monorepo/types/atlas-types.ts create mode 100644 src/monorepo/types/github-types.ts create mode 100644 src/monorepo/utils/monorepo-constants.ts create mode 100644 src/monorepo/utils/path-utils.ts create mode 100644 src/repositories/docSetRepository.ts create mode 100644 tests/unit/monorepo/monorepo.test.ts diff --git a/.github/workflows/update-feature-branch.yml b/.github/workflows/update-feature-branch.yml index 0bbf6bb53..72ebe490c 100644 --- a/.github/workflows/update-feature-branch.yml +++ b/.github/workflows/update-feature-branch.yml @@ -46,7 +46,7 @@ jobs: cd cdk-infra/ npm ci npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} \ - auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhook + auto-builder-stack-enhancedApp-stg-${{github.head_ref}}-webhooks - name: Update Worker Stack if: steps.filter.outputs.worker == 'true' diff --git a/api/controllers/v2/github.ts b/api/controllers/v2/github.ts index 19657f31c..e50842d51 100644 --- a/api/controllers/v2/github.ts +++ b/api/controllers/v2/github.ts @@ -8,6 +8,8 @@ import { ConsoleLogger } from '../../../src/services/logger'; import { RepoBranchesRepository } from '../../../src/repositories/repoBranchesRepository'; import { EnhancedJob, JobStatus } from '../../../src/entities/job'; import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handlers/github'; +import { getMonorepoPaths } from '../../../src/monorepo'; +import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils'; async function prepGithubPushPayload( githubEvent: PushEvent, @@ -75,9 +77,9 @@ export const TriggerBuild = async (event: APIGatewayEvent): Promise { + const commitInfo: GitCommitInfo = { + ownerName, + repoName, + commitSha, + }; + + const snootyDirSet = await getSnootyDirSet(commitInfo); + + const projects = updatedFilePaths.map((path) => getProjectDirFromPath(path, snootyDirSet)); + + // remove empty strings and remove duplicated values + return Array.from(new Set(projects.filter((dir) => !!dir))); +} diff --git a/src/monorepo/services/get-paths.ts b/src/monorepo/services/get-paths.ts new file mode 100644 index 000000000..8716d7ec1 --- /dev/null +++ b/src/monorepo/services/get-paths.ts @@ -0,0 +1,36 @@ +import { SNOOTY_TOML_FILENAME } from '../utils/monorepo-constants'; + +/** + * This function returns the project path for a given file change from a docs repository + * within the monorepo. This function supports nested projects. + * @param path An added/modified/removed file path from a commit e.g. server-docs/source/index.rst + * @param commitInfo Contains information + * @returns The closest file path that contains a snooty.toml, relative to the path parameter. + */ +export function getProjectDirFromPath(path: string, snootyDirSet: Set): string { + const pathArray = path.split('/'); + if (pathArray.length === 0) { + console.warn('WARNING! Empty path found: ', path); + return ''; + } + + /** + * If the changed file is the snooty.toml file, we know that we + * are in the project's root directory. We can join the original + * pathArray to get the project path since the snooty.toml has been removed. + */ + const changedFile = pathArray.pop(); + + if (changedFile === SNOOTY_TOML_FILENAME) return pathArray.join('/'); + + while (pathArray.length > 0) { + const currDir = pathArray.join('/'); + + if (snootyDirSet.has(currDir)) return currDir; + + pathArray.pop(); + } + + console.warn(`WARNING! No snooty.toml found for the given path: ${path}`); + return ''; +} diff --git a/src/monorepo/types/atlas-types.ts b/src/monorepo/types/atlas-types.ts new file mode 100644 index 000000000..1af35ee35 --- /dev/null +++ b/src/monorepo/types/atlas-types.ts @@ -0,0 +1,25 @@ +interface DirectoryConfig { + snooty_toml?: string; + source?: string; +} + +interface RepoConfig { + repoName: string; + deployable: boolean; + branches: BranchConfig[]; +} + +interface BranchConfig { + gitBranchName: string; +} + +// TODO: Populate these more. For DOP-3911, they are +// being added for testing purposes. +export interface DocSetEntry { + project: string; + prefix: string; + bucket: string; + url: string; + directories?: DirectoryConfig; + repos?: RepoConfig[]; +} diff --git a/src/monorepo/types/github-types.ts b/src/monorepo/types/github-types.ts new file mode 100644 index 000000000..161613fa8 --- /dev/null +++ b/src/monorepo/types/github-types.ts @@ -0,0 +1,5 @@ +export interface GitCommitInfo { + commitSha: string; + ownerName: string; + repoName: string; +} diff --git a/src/monorepo/utils/monorepo-constants.ts b/src/monorepo/utils/monorepo-constants.ts new file mode 100644 index 000000000..fc71e1bc5 --- /dev/null +++ b/src/monorepo/utils/monorepo-constants.ts @@ -0,0 +1,2 @@ +export const SNOOTY_TOML_FILENAME = 'snooty.toml'; +export const MONOREPO_NAME = 'docs-monorepo'; diff --git a/src/monorepo/utils/path-utils.ts b/src/monorepo/utils/path-utils.ts new file mode 100644 index 000000000..307671e05 --- /dev/null +++ b/src/monorepo/utils/path-utils.ts @@ -0,0 +1,50 @@ +import { Commit } from '@octokit/webhooks-types'; +import { getOctokitClient } from '../../clients/githubClient'; +import { GitCommitInfo } from '../types/github-types'; +import { SNOOTY_TOML_FILENAME } from './monorepo-constants'; + +/** + * Creates a `Set` of all `snooty.toml` paths within the monorepo. + * The function retrieves the monorepo's tree structure from GitHub. + */ +export async function getSnootyDirSet({ commitSha, ownerName, repoName }: GitCommitInfo): Promise> { + try { + const client = getOctokitClient(); + + // getting the repository tree for a given commit SHA. This returns an object + // with the property `tree` that is a flat array of all files in the repository. + // The tree array contains objects that hold the file path. + // Unlike the contents API for repositories, the actual file content is not returned. + const { data } = await client.request('GET /repos/{owner}/{repo}/git/trees/{tree_sha}', { + owner: ownerName, + repo: repoName, + tree_sha: commitSha, + recursive: 'true', + }); + + const snootyTomlDirs = data.tree + .filter((treeNode) => !!treeNode.path?.includes(SNOOTY_TOML_FILENAME)) + .map((treeNode) => { + // casting the `treeNode.path` from `(string | undefined)` to `string` since the filter will ensure that the result + // only includes treeNode.path values that are defined and include snooty.toml + // in the path i.e. we will not have `undefined` as a value in the resulting array. + const path = treeNode.path as string; + + // the - 1 is to remove the trailing slash + return path.slice(0, path.length - SNOOTY_TOML_FILENAME.length - 1); + }); + + const snootyDirSet = new Set(snootyTomlDirs); + + return snootyDirSet; + } catch (error) { + console.error( + `ERROR! Unable to retrieve tree for SHA: ${commitSha} owner name: ${ownerName} repo name: ${repoName}`, + error + ); + throw error; + } +} + +export const getUpdatedFilePaths = (commit: Commit): string[] => + commit.modified.concat(commit.added).concat(commit.removed); diff --git a/src/repositories/docSetRepository.ts b/src/repositories/docSetRepository.ts new file mode 100644 index 000000000..a2a2e25e8 --- /dev/null +++ b/src/repositories/docSetRepository.ts @@ -0,0 +1,45 @@ +import { IConfig } from 'config'; +import { Db } from 'mongodb'; +import { ILogger } from '../services/logger'; +import { BaseRepository } from './baseRepository'; + +const docSetCollectionName = process.env.DOCS_SET_COLLECTION_NAME || 'docset'; + +export class DocSetRepository extends BaseRepository { + constructor(db: Db, config: IConfig, logger: ILogger) { + super(config, logger, 'DocSetRepository', db.collection(docSetCollectionName)); + } + + /** + * Compares the project path from a monorepo push event, and compares it with + * what is configured in the docset entry in Atlas. + * @param path The project path where the snooty.toml file exists from the monorepo. + * This path will reflect the current project path from a given commit. + * @param projectName The project name for the docset entry. + * @returns A boolean representing whether or not the configured docset entry snooty_toml path + * matches the path found in GitHub. + */ + async checkSnootyTomlPath(path: string, projectName: string) { + const query = { project: projectName }; + try { + const docSetObject = await this.findOne( + query, + `Mongo Timeout Error: Timedout while retrieving repos entry for ${path}` + ); + + if (!docSetObject) { + console.warn(`WARNING: The docset does not exist for the following project: ${projectName} \n path: ${path}`); + + return false; + } + + return docSetObject.directories.snooty_toml === path; + } catch (error) { + console.warn( + `WARNING: Error occurred when retrieving project path for ${projectName}. The following path was provided: ${path}`, + error + ); + return false; + } + } +} diff --git a/tests/unit/monorepo/monorepo.test.ts b/tests/unit/monorepo/monorepo.test.ts new file mode 100644 index 000000000..918d48e40 --- /dev/null +++ b/tests/unit/monorepo/monorepo.test.ts @@ -0,0 +1,98 @@ +import { Octokit } from '@octokit/rest'; +import { getMonorepoPaths } from '../../../src/monorepo'; +import { getOctokitClient } from '../../../src/clients/githubClient'; +import { mockDeep } from 'jest-mock-extended'; + +jest.mock('../../../src/clients/githubClient'); +jest.mock('@octokit/rest'); + +const mockedOctokit = mockDeep(); + +beforeEach(() => { + jest.resetAllMocks(); + + const mockedGetOctokitClient = getOctokitClient as jest.MockedFunction; + mockedGetOctokitClient.mockReturnValue(mockedOctokit); +}); + +function mockOctokitTreeResponse(filePaths: string[]) { + // Partial representation of the GitHub API response that we care about. + // The response contains a property `tree` which is an array of objects. + const mockedResponse = { + data: { + tree: filePaths.map((path) => ({ path })), + }, + }; + + jest + .spyOn(mockedOctokit, 'request') + .mockResolvedValueOnce(mockedResponse as unknown as ReturnType); +} + +describe('Monorepo Path Parsing tests', () => { + it('Successfully finds project paths if snooty.toml is changed', async () => { + mockOctokitTreeResponse(['server-docs/source/datalake/snooty.toml', 'server-docs/snooty.toml']); + + const paths = await getMonorepoPaths({ + commitSha: '12345', + ownerName: 'mongodb', + repoName: 'monorepo', + updatedFilePaths: ['server-docs/snooty.toml', 'server-docs/source/datalake/snooty.toml'], + }); + + expect(paths).toContain('server-docs'); + expect(paths).toContain('server-docs/source/datalake'); + }); + + it('Successfully finds project paths based on changed files other than snooty.toml', async () => { + /** + * server-docs/source/datalake contains a snooty.toml file. We will reject once and then resolve + * once as this should mimic responses from the GitHub API. + */ + + mockOctokitTreeResponse(['server-docs/source/datalake/snooty.toml', 'server-docs/snooty.toml']); + + const paths = await getMonorepoPaths({ + commitSha: '12345', + ownerName: 'mongodb', + repoName: 'monorepo', + updatedFilePaths: ['server-docs/source/datalake/source/index.rst'], + }); + + expect(paths).toContain('server-docs/source/datalake'); + }); + + it('Returns an empty array if there is no snooty.toml at any point in the file path', async () => { + mockOctokitTreeResponse(['server-docs/source/datalake/snooty.toml', 'server-docs/snooty.toml']); + + const paths = await getMonorepoPaths({ + commitSha: '12345', + ownerName: 'mongodb', + repoName: 'monorepo', + updatedFilePaths: ['bad/path/index.rst'], + }); + + expect(paths.length).toEqual(0); + }); + + it('Returns only one project path when two files in the same project are modified', async () => { + /** + * server-docs/source/datalake contains a snooty.toml file. We will reject once and then resolve + * once as this should mimic responses from the GitHub API. + */ + mockOctokitTreeResponse(['server-docs/source/datalake/snooty.toml', 'server-docs/snooty.toml']); + + const paths = await getMonorepoPaths({ + commitSha: '12345', + ownerName: 'mongodb', + repoName: 'monorepo', + updatedFilePaths: [ + 'server-docs/source/datalake/source/index.rst', + 'server-docs/source/datalake/source/test/index.rst', + ], + }); + + expect(paths).toContain('server-docs/source/datalake'); + expect(paths.length).toEqual(1); + }); +}); From 225a7e971ca19133d9f378c6c90cffc4d62828e8 Mon Sep 17 00:00:00 2001 From: Seung Park Date: Tue, 12 Sep 2023 11:31:34 -0400 Subject: [PATCH 6/7] DOP-3994: add feature flag for chatbot (#905) * add environment flag from param store * test front end change * wrong dockerfile * user master branch * test stack update * revert testing --- cdk-infra/lib/constructs/worker/worker-env-construct.ts | 4 ++++ config/custom-environment-variables.json | 1 + config/default.json | 1 + infrastructure/ecs-main/ecs_service.yml | 2 ++ infrastructure/ecs-main/serverless.yml | 1 + src/job/jobHandler.ts | 1 + tests/data/data.ts | 2 +- tests/unit/job/productionJobHandler.test.ts | 2 +- tests/utils/jobHandlerTestHelper.ts | 1 + 9 files changed, 13 insertions(+), 2 deletions(-) diff --git a/cdk-infra/lib/constructs/worker/worker-env-construct.ts b/cdk-infra/lib/constructs/worker/worker-env-construct.ts index d9f2fbbdb..f1d27ee07 100644 --- a/cdk-infra/lib/constructs/worker/worker-env-construct.ts +++ b/cdk-infra/lib/constructs/worker/worker-env-construct.ts @@ -36,6 +36,9 @@ export class WorkerEnvConstruct extends Construct { `/docs/worker_pool/preview_webhook/snooty_gatsby_cloud_test/data_source` ); + // front end feature flag for chatbot UI + const gatsbyUseChatbot = StringParameter.valueFromLookup(this, `${ssmPrefix}/flag/use_chatbot`); + const githubBotUsername = StringParameter.valueFromLookup(this, `${ssmPrefix}/github/bot/username`); const npmEmail = StringParameter.valueFromLookup(this, `${ssmPrefix}/npm/email`); @@ -80,6 +83,7 @@ export class WorkerEnvConstruct extends Construct { USE_CUSTOM_BUCKETS: `${getUseCustomBuckets()}`, FEATURE_NAME: `${getFeatureName()}`, GATSBY_TEST_SEARCH_UI: 'false', + GATSBY_SHOW_CHATBOT: gatsbyUseChatbot, }; } } diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index edd5c2434..011a147c7 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -24,6 +24,7 @@ "previewBuildEnabled": "PREVIEW_BUILD_ENABLED", "featureFlagUpdatePages": "FEATURE_FLAG_UPDATE_PAGES", "featureFlagSearchUI": "GATSBY_TEST_SEARCH_UI", + "gatsbyUseChatbot": "GATSBY_SHOW_CHATBOT", "repoBranchesCollection": "REPO_BRANCHES_COL_NAME", "repo_dir": "repos", "jobId": "jobId", diff --git a/config/default.json b/config/default.json index dec339ac1..4f88c8feb 100644 --- a/config/default.json +++ b/config/default.json @@ -32,6 +32,7 @@ "previewBuildEnabled": "false", "featureFlagUpdatePages": "false", "featureFlagSearchUI": "false", + "gatsbyUseChatbot": "false", "parallel": { "enabled": true, "stg": { diff --git a/infrastructure/ecs-main/ecs_service.yml b/infrastructure/ecs-main/ecs_service.yml index 4d8d63f19..f4b09982c 100644 --- a/infrastructure/ecs-main/ecs_service.yml +++ b/infrastructure/ecs-main/ecs_service.yml @@ -62,6 +62,8 @@ Resources: Value: ${self:custom.featureFlagUpdatePages} - Name: GATSBY_TEST_SEARCH_UI Value: ${self:custom.featureFlagSearchUI} + - Name: GATSBY_SHOW_CHATBOT + Value: ${self:custom.gatsbyUseChatbot} - Name: FASTLY_MAIN_TOKEN Value: ${self:custom.fastlyMainToken} - Name: FASTLY_MAIN_SERVICE_ID diff --git a/infrastructure/ecs-main/serverless.yml b/infrastructure/ecs-main/serverless.yml index 0de1eb941..e06ca9a2c 100644 --- a/infrastructure/ecs-main/serverless.yml +++ b/infrastructure/ecs-main/serverless.yml @@ -117,6 +117,7 @@ custom: featureFlagUpdatePages: ${ssm:/env/${self:provider.stage}/docs/worker_pool/flag/update_pages} featureFlagSearchUI: ${ssm:/env/${self:provider.stage}/docs/worker_pool/flag/search_ui} gatsbyTestEmbedVersions: ${ssm:/env/${self:provider.stage}/docs/worker_pool/flag/embedded_versions} + gatsbyUseChatbot: ${ssm:/env/${self:provider.stage}/docs/worker_pool/flag/use_chatbot} fastlyMainToken: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/docs/main/token} fastlyMainServiceId: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/docs/main/service_id} fastlyCloudManagerToken: ${ssm:/env/${self:provider.stage}/docs/worker_pool/fastly/docs/cloudmanager/token} diff --git a/src/job/jobHandler.ts b/src/job/jobHandler.ts index 357bd2c27..baefa3b83 100644 --- a/src/job/jobHandler.ts +++ b/src/job/jobHandler.ts @@ -369,6 +369,7 @@ export abstract class JobHandler { GATSBY_BASE_URL: this._config.get('gatsbyBaseUrl'), PREVIEW_BUILD_ENABLED: this._config.get('previewBuildEnabled'), GATSBY_TEST_SEARCH_UI: this._config.get('featureFlagSearchUI'), + GATSBY_SHOW_CHATBOT: this._config.get('gatsbyUseChatbot'), }; for (const [envName, envValue] of Object.entries(snootyFrontEndVars)) { diff --git a/tests/data/data.ts b/tests/data/data.ts index fafca623a..d403e8cad 100644 --- a/tests/data/data.ts +++ b/tests/data/data.ts @@ -175,7 +175,7 @@ export class TestDataProvider { } static getEnvVarsWithPathPrefixWithFlags(job: Job): string { - return `GATSBY_PARSER_USER=TestUser\nGATSBY_PARSER_BRANCH=${job.payload.branchName}\nPATH_PREFIX=${job.payload.pathPrefix}\nGATSBY_BASE_URL=test\nPREVIEW_BUILD_ENABLED=false\nGATSBY_TEST_SEARCH_UI=false\n`; + return `GATSBY_PARSER_USER=TestUser\nGATSBY_PARSER_BRANCH=${job.payload.branchName}\nPATH_PREFIX=${job.payload.pathPrefix}\nGATSBY_BASE_URL=test\nPREVIEW_BUILD_ENABLED=false\nGATSBY_TEST_SEARCH_UI=false\nGATSBY_SHOW_CHATBOT=false\n`; } static getPathPrefixCases(): Array { diff --git a/tests/unit/job/productionJobHandler.test.ts b/tests/unit/job/productionJobHandler.test.ts index 187109286..00e5f4600 100644 --- a/tests/unit/job/productionJobHandler.test.ts +++ b/tests/unit/job/productionJobHandler.test.ts @@ -247,7 +247,7 @@ describe('ProductionJobHandler Tests', () => { expect(jobHandlerTestHelper.fileSystemServices.writeToFile).toBeCalledWith( `repos/${jobHandlerTestHelper.job.payload.repoName}/.env.production`, - `GATSBY_PARSER_USER=TestUser\nGATSBY_PARSER_BRANCH=${jobHandlerTestHelper.job.payload.branchName}\nPATH_PREFIX=/\nGATSBY_BASE_URL=test\nPREVIEW_BUILD_ENABLED=false\nGATSBY_TEST_SEARCH_UI=false\n`, + `GATSBY_PARSER_USER=TestUser\nGATSBY_PARSER_BRANCH=${jobHandlerTestHelper.job.payload.branchName}\nPATH_PREFIX=/\nGATSBY_BASE_URL=test\nPREVIEW_BUILD_ENABLED=false\nGATSBY_TEST_SEARCH_UI=false\nGATSBY_SHOW_CHATBOT=false\n`, { encoding: 'utf8', flag: 'w' } ); }); diff --git a/tests/utils/jobHandlerTestHelper.ts b/tests/utils/jobHandlerTestHelper.ts index ea24e8a1d..9d9e871e9 100644 --- a/tests/utils/jobHandlerTestHelper.ts +++ b/tests/utils/jobHandlerTestHelper.ts @@ -148,6 +148,7 @@ export class JobHandlerTestHelper { this.config.get.calledWith('gatsbyBaseUrl').mockReturnValue('test'); this.config.get.calledWith('previewBuildEnabled').mockReturnValue('false'); this.config.get.calledWith('featureFlagSearchUI').mockReturnValue('false'); + this.config.get.calledWith('gatsbyUseChatbot').mockReturnValue('false'); this.repoConnector.checkCommits .calledWith(this.job) .mockReturnValue(TestDataProvider.getCommitCheckValidResponse(this.job)); From dbb00e83562253f91e0336d59d5e02cf1ecce7bd Mon Sep 17 00:00:00 2001 From: Brandon Ly Date: Fri, 15 Sep 2023 08:36:16 -0500 Subject: [PATCH 7/7] [BUGFIX]: Fix duplicate parameter deploy error (#907) --- cdk-infra/lib/constructs/api/webhook-env-construct.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/cdk-infra/lib/constructs/api/webhook-env-construct.ts b/cdk-infra/lib/constructs/api/webhook-env-construct.ts index 2aefada52..eec5651ff 100644 --- a/cdk-infra/lib/constructs/api/webhook-env-construct.ts +++ b/cdk-infra/lib/constructs/api/webhook-env-construct.ts @@ -3,7 +3,7 @@ import { StringParameter } from 'aws-cdk-lib/aws-ssm'; import { Construct } from 'constructs'; import { getSsmPathPrefix } from '../../../utils/ssm'; import { getDashboardUrl } from '../../../utils/slack'; -import { getEnv } from '../../../utils/env'; +import { getEnv, getFeatureName } from '../../../utils/env'; interface WebhookEnvConstructProps { jobsQueue: IQueue; @@ -18,10 +18,11 @@ export class WebhookEnvConstruct extends Construct { const ssmPrefix = getSsmPathPrefix(); const env = getEnv(); + const featureName = getFeatureName(); // Create configurable feature flag that lives in parameter store. const monorepoPathFeature = new StringParameter(this, 'monorepoPathFeature', { - parameterName: `${ssmPrefix}/monorepo/path_feature`, + parameterName: `${ssmPrefix}/${featureName}/monorepo/path_feature`, stringValue: env === 'dotcomstg' || env === 'stg' ? 'true' : 'false', });