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
17 changes: 17 additions & 0 deletions packages/build/src/npm-packages/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {

import { promises as fs } from 'fs';
import path from 'path';
import { spawnSync as spawnSyncFn } from '../helpers';
import { getPackagesInTopologicalOrder } from '@mongodb-js/monorepo-tools';

/** Bumps only the main mongosh release packages to the set version. */
Expand Down Expand Up @@ -105,3 +106,19 @@ export function bumpAuxiliaryPackages() {
},
});
}

export function commitBumpedPackages(
spawnSync: typeof spawnSyncFn = spawnSyncFn
) {
spawnSync('git', ['add', '.'], {
stdio: 'inherit',
cwd: PROJECT_ROOT,
encoding: 'utf8',
});

spawnSync('git', ['commit', '-m', 'chore(release): bump packages'], {
stdio: 'inherit',
cwd: PROJECT_ROOT,
encoding: 'utf8',
});
}
44 changes: 1 addition & 43 deletions packages/build/src/npm-packages/publish.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { publishToNpm } from './publish';

describe('npm-packages publishToNpm', function () {
let listNpmPackages: SinonStub;
let markBumpedFilesAsAssumeUnchanged: SinonStub;
let spawnSync: SinonStub;
const lernaBin = path.resolve(
__dirname,
Expand All @@ -21,7 +20,6 @@ describe('npm-packages publishToNpm', function () {

beforeEach(function () {
listNpmPackages = sinon.stub();
markBumpedFilesAsAssumeUnchanged = sinon.stub();
spawnSync = sinon.stub();
});

Expand All @@ -32,17 +30,8 @@ describe('npm-packages publishToNpm', function () {
];
listNpmPackages.returns(packages);

publishToNpm(
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
listNpmPackages,
markBumpedFilesAsAssumeUnchanged,
spawnSync
);
publishToNpm({ isDryRun: false }, listNpmPackages);

expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
packages,
true
);
expect(spawnSync).to.have.been.calledWith(
lernaBin,
[
Expand All @@ -56,36 +45,5 @@ describe('npm-packages publishToNpm', function () {
],
sinon.match.any
);
expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
packages,
false
);
});

it('reverts the assume unchanged even on spawn failure', function () {
const packages = [{ name: 'packageA', version: '0.7.0' }];
listNpmPackages.returns(packages);
spawnSync.throws(new Error('meeep'));

try {
publishToNpm(
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
listNpmPackages,
markBumpedFilesAsAssumeUnchanged,
spawnSync
);
} catch (e: any) {
expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
packages,
true
);
expect(spawnSync).to.have.been.called;
expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
packages,
false
);
return;
}
expect.fail('Expected error');
});
});
53 changes: 15 additions & 38 deletions packages/build/src/npm-packages/publish.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
import path from 'path';
import {
EXCLUDE_RELEASE_PACKAGES,
LERNA_BIN,
MONGOSH_RELEASE_PACKAGES,
PROJECT_ROOT,
} from './constants';
import { LERNA_BIN, PROJECT_ROOT } from './constants';
import type { LernaPackageDescription } from './list';
import { listNpmPackages as listNpmPackagesFn } from './list';
import { spawnSync as spawnSyncFn } from '../helpers/spawn-sync';
import type { SpawnSyncOptionsWithStringEncoding } from 'child_process';

export function publishToNpm(
{ isDryRun = false, useAuxiliaryPackagesOnly = false },
listNpmPackages: typeof listNpmPackagesFn = listNpmPackagesFn,
markBumpedFilesAsAssumeUnchangedFn: typeof markBumpedFilesAsAssumeUnchanged = markBumpedFilesAsAssumeUnchanged,
{ isDryRun = false },
spawnSync: typeof spawnSyncFn = spawnSyncFn
): void {
const commandOptions: SpawnSyncOptionsWithStringEncoding = {
Expand All @@ -25,37 +17,22 @@ export function publishToNpm(
...(isDryRun ? { npm_config_dry_run: 'true' } : {}),
},
};
const allReleasablePackages = listNpmPackages().filter(
(packageConfig) => !EXCLUDE_RELEASE_PACKAGES.includes(packageConfig.name)
);

const packages: LernaPackageDescription[] = useAuxiliaryPackagesOnly
? allReleasablePackages.filter(
(packageConfig) =>
!MONGOSH_RELEASE_PACKAGES.includes(packageConfig.name)
)
: allReleasablePackages;

// Lerna requires a clean repository for a publish from-package
// we use git update-index --assume-unchanged on files we know have been bumped
markBumpedFilesAsAssumeUnchangedFn(packages, true);
try {
spawnSync(
LERNA_BIN,
[
'publish',
'from-package',
'--no-private',
'--no-changelog',
'--exact',
'--yes',
'--no-verify-access',
],
commandOptions
);
} finally {
markBumpedFilesAsAssumeUnchangedFn(packages, false);
}
spawnSync(
LERNA_BIN,
[
'publish',
'from-package',
'--no-private',
'--no-changelog',
'--exact',
'--yes',
'--no-verify-access',
],
commandOptions
);
}

export function markBumpedFilesAsAssumeUnchanged(
Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/npm-packages/push-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export function pushTags(
}

if (!isDryRun) {
spawnSync('git', ['push', '--follow-tags'], commandOptions);
spawnSync('git', ['push', '--tags'], commandOptions);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/build/src/publish-auxiliary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export function publishAuxiliaryPackages(config: Config) {
'This should only be used when publishing auxiliary packages'
);
}
publishToNpm(config);
pushTags({
useAuxiliaryPackagesOnly: true,
isDryRun: config.isDryRun || false,
});
publishToNpm(config);
}
38 changes: 26 additions & 12 deletions packages/build/src/publish-mongosh.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('publishMongosh', function () {
let barque: Barque;
let pushTags: typeof pushTagsType;
const getEvergreenArtifactUrl = getArtifactUrl;
let spawnSync: sinon.SinonStub;

beforeEach(function () {
config = { ...dummyConfig };
Expand All @@ -61,6 +62,7 @@ describe('publishMongosh', function () {
pushTags = sinon.spy();
bumpMongoshReleasePackages = sinon.spy();
bumpAuxiliaryPackages = sinon.spy();
spawnSync = sinon.stub().resolves();

githubRepo = createStubRepo();
mongoHomebrewCoreForkRepo = createStubRepo();
Expand Down Expand Up @@ -108,7 +110,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);
} catch (e: any) {
return expect(e.message).to.contain('Could not find prior draft tag');
Expand Down Expand Up @@ -137,7 +140,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);
} catch (e: any) {
return expect(e.message).to.contain('Version mismatch');
Expand All @@ -161,7 +165,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(barque.releaseToBarque).to.have.been.callCount(26);
Expand Down Expand Up @@ -195,7 +200,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(createAndPublishDownloadCenterConfig).to.have.been.calledWith(
Expand All @@ -221,7 +227,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(githubRepo.promoteRelease).to.have.been.calledWith(config);
Expand All @@ -242,7 +249,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(writeBuildInfo).to.have.been.calledOnceWith(config);
Expand All @@ -264,7 +272,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(publishToHomebrew).to.have.been.calledWith(
Expand Down Expand Up @@ -298,7 +307,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(createAndPublishDownloadCenterConfig).not.to.have.been.called;
Expand All @@ -319,7 +329,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(githubRepo.promoteRelease).not.to.have.been.called;
Expand All @@ -340,7 +351,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(publishToNpm).not.to.have.been.called;
Expand All @@ -361,7 +373,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(publishToHomebrew).not.to.have.been.called;
Expand All @@ -382,7 +395,8 @@ describe('publishMongosh', function () {
shouldDoPublicRelease,
getEvergreenArtifactUrl,
bumpMongoshReleasePackages,
bumpAuxiliaryPackages
bumpAuxiliaryPackages,
spawnSync
);

expect(barque.releaseToBarque).not.to.have.been.called;
Expand Down
16 changes: 9 additions & 7 deletions packages/build/src/publish-mongosh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
} from './npm-packages';
import { commitBumpedPackages } from './npm-packages/bump';
import { spawnSync as spawnSyncFn } from './helpers';

export async function publishMongosh(
config: Config,
Expand All @@ -33,7 +35,8 @@ export async function publishMongosh(
shouldDoPublicRelease: typeof shouldDoPublicReleaseFn = shouldDoPublicReleaseFn,
getEvergreenArtifactUrl: typeof getArtifactUrlFn = getArtifactUrlFn,
bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn = bumpMongoshReleasePackagesFn,
bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn
bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn,
spawnSync: typeof spawnSyncFn = spawnSyncFn
Copy link
Contributor Author

@gagik gagik Feb 4, 2025

Choose a reason for hiding this comment

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

def creating the ticket for this helper mess now 😭

): Promise<void> {
if (!shouldDoPublicRelease(config)) {
console.warn(
Expand Down Expand Up @@ -67,6 +70,11 @@ export async function publishMongosh(

bumpAuxiliaryPackages();
await bumpMongoshReleasePackages(releaseVersion);
commitBumpedPackages(spawnSync);
pushTags({
useAuxiliaryPackagesOnly: false,
isDryRun: config.isDryRun || false,
});

await publishArtifactsToBarque(
barque,
Expand Down Expand Up @@ -94,7 +102,6 @@ export async function publishMongosh(

publishToNpm({
isDryRun: config.isDryRun,
useAuxiliaryPackagesOnly: config.useAuxiliaryPackagesOnly,
});

await publishToHomebrew(
Expand All @@ -105,11 +112,6 @@ export async function publishMongosh(
!!config.isDryRun
);

pushTags({
useAuxiliaryPackagesOnly: false,
isDryRun: config.isDryRun || false,
});

console.info('mongosh: finished release process.');
}

Expand Down