Skip to content
Merged
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
9 changes: 3 additions & 6 deletions packages/build/src/npm-packages/bump.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ describe('npm-packages bump', function () {
});

describe('bumpMongoshReleasePackages', function () {
it('throws if MONGOSH_RELEASE_VERSION is not set', async function () {
process.env.MONGOSH_RELEASE_VERSION = '';

it('throws if version is not set', async function () {
try {
await bumpMongoshReleasePackages();
await bumpMongoshReleasePackages('');
expect.fail('did not error');
} catch (error) {
expect(error).instanceOf(Error);
expect((error as Error).message).equals(
'MONGOSH_RELEASE_VERSION version not specified during mongosh bump'
'version not specified during mongosh bump'
);
}
});
Expand All @@ -51,7 +49,6 @@ describe('npm-packages bump', function () {

expect(fsWriteFile).calledWith(
path.join(
__dirname,
PROJECT_ROOT,
'packages',
'shell-api',
Expand Down
13 changes: 6 additions & 7 deletions packages/build/src/npm-packages/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import path from 'path';
import { getPackagesInTopologicalOrder } from '@mongodb-js/monorepo-tools';

/** Bumps only the main mongosh release packages to the set version. */
export async function bumpMongoshReleasePackages(): Promise<void> {
const version = process.env.MONGOSH_RELEASE_VERSION;
export async function bumpMongoshReleasePackages(
version: string
): Promise<void> {
if (!version) {
throw new Error(
'MONGOSH_RELEASE_VERSION version not specified during mongosh bump'
);
throw new Error('version not specified during mongosh bump');
}
console.info(`mongosh: Bumping package versions to ${version}`);

console.info(`mongosh: Bumping mongosh release packages to ${version}`);
const monorepoRootPath = path.resolve(__dirname, '..', '..', '..', '..');
const packages = await getPackagesInTopologicalOrder(monorepoRootPath);

Expand Down Expand Up @@ -62,7 +62,6 @@ export async function bumpMongoshReleasePackages(): Promise<void> {
/** Updates the shell-api constant to match the mongosh version. */
export async function updateShellApiMongoshVersion(version: string) {
const shellApiVersionFilePath = path.join(
__dirname,
PROJECT_ROOT,
'packages',
'shell-api',
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/npm-packages/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { bumpAuxiliaryPackages } from './bump';
export { bumpAuxiliaryPackages, bumpMongoshReleasePackages } from './bump';
export { publishToNpm } from './publish';
export { pushTags } from './push-tags';
74 changes: 60 additions & 14 deletions packages/build/src/publish-mongosh.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,17 @@ import type {
import type { createAndPublishDownloadCenterConfig as createAndPublishDownloadCenterConfigFn } from './download-center';
import { GithubRepo } from '@mongodb-js/devtools-github-repo';
import type { publishToHomebrew as publishToHomebrewType } from './homebrew';
import {
type publishToNpm as publishToNpmType,
type pushTags as pushTagsType,
} from './npm-packages';
import type {
publishToNpm as publishToNpmType,
pushTags as pushTagsType,
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
} from './npm-packages';
import { publishMongosh } from './publish-mongosh';
import { dummyConfig } from '../test/helpers';
import { getArtifactUrl } from './evergreen';

chai.use(require('sinon-chai'));

Expand All @@ -36,11 +41,14 @@ describe('publishMongosh', function () {
let writeBuildInfo: typeof writeBuildInfoType;
let publishToHomebrew: typeof publishToHomebrewType;
let shouldDoPublicRelease: typeof shouldDoPublicReleaseFn;
let bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn;
let bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn;
let githubRepo: GithubRepo;
let mongoHomebrewCoreForkRepo: GithubRepo;
let homebrewCoreRepo: GithubRepo;
let barque: Barque;
let pushTags: typeof pushTagsType;
const getEvergreenArtifactUrl = getArtifactUrl;

beforeEach(function () {
config = { ...dummyConfig };
Expand All @@ -51,6 +59,8 @@ describe('publishMongosh', function () {
publishToHomebrew = sinon.spy();
shouldDoPublicRelease = sinon.spy();
pushTags = sinon.spy();
bumpMongoshReleasePackages = sinon.spy();
bumpAuxiliaryPackages = sinon.spy();

githubRepo = createStubRepo();
mongoHomebrewCoreForkRepo = createStubRepo();
Expand Down Expand Up @@ -95,7 +105,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);
} catch (e: any) {
return expect(e.message).to.contain('Could not find prior draft tag');
Expand All @@ -121,7 +134,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);
} catch (e: any) {
return expect(e.message).to.contain('Version mismatch');
Expand All @@ -142,7 +158,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(barque.releaseToBarque).to.have.been.callCount(26);
Expand Down Expand Up @@ -173,7 +192,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(createAndPublishDownloadCenterConfig).to.have.been.calledWith(
Expand All @@ -196,7 +218,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(githubRepo.promoteRelease).to.have.been.calledWith(config);
Expand All @@ -214,7 +239,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(writeBuildInfo).to.have.been.calledOnceWith(config);
Expand All @@ -233,7 +261,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(publishToHomebrew).to.have.been.calledWith(
Expand Down Expand Up @@ -264,7 +295,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(createAndPublishDownloadCenterConfig).not.to.have.been.called;
Expand All @@ -282,7 +316,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(githubRepo.promoteRelease).not.to.have.been.called;
Expand All @@ -300,7 +337,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(publishToNpm).not.to.have.been.called;
Expand All @@ -318,7 +358,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(publishToHomebrew).not.to.have.been.called;
Expand All @@ -336,7 +379,10 @@ describe('publishMongosh', function () {
pushTags,
writeBuildInfo,
publishToHomebrew,
shouldDoPublicRelease
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
);

expect(barque.releaseToBarque).not.to.have.been.called;
Expand Down
11 changes: 10 additions & 1 deletion packages/build/src/publish-mongosh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import type { pushTags as pushTagsType } from './npm-packages';
import { type publishToNpm as publishToNpmType } from './npm-packages';
import type { PackageInformationProvider } from './packaging';
import { getPackageFile } from './packaging';
import {
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
} from './npm-packages';

export async function publishMongosh(
config: Config,
Expand All @@ -27,7 +31,9 @@ export async function publishMongosh(
writeBuildInfo: typeof writeBuildInfoType,
publishToHomebrew: typeof publishToHomebrewType,
shouldDoPublicRelease: typeof shouldDoPublicReleaseFn = shouldDoPublicReleaseFn,
getEvergreenArtifactUrl: typeof getArtifactUrlFn = getArtifactUrlFn
getEvergreenArtifactUrl: typeof getArtifactUrlFn = getArtifactUrlFn,
bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn = bumpMongoshReleasePackagesFn,
bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn
): Promise<void> {
if (!shouldDoPublicRelease(config)) {
console.warn(
Expand Down Expand Up @@ -59,6 +65,9 @@ export async function publishMongosh(
latestDraftTag.name
);

bumpAuxiliaryPackages();
await bumpMongoshReleasePackages(releaseVersion);

await publishArtifactsToBarque(
barque,
config.project as string,
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export async function release(
if (command === 'bump') {
bumpAuxiliaryPackages();
if (!config.useAuxiliaryPackagesOnly) {
await bumpMongoshReleasePackages();
await bumpMongoshReleasePackages(config.version);
}
return;
}
Expand Down
14 changes: 11 additions & 3 deletions packages/build/src/run-draft.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ describe('draft', function () {
});

describe('runDraft', function () {
const bumpMongoshReleasePackages = sinon.spy();
const bumpMongoshAuxiliaryPackages = sinon.spy();
let ensureGithubReleaseExistsAndUpdateChangelog: typeof ensureGithubReleaseExistsAndUpdateChangelogFn;

beforeEach(function () {
Expand All @@ -58,7 +60,9 @@ describe('draft', function () {
githubRepo,
uploadArtifactToDownloadCenter,
downloadArtifactFromEvergreen,
ensureGithubReleaseExistsAndUpdateChangelog
ensureGithubReleaseExistsAndUpdateChangelog,
bumpMongoshReleasePackages,
bumpMongoshAuxiliaryPackages
);
});

Expand Down Expand Up @@ -102,7 +106,9 @@ describe('draft', function () {
githubRepo,
uploadArtifactToDownloadCenter,
downloadArtifactFromEvergreen,
ensureGithubReleaseExistsAndUpdateChangelog
ensureGithubReleaseExistsAndUpdateChangelog,
bumpMongoshReleasePackages,
bumpMongoshAuxiliaryPackages
);
expect(ensureGithubReleaseExistsAndUpdateChangelog).to.not.have.been
.called;
Expand All @@ -125,7 +131,9 @@ describe('draft', function () {
githubRepo,
uploadArtifactToDownloadCenter,
downloadArtifactFromEvergreen,
ensureGithubReleaseExistsAndUpdateChangelog
ensureGithubReleaseExistsAndUpdateChangelog,
bumpMongoshReleasePackages,
bumpMongoshAuxiliaryPackages
);
} catch (e: any) {
expect(e.message).to.contain('Missing package information from config');
Expand Down
14 changes: 12 additions & 2 deletions packages/build/src/run-draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import { downloadArtifactFromEvergreen as downloadArtifactFromEvergreenFn } from
import { generateChangelog as generateChangelogFn } from './git';
import type { GithubRepo } from '@mongodb-js/devtools-github-repo';
import { getPackageFile } from './packaging';
import {
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
} from './npm-packages/bump';

export async function runDraft(
config: Config,
githubRepo: GithubRepo,
uploadToDownloadCenter: typeof uploadArtifactToDownloadCenterFn = uploadArtifactToDownloadCenterFn,
downloadArtifactFromEvergreen: typeof downloadArtifactFromEvergreenFn = downloadArtifactFromEvergreenFn,
ensureGithubReleaseExistsAndUpdateChangelog: typeof ensureGithubReleaseExistsAndUpdateChangelogFn = ensureGithubReleaseExistsAndUpdateChangelogFn
ensureGithubReleaseExistsAndUpdateChangelog: typeof ensureGithubReleaseExistsAndUpdateChangelogFn = ensureGithubReleaseExistsAndUpdateChangelogFn,
bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn = bumpMongoshReleasePackagesFn,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am definitely getting rid of this structure of functions the moment I have a chance but for now... 😫

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, please feel very free to create a ticket for this 🙂

bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn
): Promise<void> {
const { triggeringGitTag } = config;
if (!triggeringGitTag || !getReleaseVersionFromTag(triggeringGitTag)) {
const draftReleaseVersion = getReleaseVersionFromTag(triggeringGitTag);
if (!triggeringGitTag || !draftReleaseVersion) {
console.error(
'mongosh: skipping draft as not triggered by a git tag that matches a draft/release tag'
);
Expand Down Expand Up @@ -44,6 +51,9 @@ export async function runDraft(
);
await fs.mkdir(tmpDir, { recursive: true });

bumpAuxiliaryPackages();
await bumpMongoshReleasePackages(draftReleaseVersion);

for await (const variant of ALL_PACKAGE_VARIANTS) {
const tarballFile = getPackageFile(variant, config.packageInformation);
console.info(
Expand Down