Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOP-4414: Lambda function to handle automated test deploys #1011

Merged
merged 224 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from 223 commits
Commits
Show all changes
224 commits
Select commit Hold shift + click to select a range
4db21c2
DOP-4414 pushing to preprd
anabellabuckvar Mar 6, 2024
278012d
DOP-4414 logging more
anabellabuckvar Mar 7, 2024
51c62aa
DOP-4414 logging
anabellabuckvar Mar 8, 2024
b68c870
DOP-4414 logging
anabellabuckvar Mar 8, 2024
6539150
DOP-4414 logging
anabellabuckvar Mar 8, 2024
8cdff97
DOP-4414 logging
anabellabuckvar Mar 8, 2024
a26d20d
DOP-4414 initial changes
anabellabuckvar Mar 8, 2024
c432cdb
DOP-4414 majority of ticket
anabellabuckvar Mar 11, 2024
4f784e2
DOP-4414 cleaning up
anabellabuckvar Mar 11, 2024
269718b
DOP-4414 refactoring
anabellabuckvar Mar 12, 2024
7d6edd6
DOP-4414 webhook api construct
anabellabuckvar Mar 12, 2024
f9d4616
DOP-4414 checks build on main
anabellabuckvar Mar 12, 2024
63b183f
DOP-4414 update validation
anabellabuckvar Mar 12, 2024
295f27f
DOP-4414 deploy to preprd
anabellabuckvar Mar 12, 2024
8d09650
DOP-4414 testing webhook
anabellabuckvar Mar 12, 2024
807be13
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
2671250
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
01dc7b8
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
e60b482
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
b73845d
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
c44d6bf
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
9b9b25d
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
9d6d0d5
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
e9dd2a1
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
47eee25
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
aa1904e
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
c85b210
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
1298971
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
b76af20
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
46cf92e
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
aba0f43
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
dcebb4f
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
c6809ff
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
f43dd05
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
e80cdab
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
c187a36
DOP-4414 testing lambda
anabellabuckvar Mar 12, 2024
c088704
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
e886331
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
9acfb29
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
93a360a
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
ca3814c
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
0bf36a5
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
1ce574b
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
c51a0e0
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
a43b0db
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
285f88e
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
b420a80
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
14280a6
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
8844c5a
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
dfa6854
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
81461c2
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
3a6c918
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
c9a40ea
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
d603529
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
e650b15
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
26f648b
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
0fb91a1
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
33f91cf
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
d895253
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
b1c8c27
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
64e1c34
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
0a83774
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
bddde4c
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
e3f4151
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
ba4dbae
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
666debf
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
97f61fd
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
b1a0423
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
c81dce1
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
b4bca05
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
783dd3b
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
ad1bd54
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
a574352
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
622f914
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
65572bb
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
23cab1f
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
81ff14f
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
452bd57
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
ca67083
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
e1c7d11
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
8dd1e0c
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
521092b
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
ea6eb17
DOP-4414 testing lambda
anabellabuckvar Mar 13, 2024
3864344
DOP-4414 more changes
anabellabuckvar Mar 13, 2024
61eb93e
DOP-4414 cleaning up
anabellabuckvar Mar 13, 2024
62d9ee3
DOP-4414 cleaning up
anabellabuckvar Mar 13, 2024
7d55d9d
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
3cddb7f
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
5dc7ff3
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
8100244
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
49e106a
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
33c1d31
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
20ab10f
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
221187a
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
56e63cf
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
099bbbe
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
16a4057
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
ac84af3
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
c3c32aa
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
0c7b269
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
c15f5bb
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
39f729d
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
8e378d2
DOP-4414 push to preprd
anabellabuckvar Mar 14, 2024
ab21345
DOP-4414 return true early
anabellabuckvar Mar 14, 2024
d3a7632
DOP-4414 return true early
anabellabuckvar Mar 14, 2024
cdc2a80
DOP-4414 return true early
anabellabuckvar Mar 14, 2024
49262cc
DOP-4414 return true early
anabellabuckvar Mar 14, 2024
4eb40e0
DOP-4414 return true early
anabellabuckvar Mar 14, 2024
4c27e3a
DOP-4414 return true early
anabellabuckvar Mar 14, 2024
debac8f
DOP-4414 return true early
anabellabuckvar Mar 15, 2024
fbb6987
DOP-4414 return true early
anabellabuckvar Mar 15, 2024
0dd6ecc
DOP-4414 remove validation
anabellabuckvar Mar 15, 2024
8280c1b
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
84768ee
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
a324aa9
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
d1aa508
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
c3f01ff
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
51bc791
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
7035d96
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
bed862c
DOP-4414 fewer sites
anabellabuckvar Mar 15, 2024
304cc33
DOP-4414 testing job prefix
anabellabuckvar Mar 15, 2024
511d6d7
DOP-4414 testing job prefix
anabellabuckvar Mar 15, 2024
f509707
DOP-4414 testing job prefix
anabellabuckvar Mar 15, 2024
98a2e69
DOP-4414 testing job prefix
anabellabuckvar Mar 15, 2024
2b2c108
DOP-4414 testing job prefix
anabellabuckvar Mar 15, 2024
0811ee2
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
f09d8e1
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
4a37c8d
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
68bd960
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
bb47d60
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
48722fe
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
8edf348
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
48e8e72
DOP-4414 testing job prefix
anabellabuckvar Mar 16, 2024
6237463
DOP-4414 testing job prefix
anabellabuckvar Mar 17, 2024
a2f7f1f
DOP-4414 testing
anabellabuckvar Mar 18, 2024
489efa1
DOP-4414 testing
anabellabuckvar Mar 18, 2024
7a9b1ae
DOP-4414 testing
anabellabuckvar Mar 18, 2024
cc36292
DOP-4414 testing
anabellabuckvar Mar 18, 2024
fd61bfc
DOP-4414 testing
anabellabuckvar Mar 18, 2024
bc14ddf
DOP-4414 testing
anabellabuckvar Mar 18, 2024
3bc7982
DOP-4414 testing
anabellabuckvar Mar 18, 2024
484d6a1
DOP-4414 testing
anabellabuckvar Mar 18, 2024
d5aa217
DOP-4414 testing
anabellabuckvar Mar 18, 2024
69a0086
DOP-4414 testing
anabellabuckvar Mar 18, 2024
25f19b8
DOP-4414 testing
anabellabuckvar Mar 18, 2024
50a685a
DOP-4414 testing jobupdates queue
anabellabuckvar Mar 18, 2024
a0088eb
DOP-4414 testing refactor
anabellabuckvar Mar 18, 2024
60ddb03
DOP-4414 testing refactor
anabellabuckvar Mar 18, 2024
41787bf
DOP-4414 testing jobupdatesqueue
anabellabuckvar Mar 18, 2024
7799369
DOP-4414 cleaning up
anabellabuckvar Mar 18, 2024
c11c3ba
Merge branch 'main' into DOP-4414
anabellabuckvar Mar 18, 2024
10bf719
DOP-4414 webhook update and cleaning
anabellabuckvar Mar 18, 2024
db82c8d
DOP-4414 secret
anabellabuckvar Mar 18, 2024
635025b
DOP-4414 checking main
anabellabuckvar Mar 18, 2024
98c4a15
DOP-4414 checking main
anabellabuckvar Mar 18, 2024
aee5cd4
DOP-4414 types and env vars
anabellabuckvar Mar 19, 2024
bce69c3
DOP-4414 comment out check for main branch
anabellabuckvar Mar 19, 2024
c86c466
DOP-4414 entitlements repos
anabellabuckvar Mar 19, 2024
c4ac837
DOP-4414 testing
anabellabuckvar Mar 19, 2024
2c3693a
revert "DOP-4414 testing"
anabellabuckvar Mar 19, 2024
242cf10
Revert "DOP-4414 entitlements repos"
anabellabuckvar Mar 19, 2024
40a1194
Revert "DOP-4414 comment out check for main branch"
anabellabuckvar Mar 19, 2024
6ccdc00
reverting commit
anabellabuckvar Mar 19, 2024
c2b1f57
DOP-4414 comment out main check for testing
anabellabuckvar Mar 19, 2024
abdd426
DOP-4414 testing
anabellabuckvar Mar 19, 2024
1a79d7b
DOP-4414 add branch to deploy enhanced worker
anabellabuckvar Mar 19, 2024
273da47
DOP-4414 add branch to deploy enhanced webhook
anabellabuckvar Mar 20, 2024
ca9bb9f
DOP-4414 add branch to deploy enhanced webhook
anabellabuckvar Mar 20, 2024
dccda66
DOP-4414 add branch to deploy enhanced webhook
anabellabuckvar Mar 20, 2024
d953ccd
DOP-4414 add branch to deploy enhanced webhook
anabellabuckvar Mar 20, 2024
c0fe254
DOP-4414 nits
anabellabuckvar Mar 20, 2024
b28d519
DOP-4414 fixing small error
anabellabuckvar Mar 20, 2024
61b2c33
DOP-4414 refactoring promises
anabellabuckvar Mar 20, 2024
47d0600
DOP-4414 testing new promise format
anabellabuckvar Mar 20, 2024
654f59b
DOP-4414 testing new promise format
anabellabuckvar Mar 20, 2024
3fefba1
DOP-4414 testing new promise format
anabellabuckvar Mar 20, 2024
025a872
DOP-4414 refactoring and cleaning
anabellabuckvar Mar 20, 2024
2797e71
DOP-4414 refactoring and cleaning
anabellabuckvar Mar 20, 2024
b82af1a
DOP-4414 adding projects collection as constant
anabellabuckvar Mar 21, 2024
70c67bd
DOP-4414 add docs_metadata as constant
anabellabuckvar Mar 21, 2024
73ce79e
DOP-4414 remove unecessary vars from the configs
anabellabuckvar Mar 25, 2024
2563973
DOP-4414 readded name
anabellabuckvar Mar 25, 2024
bfb75a9
DOP-4414 testing
anabellabuckvar Mar 25, 2024
b48eff1
DOP-4414 testing env vars
anabellabuckvar Mar 25, 2024
b0fcb25
DOP-4414 testing env vars
anabellabuckvar Mar 25, 2024
98be689
DOP-4414 testing env vars
anabellabuckvar Mar 25, 2024
7a85e8b
DOP-4414 testing env vars
anabellabuckvar Mar 25, 2024
aaf71e9
DOP-4414 testing env vars
anabellabuckvar Mar 25, 2024
d0071fd
DOP-4414 testing env vars removing from yamls
anabellabuckvar Mar 25, 2024
2c71ab2
DOP-4414 testing env vars removing adding back to yamll
anabellabuckvar Mar 25, 2024
7a62fc3
DOP-4414 testing env vars removing adding back to yamll
anabellabuckvar Mar 25, 2024
cde1bdd
DOP-4414 testing env vars removing from get-env-vars
anabellabuckvar Mar 25, 2024
88def81
DOP-4414 testing env vars removing from get-env-vars
anabellabuckvar Mar 25, 2024
e6a2906
DOP-4414 testing env vars removing jsons
anabellabuckvar Mar 25, 2024
2f6b1a0
DOP-4414 ssm putparam
anabellabuckvar Mar 25, 2024
ea685a6
DOP-4414 removing env vars
anabellabuckvar Mar 25, 2024
7d1a06f
DOP-4414 removing env vars
anabellabuckvar Mar 25, 2024
8e39c0b
DOP-4414 removing more env vars
anabellabuckvar Mar 25, 2024
0838c01
DOP-4414 removing more env vars
anabellabuckvar Mar 25, 2024
73875bf
DOP-4414 uncomment main branch check
anabellabuckvar Mar 25, 2024
770ffcc
DOP-4414 cleaning up
anabellabuckvar Mar 25, 2024
2da0106
DOP-4414 last cleaning
anabellabuckvar Mar 25, 2024
3bf25c6
Merge branch 'main' into DOP-4414
anabellabuckvar Mar 25, 2024
a164201
Merge branch 'main' into DOP-4414
anabellabuckvar Mar 26, 2024
7fddfaa
DOP-4414 removing from preprd
anabellabuckvar Mar 26, 2024
9867c1a
DOP-4414 playing with prefixes, all changes in this commit should not…
anabellabuckvar Apr 8, 2024
64c4d9a
DOP-4414 push to preprd
anabellabuckvar Apr 8, 2024
b1a415d
DOP-4414 trying to get jobhandler lambda to update and reflect changes
anabellabuckvar Apr 9, 2024
5b79c9f
Fix workflow cache
branberry Apr 9, 2024
3632a74
Fix workflow paths
branberry Apr 9, 2024
2be4d3e
DOP-4414 nit changing how returnVal is declared
anabellabuckvar Apr 9, 2024
ae39269
Fix workflow paths
branberry Apr 9, 2024
0203e96
Fix workflow paths
branberry Apr 9, 2024
cc64860
DOP-4414 changing prefix again
anabellabuckvar Apr 9, 2024
2f42c08
DOP-4414 adding code for newHead and changing mut prefix path
anabellabuckvar Apr 9, 2024
71bbf83
DOP-4414 removing newHead and passing in hash through title
anabellabuckvar Apr 9, 2024
7e19595
DOP-4414 fixing conditional for amending mut prefix so that it executes
anabellabuckvar Apr 9, 2024
cfb3f13
DOP-4414 placing commitHash at end of mutprefix instead of beginngin
anabellabuckvar Apr 10, 2024
cc3a702
DOP-4414 adding extra part to mutprefix path
anabellabuckvar Apr 10, 2024
d38b616
DOP-4414 reversing changes made for testing purposes
anabellabuckvar Apr 10, 2024
d65eb0c
DOP-4414 reverting more changes that were made for testing
anabellabuckvar Apr 10, 2024
a935da1
DOP-4414 conditional nit
anabellabuckvar Apr 10, 2024
245cb6a
Merge branch 'main' into DOP-4414
anabellabuckvar Apr 10, 2024
a7c5833
Merge branch 'main' into DOP-4414
anabellabuckvar Apr 11, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/deploy-stg-enhanced-webhooks.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
on:
push:
paths: ["api/v2/**", "cdk-infra/lib/constructs/api/**", "cdk-infra/utils/**"]
paths: ['api/**', 'cdk-infra/lib/constructs/api/**', 'cdk-infra/utils/**']
branches:
- "main"
- "integration"
- 'main'
- 'integration'

concurrency:
group: environment-stg-enhanced-webhooks-${{ github.ref }}
Expand All @@ -30,4 +30,3 @@ jobs:
npm ci
npm run deploy:feature:stack -- -c env=dotcomstg -c customFeatureName=enhancedApp-dotcomstg auto-builder-stack-enhancedApp-dotcomstg-webhooks
npm run deploy:feature:stack -- -c env=stg -c customFeatureName=enhancedApp-stg auto-builder-stack-enhancedApp-stg-webhooks

1 change: 0 additions & 1 deletion .github/workflows/deploy-stg-enhanced-worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
branches:
- 'main'
- 'integration'

concurrency:
group: environment-stg-enhanced-worker-${{ github.ref }}
cancel-in-progress: true
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/update-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ jobs:
node_modules
cdk-infra/node_modules
key: ${{ github.head_ref }}
- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
npm ci
cd cdk-infra/
npm ci
- uses: dorny/paths-filter@v2
id: filter
with:
Expand Down Expand Up @@ -96,6 +102,12 @@ jobs:
node_modules
cdk-infra/node_modules
key: ${{ github.head_ref }}
- name: Install Dependencies
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
npm ci
cd cdk-infra/
npm ci
- uses: dorny/paths-filter@v2
id: filter
with:
Expand Down
264 changes: 227 additions & 37 deletions api/controllers/v2/github.ts
Original file line number Diff line number Diff line change
@@ -1,71 +1,125 @@
import * as c from 'config';
import * as mongodb from 'mongodb';
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
import { PushEvent } from '@octokit/webhooks-types';
import { PushEvent, WorkflowRunCompletedEvent } from '@octokit/webhooks-types';

import { JobRepository } from '../../../src/repositories/jobRepository';
import { ConsoleLogger } from '../../../src/services/logger';
import { RepoBranchesRepository } from '../../../src/repositories/repoBranchesRepository';
import { EnhancedJob, JobStatus } from '../../../src/entities/job';
import { ProjectsRepository } from '../../../src/repositories/projectsRepository';
import { EnhancedJob, EnhancedPayload, JobStatus } from '../../../src/entities/job';
import { markBuildArtifactsForDeletion, validateJsonWebhook } from '../../handlers/github';
import { DocsetsRepository } from '../../../src/repositories/docsetsRepository';
import { getMonorepoPaths } from '../../../src/monorepo';
import { getUpdatedFilePaths } from '../../../src/monorepo/utils/path-utils';
import { ReposBranchesDocsetsDocument } from '../../../modules/persistence/src/services/metadata/repos_branches';
import { MONOREPO_NAME } from '../../../src/monorepo/utils/monorepo-constants';

const SMOKETEST_SITES = [
'docs-landing',
'cloud-docs',
'docs-realm',
'docs',
'docs-atlas-cli',
'docs-node',
'docs-app-services',
];

//EnhancedPayload and EnhancedJob are used here for both githubPush (feature branch) events as well as productionDeploy(smoke test deploy) events for typing purposes
async function prepGithubPushPayload(
githubEvent: PushEvent,
repoBranchesRepository: RepoBranchesRepository,
prefix: string,
repoInfo: ReposBranchesDocsetsDocument,
directory?: string
githubEvent: PushEvent | WorkflowRunCompletedEvent,
payload: EnhancedPayload,
title: string
): Promise<Omit<EnhancedJob, '_id'>> {
const branch_name = githubEvent.ref.split('/')[2];
const branch_info = await repoBranchesRepository.getRepoBranchAliases(
githubEvent.repository.name,
branch_name,
repoInfo.project
);
const urlSlug = branch_info.aliasObject?.urlSlug ?? branch_name;
const project = repoInfo?.project ?? githubEvent.repository.name;

return {
title: githubEvent.repository.full_name,
user: githubEvent.pusher.name,
email: githubEvent.pusher.email ?? '',
title: title,
user: githubEvent.sender.login,
status: JobStatus.inQueue,
createdTime: new Date(),
startTime: null,
endTime: null,
priority: 1,
error: {},
result: null,
payload: {
jobType: 'githubPush',
source: 'github',
action: 'push',
repoName: githubEvent.repository.name,
branchName: githubEvent.ref.split('/')[2],
isFork: githubEvent.repository.fork,
repoOwner: githubEvent.repository.owner.login,
url: githubEvent.repository.clone_url,
newHead: githubEvent.after,
urlSlug: urlSlug,
prefix: prefix,
project: project,
directory: directory,
},
payload,
logs: [],
};
}

export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
interface CreatePayloadProps {
repoName: string;
isSmokeTestDeploy?: boolean;
prefix: string;
repoBranchesRepository: RepoBranchesRepository;
repoInfo: ReposBranchesDocsetsDocument;
newHead?: string;
repoOwner?: string;
githubEvent?: PushEvent;
directory?: string;
}

async function createPayload({
repoName,
isSmokeTestDeploy = false,
prefix,
repoBranchesRepository,
repoInfo,
newHead,
repoOwner = '',
githubEvent,
directory,
}: CreatePayloadProps): Promise<EnhancedPayload> {
const source = 'github';
const project = repoInfo?.project ?? repoName;

let branchName: string;
let jobType: string;
let action: string;
let url: string;

if (isSmokeTestDeploy) {
url = 'https://github.com/' + repoOwner + '/' + repoName;
action = 'automatedTest';
jobType = 'productionDeploy';
branchName = 'master';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not blocking (I don't think): I believe we've instituted a way within the parser to deal with a content repo's master branch to be named either "master" or "main". I wonder if we need to find a way to be agnostic here as well... once again, this is maybe a different ticket. To my knowledge all content repos use "master"...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thank you. I did consider this, but I checked at least the specific content repos that Allison requested always be deployed for smoke tests, and those at least all use "master" as the master branch.

If, at a later date, someone, for some reason, adds a repo to the list that uses main, they will have to add additional logic to handle that then. However, I agree that I don't believe it should be blocking right now for that hypothetical

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

} else {
if (!githubEvent) {
throw new Error(`Non SmokeTest Deploy jobs must have a github Event`);
}
action = 'push';
jobType = 'githubPush';
branchName = githubEvent.ref.split('/')[2];
url = githubEvent.repository?.clone_url;
newHead = githubEvent.after;
repoOwner = githubEvent.repository?.owner?.login;
}

const branchInfo = await repoBranchesRepository.getRepoBranchAliases(repoName, branchName, repoInfo.project);
const urlSlug = branchInfo.aliasObject?.urlSlug ?? branchName;

return {
jobType,
source,
action,
repoName,
repoOwner,
branchName,
project,
prefix,
urlSlug,
url,
newHead,
directory,
};
}

export const triggerSmokeTestAutomatedBuild = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult | null> => {
const client = new mongodb.MongoClient(c.get('dbUrl'));
await client.connect();
const db = client.db(c.get('dbName'));
const consoleLogger = new ConsoleLogger();
const jobRepository = new JobRepository(db, c, consoleLogger);
const projectsRepository = new ProjectsRepository(client.db(process.env.METADATA_DB_NAME), c, consoleLogger);
const repoBranchesRepository = new RepoBranchesRepository(db, c, consoleLogger);
const docsetsRepository = new DocsetsRepository(db, c, consoleLogger);

Expand All @@ -79,6 +133,132 @@ export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayPr
};
}

if (!validateJsonWebhook(event, c.get<string>('githubSecret'))) {
const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match";
return {
statusCode: 401,
headers: { 'Content-Type': 'text/plain' },
body: errMsg,
};
}

let body: WorkflowRunCompletedEvent;
try {
body = JSON.parse(event.body) as WorkflowRunCompletedEvent;
} catch (e) {
console.log('[TriggerBuild]: ERROR! Could not parse event.body', e);
return {
statusCode: 502,
headers: { 'Content-Type': 'text/plain' },
body: ' ERROR! Could not parse event.body',
};
}

if (body.workflow_run.conclusion != 'success')
return {
statusCode: 202,
headers: { 'Content-Type': 'text/plain' },
body: `Build on branch ${body.workflow_run.head_branch} is not complete and will not trigger smoke test site deployments`,
};

if (body.workflow_run.name != 'Deploy Staging ECS')
return {
statusCode: 202,
headers: { 'Content-Type': 'text/plain' },
body: `Workflow ${body.workflow_run.name} completed successfully but only Deploy Staging ECS workflow completion will trigger smoke test site deployments`,
};

// if the build was not building main branch, no need for smoke test sites
if (body.workflow_run.head_branch != 'main' || body.repository.fork) {
branberry marked this conversation as resolved.
Show resolved Hide resolved
console.log('Build was not on master branch in main repo, sites will not deploy as no smoke tests are needed');
return {
statusCode: 202,
headers: { 'Content-Type': 'text/plain' },
body: `Build on branch ${body.workflow_run.head_branch} will not trigger site deployments as it was not on main branch in upstream repo`,
};
}

//automated test builds will always deploy in dotcomstg
const env = 'dotcomstg';

async function createAndInsertJob() {
return await Promise.all(
SMOKETEST_SITES.map(async (repoName): Promise<string> => {
const jobTitle = `Smoke Test ${repoName} site for commit ${body.workflow_run.head_sha} on docs-worker-pool main branch`;
let repoInfo, projectEntry, repoOwner;
try {
repoInfo = await docsetsRepository.getRepo(repoName);
projectEntry = await projectsRepository.getProjectEntry(repoInfo.project);
repoOwner = projectEntry.github.organization;
} catch (err) {
consoleLogger.error(
`Atlas Repo Information Error`,
`RepoInfo, projectEntry, or repoOwner not found for docs site ${repoName}. RepoInfo: ${repoInfo}, projectEntry: ${projectEntry}, repoOwner: ${repoOwner}`
);
return err;
}

const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
const payload = await createPayload({
repoName,
isSmokeTestDeploy: true,
prefix: jobPrefix,
repoBranchesRepository,
repoInfo,
repoOwner,
});

//add logic for getting master branch, latest stable branch
const job = await prepGithubPushPayload(body, payload, jobTitle);

try {
consoleLogger.info(job.title, 'Creating Job');
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
jobRepository.notify(jobId, c.get('jobUpdatesQueueUrl'), JobStatus.inQueue, 0);
consoleLogger.info(job.title, `Created Job ${jobId}`);
return jobId;
} catch (err) {
consoleLogger.error('TriggerBuildError', `${err} Error inserting job for ${repoName}`);
return err;
}
})
);
}

try {
const returnVal = await createAndInsertJob();
return {
statusCode: 202,
headers: { 'Content-Type': 'text/plain' },
body: 'Smoke Test Jobs Queued with the following Job Ids ' + returnVal,
};
} catch (err) {
return {
statusCode: 500,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}
};

export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayProxyResult> => {
const client = new mongodb.MongoClient(c.get('dbUrl'));
await client.connect();
const db = client.db(c.get('dbName'));
const consoleLogger = new ConsoleLogger();
const jobRepository = new JobRepository(db, c, consoleLogger);
const repoBranchesRepository = new RepoBranchesRepository(db, c, consoleLogger);
const docsetsRepository = new DocsetsRepository(db, c, consoleLogger);

if (!event.body) {
const err = 'Trigger build does not have a body in event payload';
return {
statusCode: 400,
headers: { 'Content-Type': 'text/plain' },
body: err,
};
}

if (!validateJsonWebhook(event, c.get<string>('githubSecret'))) {
const errMsg = "X-Hub-Signature incorrect. Github webhook token doesn't match";
return {
Expand Down Expand Up @@ -110,9 +290,19 @@ export const TriggerBuild = async (event: APIGatewayEvent): Promise<APIGatewayPr
const env = c.get<string>('env');

async function createAndInsertJob(path?: string) {
const repoInfo = await docsetsRepository.getRepo(body.repository.name, path);
const repo = body.repository;
const repoInfo = await docsetsRepository.getRepo(repo.name, path);
const jobPrefix = repoInfo?.prefix ? repoInfo['prefix'][env] : '';
const job = await prepGithubPushPayload(body, repoBranchesRepository, jobPrefix, repoInfo, path);
const jobTitle = repo.full_name;
const payload = await createPayload({
repoName: repo.name,
prefix: jobPrefix,
repoBranchesRepository,
repoInfo,
githubEvent: body,
});

const job = await prepGithubPushPayload(body, payload, jobTitle);

consoleLogger.info(job.title, 'Creating Job');
const jobId = await jobRepository.insertJob(job, c.get('jobsQueueUrl'));
Expand Down
4 changes: 2 additions & 2 deletions api/controllers/v2/slack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ConsoleLogger, ILogger } from '../../../src/services/logger';
import { SlackConnector } from '../../../src/services/slack';
import { JobRepository } from '../../../src/repositories/jobRepository';
import { APIGatewayEvent, APIGatewayProxyResult } from 'aws-lambda';
import { JobStatus } from '../../../src/entities/job';
import { EnhancedPayload, JobStatus } from '../../../src/entities/job';
import {
buildEntitledBranchList,
getQSString,
Expand Down Expand Up @@ -256,7 +256,7 @@ function createPayload(
};
}

function createJob(payload: any, jobTitle: string, jobUserName: string, jobUserEmail: string) {
function createJob(payload: EnhancedPayload, jobTitle: string, jobUserName: string, jobUserEmail: string) {
return {
title: jobTitle,
user: jobUserName,
Expand Down
Loading
Loading