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

correct branch #45

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 10 additions & 11 deletions extensions/redirects-and-publish/src/mutRedirectsAndPublish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@ export const mutRedirectsAndPublish = async (
): Promise<void> => {
// Connect to mongodb and pool.docsets to get bucket
const docsetEntry = configEnvironment?.DOCSET_ENTRY;
if (!docsetEntry) {
throw new Error ("Unable to retrive DOCSET_ENTRY");
}
console.log('Succesfully got docsets entry:', docsetEntry);

console.log('the urlslug is', configEnvironment?.BRANCH_ENTRY?.urlSlug);

// We want to copy the snooty folder and run `npm run build` instead of `npm run build:no-prefix` as it does in the build.sh
// We do this so when we run mut-publish we are able to uplaod the correct files with the correct paths
await run.command('rm -f -r running-mut');
await run.command('mkdir -p running-mut');

if (configEnvironment?.SITE_NAME === 'mongodb-snooty') {
// Since mongodb-snooty is not a content repo the file structure is different and needs to be treated as such
// TODO: this should also happen for dotcomprd if configEnvironment.ENV == dotcomstg or (dotcomprd)
if (configEnvironment?.ENV === 'dotcomstg') {
await run.command('mkdir -p running-mut/snooty');
await run.command(
`rsync -q -i -av --progress ${process.cwd()} ${process.cwd()}/running-mut/snooty --exclude node_modules --exclude .cache --exclude running-mut`,
);
process.chdir(`${process.cwd()}/running-mut/snooty/repo`);
} else {
await run.command('cp -r snooty running-mut');
process.chdir(`${process.cwd()}/running-mut/snooty`);
}
}

process.env.GATSBY_MANIFEST_PATH = MANIFEST_PATH;
// TODO: When uploaded to prod, run this command instead: process.env.PATH_PREFIX = `/${docsetEntry?.prefix?.[configEnvironment.ENV]}`; (DOP-5178)
Expand All @@ -52,12 +54,9 @@ export const mutRedirectsAndPublish = async (
try {
console.log('Running mut-redirects...');
// TODO: Change hard coded `docs-landing` to whatever repo is being built after DOP-5159 is completed
const redirectPath =
configEnvironment.SITE_NAME === 'mongodb-snooty'
? 'docs-landing/config/redirects'
: '../../config/redirects';
console.log('the repo name is', process.env.REPO_NAME);
await run.command(
`${process.cwd()}/mut/mut-redirects ${redirectPath} -o public/.htaccess`,
`${process.cwd()}/mut/mut-redirects ${process.env.REPO_NAME}/config/redirects -o public/.htaccess`,
);
} catch (e) {
console.log(`Error occurred while running mut-redirects: ${e}`);
Expand Down
39 changes: 22 additions & 17 deletions extensions/redoc/src/atlas.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import { COLLECTION_NAME, db } from './utils/db';

const env = process.env.SNOOTY_ENV ?? '';

const OAS_FILE_SERVER =
env === 'dotcomprd'
? 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/'
: 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/';

const GIT_HASH_URL =
env === 'dotcomprd'
? 'https://cloud.mongodb.com/version'
: 'https://cloud-dev.mongodb.com/version';
import type { ConfigEnvironmentVariables } from 'util/extension';

export interface OASFile {
api: string;
Expand All @@ -22,8 +11,8 @@ export interface OASFile {

export type OASFilePartial = Pick<OASFile, 'gitHash' | 'versions'>;

export const findLastSavedVersionData = async (apiKeyword: string) => {
const dbSession = await db();
export const findLastSavedVersionData = async (apiKeyword: string, configEnvironment: ConfigEnvironmentVariables) => {
const dbSession = await db(configEnvironment);
try {
const projection = { gitHash: 1, versions: 1 };
const filter = { api: apiKeyword };
Expand All @@ -41,14 +30,29 @@ interface AtlasSpecUrlParams {
apiVersion?: string;
resourceVersion?: string;
latestResourceVersion?: string;
configEnvironment?: ConfigEnvironmentVariables;
}

export const getAtlasSpecUrl = async ({
apiKeyword,
apiVersion,
resourceVersion,
latestResourceVersion,
configEnvironment
}: AtlasSpecUrlParams) => {
// get the environemnt from netlify
const env = configEnvironment?.ENV ?? '';

const OAS_FILE_SERVER =
env === 'dotcomprd'
? 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/'
: 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/';

const GIT_HASH_URL =
env === 'dotcomprd'
? 'https://cloud.mongodb.com/version'
: 'https://cloud-dev.mongodb.com/version';

// 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 @@ -70,6 +74,7 @@ export const getAtlasSpecUrl = async ({
let successfulGitHash = true;

try {
const { fetchGitHash, resetGitHashCache } = createFetchGitHash(GIT_HASH_URL);
const gitHash = await fetchGitHash();
oasFileURL = `${OAS_FILE_SERVER}${gitHash}${versionExtension}.json`;

Expand All @@ -81,7 +86,7 @@ export const getAtlasSpecUrl = async ({
const unsuccessfulOasFileURL = oasFileURL;
successfulGitHash = false;

const res = await findLastSavedVersionData(apiKeyword);
const res = await findLastSavedVersionData(apiKeyword, configEnvironment);
if (res) {
ensureSavedVersionDataMatches(res.versions, apiVersion, resourceVersion);
oasFileURL = `${OAS_FILE_SERVER}${res.gitHash}${versionExtension}.json`;
Expand Down Expand Up @@ -130,7 +135,7 @@ function ensureSavedVersionDataMatches(
}
}

function createFetchGitHash() {
function createFetchGitHash(GIT_HASH_URL: string) {
let gitHashCache: string;
return {
fetchGitHash: async () => {
Expand All @@ -153,4 +158,4 @@ function createFetchGitHash() {
};
}

const { fetchGitHash, resetGitHashCache } = createFetchGitHash();

8 changes: 6 additions & 2 deletions extensions/redoc/src/build-pages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { NetlifyPluginUtils } from '@netlify/build';
import type { ConfigEnvironmentVariables } from 'util/extension';
import type { OASPageMetadata } from '.';
import { getAtlasSpecUrl } from './atlas';
import { db } from './utils/db';
Expand Down Expand Up @@ -61,6 +62,7 @@ export async function getBuildOasSpecCommand({
apiKeyword: source,
apiVersion,
resourceVersion,
configEnvironment
});

spec = oasFileURL;
Expand Down Expand Up @@ -141,8 +143,9 @@ export const saveSuccessfulBuildVersionData = async (
apiKeyword: string,
gitHash: string,
versionData: Record<string, string>,
configEnvironment: ConfigEnvironmentVariables
) => {
const dbSession = await db();
const dbSession = await db(configEnvironment);
try {
const query = {
api: apiKeyword,
Expand Down Expand Up @@ -172,6 +175,7 @@ export async function buildOpenAPIPages(
entries: [string, OASPageMetadata][],
{ siteUrl, siteTitle }: PageBuilderOptions,
run: NetlifyPluginUtils['run'],
configEnvironment: ConfigEnvironmentVariables,
) {
for (const [pageSlug, data] of entries) {
const {
Expand Down Expand Up @@ -240,7 +244,7 @@ export async function buildOpenAPIPages(
try {
const gitHash = await fetchGitHash();
const versions = await fetchVersionData(gitHash, OAS_FILE_SERVER);
await saveSuccessfulBuildVersionData(source, gitHash, versions);
await saveSuccessfulBuildVersionData(source, gitHash, versions, configEnvironment);
} catch (e) {
console.error(e);
}
Expand Down
1 change: 1 addition & 0 deletions extensions/redoc/src/utils/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export const teardown = async () => {
};

const getDbName = () => {
// should I replace this with configEnv.ENV
const env = process.env.SNOOTY_ENV ?? '';

switch (env) {
Expand Down
Loading