Skip to content

Commit

Permalink
Merge branch 'master' into DOP-3999
Browse files Browse the repository at this point in the history
  • Loading branch information
anabellabuckvar authored Sep 7, 2023
2 parents 78e1f13 + a746745 commit f97d340
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 28 deletions.
14 changes: 14 additions & 0 deletions .github/scripts/webhook-pr-comment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const fs = require('fs');
const path = require('path');
module.exports = () => {
try {
const outputsFile = fs.readFileSync('cdk-infra/outputs.json').toString();
const outputs = JSON.parse(outputsFile);

const webhook = Object.values(outputs[`auto-builder-stack-enhancedApp-stg-${process.env.GIT_BRANCH}-webhooks`])[0];
return webhook;
} catch (error) {
console.log('Error occurred when retrieving Webhook URL', error);
return '';
}
};
20 changes: 16 additions & 4 deletions .github/workflows/deploy-feature-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ on:
types:
- opened
- reopened

name: Initial Feature Branch Deploy
jobs:
deploy:
permissions: write-all
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand All @@ -28,5 +27,18 @@ jobs:
cd cdk-infra/
npm ci
npm run deploy:feature -- -c env=stg -c customFeatureName=enhancedApp-stg-${{github.head_ref}} --outputs-file outputs.json
- name: Display resource URLs
run: cat cdk-infra/outputs.json
- name: Get Webhook URL
uses: actions/github-script@v6
id: webhook
env:
GIT_BRANCH: ${{github.head_ref}}
with:
script: |
const script = require('./.github/scripts/webhook-pr-comment.js');
return script()
result-encoding: string
- name: Comment on PR
if: steps.webhook.outputs.result != ''
run: gh pr comment ${{github.event.number}} --body "The URL for your feature branch webhook is ${{steps.webhook.outputs.result}}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.8
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
Expand Down
16 changes: 13 additions & 3 deletions api/controllers/v1/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('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':
Expand Down Expand Up @@ -213,7 +222,8 @@ async function NotifyBuildProgress(jobId: string): Promise<any> {
jobId,
jobTitle,
fullDocument.status as string,
fullDocument?.error?.reason || ''
fullDocument?.error?.reason || '',
fullDocument?.payload.jobType
),
entitlement['slack_user_id']
);
Expand Down
25 changes: 23 additions & 2 deletions modules/oas-page-builder/src/services/pageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface AtlasSpecUrlParams {
apiKeyword: string;
apiVersion?: string;
resourceVersion?: string;
latestResourceVersion?: string;
}

const ensureSavedVersionDataMatches = (versions: VersionData, apiVersion?: string, resourceVersion?: string) => {
Expand All @@ -57,7 +58,12 @@ const ensureSavedVersionDataMatches = (versions: VersionData, apiVersion?: strin
}
};

const getAtlasSpecUrl = async ({ apiKeyword, apiVersion, resourceVersion }: AtlasSpecUrlParams) => {
const getAtlasSpecUrl = async ({
apiKeyword,
apiVersion,
resourceVersion,
latestResourceVersion,
}: AtlasSpecUrlParams) => {
// Currently, the only expected API fetched programmatically is the Cloud Admin API,
// but it's possible to have more in the future with varying processes.
const keywords = ['cloud'];
Expand All @@ -66,7 +72,11 @@ const getAtlasSpecUrl = async ({ apiKeyword, apiVersion, resourceVersion }: Atla
}

const versionExtension = `${apiVersion ? `-v${apiVersion.split('.')[0]}` : ''}${
apiVersion && resourceVersion ? `-${resourceVersion}` : ''
apiVersion && resourceVersion
? `-${resourceVersion}`
: apiVersion && latestResourceVersion && !resourceVersion
? `-${latestResourceVersion}`
: ''
}`;

let oasFileURL;
Expand Down Expand Up @@ -169,6 +179,17 @@ async function getOASpec({
resourceVersions.length - 1
];

/* Build the latest Resource Version spec if on a base API Version that has multiple Resource Versions
* Do not build the base API VERSION, since it may have out of order resources*/
const { oasFileURL, successfulGitHash } = await getAtlasSpecUrl({
apiKeyword: source,
apiVersion,
resourceVersion,
latestResourceVersion,
});
spec = oasFileURL;
isSuccessfulBuild = successfulGitHash;

versionOptions = {
active: {
apiVersion,
Expand Down
22 changes: 5 additions & 17 deletions modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('pageBuilder', () => {

await buildOpenAPIPages(testEntries, testOptions);

expect(mockExecute).toBeCalledTimes(testEntries.length * 2);
expect(mockExecute).toBeCalledTimes(4);
// Local
expect(mockExecute).toBeCalledWith(
`${testOptions.repo}/source${testEntries[0][1].source}`,
Expand All @@ -201,12 +201,6 @@ describe('pageBuilder', () => {
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`)
);

expect(mockExecute).toBeCalledWith(
`${testOptions.repo}/source${testEntries[0][1].source}`,
`${testOptions.output}/${testEntries[0][0]}/index.html`,
expectedDefaultBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`)
);
// Url
expect(mockExecute).toBeCalledWith(
`${testEntries[1][1].source}`,
Expand All @@ -215,12 +209,6 @@ describe('pageBuilder', () => {
getExpectedVersionOptions(`${SITE_URL}/${testEntries[1][0]}`)
);

expect(mockExecute).toBeCalledWith(
`${testEntries[1][1].source}`,
getExpectedOutputPath(testOptions.output, testEntries[1][0], API_VERSION),
expectedDefaultBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[1][0]}`)
);
// Atlas
expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
Expand All @@ -230,8 +218,8 @@ describe('pageBuilder', () => {
);

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION),
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION, RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[2][0]}`)
);
Expand Down Expand Up @@ -280,8 +268,8 @@ describe('pageBuilder', () => {
);

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION),
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, LATEST_RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, LATEST_RESOURCE_VERSION)
);
Expand Down

0 comments on commit f97d340

Please sign in to comment.