Skip to content

Commit 4d248d5

Browse files
authored
fix(ci): commit changes from bumping packages (#2352)
1 parent 097c141 commit 4d248d5

File tree

7 files changed

+70
-102
lines changed

7 files changed

+70
-102
lines changed

packages/build/src/npm-packages/bump.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77

88
import { promises as fs } from 'fs';
99
import path from 'path';
10+
import { spawnSync as spawnSyncFn } from '../helpers';
1011
import { getPackagesInTopologicalOrder } from '@mongodb-js/monorepo-tools';
1112

1213
/** Bumps only the main mongosh release packages to the set version. */
@@ -105,3 +106,19 @@ export function bumpAuxiliaryPackages() {
105106
},
106107
});
107108
}
109+
110+
export function commitBumpedPackages(
111+
spawnSync: typeof spawnSyncFn = spawnSyncFn
112+
) {
113+
spawnSync('git', ['add', '.'], {
114+
stdio: 'inherit',
115+
cwd: PROJECT_ROOT,
116+
encoding: 'utf8',
117+
});
118+
119+
spawnSync('git', ['commit', '-m', 'chore(release): bump packages'], {
120+
stdio: 'inherit',
121+
cwd: PROJECT_ROOT,
122+
encoding: 'utf8',
123+
});
124+
}

packages/build/src/npm-packages/publish.spec.ts

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { publishToNpm } from './publish';
66

77
describe('npm-packages publishToNpm', function () {
88
let listNpmPackages: SinonStub;
9-
let markBumpedFilesAsAssumeUnchanged: SinonStub;
109
let spawnSync: SinonStub;
1110
const lernaBin = path.resolve(
1211
__dirname,
@@ -21,7 +20,6 @@ describe('npm-packages publishToNpm', function () {
2120

2221
beforeEach(function () {
2322
listNpmPackages = sinon.stub();
24-
markBumpedFilesAsAssumeUnchanged = sinon.stub();
2523
spawnSync = sinon.stub();
2624
});
2725

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

35-
publishToNpm(
36-
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
37-
listNpmPackages,
38-
markBumpedFilesAsAssumeUnchanged,
39-
spawnSync
40-
);
33+
publishToNpm({ isDryRun: false }, listNpmPackages);
4134

42-
expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
43-
packages,
44-
true
45-
);
4635
expect(spawnSync).to.have.been.calledWith(
4736
lernaBin,
4837
[
@@ -56,36 +45,5 @@ describe('npm-packages publishToNpm', function () {
5645
],
5746
sinon.match.any
5847
);
59-
expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
60-
packages,
61-
false
62-
);
63-
});
64-
65-
it('reverts the assume unchanged even on spawn failure', function () {
66-
const packages = [{ name: 'packageA', version: '0.7.0' }];
67-
listNpmPackages.returns(packages);
68-
spawnSync.throws(new Error('meeep'));
69-
70-
try {
71-
publishToNpm(
72-
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
73-
listNpmPackages,
74-
markBumpedFilesAsAssumeUnchanged,
75-
spawnSync
76-
);
77-
} catch (e: any) {
78-
expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
79-
packages,
80-
true
81-
);
82-
expect(spawnSync).to.have.been.called;
83-
expect(markBumpedFilesAsAssumeUnchanged).to.have.been.calledWith(
84-
packages,
85-
false
86-
);
87-
return;
88-
}
89-
expect.fail('Expected error');
9048
});
9149
});

packages/build/src/npm-packages/publish.ts

Lines changed: 15 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
import path from 'path';
2-
import {
3-
EXCLUDE_RELEASE_PACKAGES,
4-
LERNA_BIN,
5-
MONGOSH_RELEASE_PACKAGES,
6-
PROJECT_ROOT,
7-
} from './constants';
2+
import { LERNA_BIN, PROJECT_ROOT } from './constants';
83
import type { LernaPackageDescription } from './list';
9-
import { listNpmPackages as listNpmPackagesFn } from './list';
104
import { spawnSync as spawnSyncFn } from '../helpers/spawn-sync';
115
import type { SpawnSyncOptionsWithStringEncoding } from 'child_process';
126

137
export function publishToNpm(
14-
{ isDryRun = false, useAuxiliaryPackagesOnly = false },
15-
listNpmPackages: typeof listNpmPackagesFn = listNpmPackagesFn,
16-
markBumpedFilesAsAssumeUnchangedFn: typeof markBumpedFilesAsAssumeUnchanged = markBumpedFilesAsAssumeUnchanged,
8+
{ isDryRun = false },
179
spawnSync: typeof spawnSyncFn = spawnSyncFn
1810
): void {
1911
const commandOptions: SpawnSyncOptionsWithStringEncoding = {
@@ -25,37 +17,22 @@ export function publishToNpm(
2517
...(isDryRun ? { npm_config_dry_run: 'true' } : {}),
2618
},
2719
};
28-
const allReleasablePackages = listNpmPackages().filter(
29-
(packageConfig) => !EXCLUDE_RELEASE_PACKAGES.includes(packageConfig.name)
30-
);
31-
32-
const packages: LernaPackageDescription[] = useAuxiliaryPackagesOnly
33-
? allReleasablePackages.filter(
34-
(packageConfig) =>
35-
!MONGOSH_RELEASE_PACKAGES.includes(packageConfig.name)
36-
)
37-
: allReleasablePackages;
3820

3921
// Lerna requires a clean repository for a publish from-package
4022
// we use git update-index --assume-unchanged on files we know have been bumped
41-
markBumpedFilesAsAssumeUnchangedFn(packages, true);
42-
try {
43-
spawnSync(
44-
LERNA_BIN,
45-
[
46-
'publish',
47-
'from-package',
48-
'--no-private',
49-
'--no-changelog',
50-
'--exact',
51-
'--yes',
52-
'--no-verify-access',
53-
],
54-
commandOptions
55-
);
56-
} finally {
57-
markBumpedFilesAsAssumeUnchangedFn(packages, false);
58-
}
23+
spawnSync(
24+
LERNA_BIN,
25+
[
26+
'publish',
27+
'from-package',
28+
'--no-private',
29+
'--no-changelog',
30+
'--exact',
31+
'--yes',
32+
'--no-verify-access',
33+
],
34+
commandOptions
35+
);
5936
}
6037

6138
export function markBumpedFilesAsAssumeUnchanged(

packages/build/src/npm-packages/push-tags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function pushTags(
7272
}
7373

7474
if (!isDryRun) {
75-
spawnSync('git', ['push', '--follow-tags'], commandOptions);
75+
spawnSync('git', ['push', '--tags'], commandOptions);
7676
}
7777
}
7878

packages/build/src/publish-auxiliary.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export function publishAuxiliaryPackages(config: Config) {
77
'This should only be used when publishing auxiliary packages'
88
);
99
}
10-
publishToNpm(config);
1110
pushTags({
1211
useAuxiliaryPackagesOnly: true,
1312
isDryRun: config.isDryRun || false,
1413
});
14+
publishToNpm(config);
1515
}

packages/build/src/publish-mongosh.spec.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ describe('publishMongosh', function () {
4949
let barque: Barque;
5050
let pushTags: typeof pushTagsType;
5151
const getEvergreenArtifactUrl = getArtifactUrl;
52+
let spawnSync: sinon.SinonStub;
5253

5354
beforeEach(function () {
5455
config = { ...dummyConfig };
@@ -61,6 +62,7 @@ describe('publishMongosh', function () {
6162
pushTags = sinon.spy();
6263
bumpMongoshReleasePackages = sinon.spy();
6364
bumpAuxiliaryPackages = sinon.spy();
65+
spawnSync = sinon.stub().resolves();
6466

6567
githubRepo = createStubRepo();
6668
mongoHomebrewCoreForkRepo = createStubRepo();
@@ -108,7 +110,8 @@ describe('publishMongosh', function () {
108110
shouldDoPublicRelease,
109111
getEvergreenArtifactUrl,
110112
bumpMongoshReleasePackages,
111-
bumpAuxiliaryPackages
113+
bumpAuxiliaryPackages,
114+
spawnSync
112115
);
113116
} catch (e: any) {
114117
return expect(e.message).to.contain('Could not find prior draft tag');
@@ -137,7 +140,8 @@ describe('publishMongosh', function () {
137140
shouldDoPublicRelease,
138141
getEvergreenArtifactUrl,
139142
bumpMongoshReleasePackages,
140-
bumpAuxiliaryPackages
143+
bumpAuxiliaryPackages,
144+
spawnSync
141145
);
142146
} catch (e: any) {
143147
return expect(e.message).to.contain('Version mismatch');
@@ -161,7 +165,8 @@ describe('publishMongosh', function () {
161165
shouldDoPublicRelease,
162166
getEvergreenArtifactUrl,
163167
bumpMongoshReleasePackages,
164-
bumpAuxiliaryPackages
168+
bumpAuxiliaryPackages,
169+
spawnSync
165170
);
166171

167172
expect(barque.releaseToBarque).to.have.been.callCount(26);
@@ -195,7 +200,8 @@ describe('publishMongosh', function () {
195200
shouldDoPublicRelease,
196201
getEvergreenArtifactUrl,
197202
bumpMongoshReleasePackages,
198-
bumpAuxiliaryPackages
203+
bumpAuxiliaryPackages,
204+
spawnSync
199205
);
200206

201207
expect(createAndPublishDownloadCenterConfig).to.have.been.calledWith(
@@ -221,7 +227,8 @@ describe('publishMongosh', function () {
221227
shouldDoPublicRelease,
222228
getEvergreenArtifactUrl,
223229
bumpMongoshReleasePackages,
224-
bumpAuxiliaryPackages
230+
bumpAuxiliaryPackages,
231+
spawnSync
225232
);
226233

227234
expect(githubRepo.promoteRelease).to.have.been.calledWith(config);
@@ -242,7 +249,8 @@ describe('publishMongosh', function () {
242249
shouldDoPublicRelease,
243250
getEvergreenArtifactUrl,
244251
bumpMongoshReleasePackages,
245-
bumpAuxiliaryPackages
252+
bumpAuxiliaryPackages,
253+
spawnSync
246254
);
247255

248256
expect(writeBuildInfo).to.have.been.calledOnceWith(config);
@@ -264,7 +272,8 @@ describe('publishMongosh', function () {
264272
shouldDoPublicRelease,
265273
getEvergreenArtifactUrl,
266274
bumpMongoshReleasePackages,
267-
bumpAuxiliaryPackages
275+
bumpAuxiliaryPackages,
276+
spawnSync
268277
);
269278

270279
expect(publishToHomebrew).to.have.been.calledWith(
@@ -298,7 +307,8 @@ describe('publishMongosh', function () {
298307
shouldDoPublicRelease,
299308
getEvergreenArtifactUrl,
300309
bumpMongoshReleasePackages,
301-
bumpAuxiliaryPackages
310+
bumpAuxiliaryPackages,
311+
spawnSync
302312
);
303313

304314
expect(createAndPublishDownloadCenterConfig).not.to.have.been.called;
@@ -319,7 +329,8 @@ describe('publishMongosh', function () {
319329
shouldDoPublicRelease,
320330
getEvergreenArtifactUrl,
321331
bumpMongoshReleasePackages,
322-
bumpAuxiliaryPackages
332+
bumpAuxiliaryPackages,
333+
spawnSync
323334
);
324335

325336
expect(githubRepo.promoteRelease).not.to.have.been.called;
@@ -340,7 +351,8 @@ describe('publishMongosh', function () {
340351
shouldDoPublicRelease,
341352
getEvergreenArtifactUrl,
342353
bumpMongoshReleasePackages,
343-
bumpAuxiliaryPackages
354+
bumpAuxiliaryPackages,
355+
spawnSync
344356
);
345357

346358
expect(publishToNpm).not.to.have.been.called;
@@ -361,7 +373,8 @@ describe('publishMongosh', function () {
361373
shouldDoPublicRelease,
362374
getEvergreenArtifactUrl,
363375
bumpMongoshReleasePackages,
364-
bumpAuxiliaryPackages
376+
bumpAuxiliaryPackages,
377+
spawnSync
365378
);
366379

367380
expect(publishToHomebrew).not.to.have.been.called;
@@ -382,7 +395,8 @@ describe('publishMongosh', function () {
382395
shouldDoPublicRelease,
383396
getEvergreenArtifactUrl,
384397
bumpMongoshReleasePackages,
385-
bumpAuxiliaryPackages
398+
bumpAuxiliaryPackages,
399+
spawnSync
386400
);
387401

388402
expect(barque.releaseToBarque).not.to.have.been.called;

packages/build/src/publish-mongosh.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import {
1818
bumpMongoshReleasePackages as bumpMongoshReleasePackagesFn,
1919
bumpAuxiliaryPackages as bumpAuxiliaryPackagesFn,
2020
} from './npm-packages';
21+
import { commitBumpedPackages } from './npm-packages/bump';
22+
import { spawnSync as spawnSyncFn } from './helpers';
2123

2224
export async function publishMongosh(
2325
config: Config,
@@ -33,7 +35,8 @@ export async function publishMongosh(
3335
shouldDoPublicRelease: typeof shouldDoPublicReleaseFn = shouldDoPublicReleaseFn,
3436
getEvergreenArtifactUrl: typeof getArtifactUrlFn = getArtifactUrlFn,
3537
bumpMongoshReleasePackages: typeof bumpMongoshReleasePackagesFn = bumpMongoshReleasePackagesFn,
36-
bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn
38+
bumpAuxiliaryPackages: typeof bumpAuxiliaryPackagesFn = bumpAuxiliaryPackagesFn,
39+
spawnSync: typeof spawnSyncFn = spawnSyncFn
3740
): Promise<void> {
3841
if (!shouldDoPublicRelease(config)) {
3942
console.warn(
@@ -67,6 +70,11 @@ export async function publishMongosh(
6770

6871
bumpAuxiliaryPackages();
6972
await bumpMongoshReleasePackages(releaseVersion);
73+
commitBumpedPackages(spawnSync);
74+
pushTags({
75+
useAuxiliaryPackagesOnly: false,
76+
isDryRun: config.isDryRun || false,
77+
});
7078

7179
await publishArtifactsToBarque(
7280
barque,
@@ -94,7 +102,6 @@ export async function publishMongosh(
94102

95103
publishToNpm({
96104
isDryRun: config.isDryRun,
97-
useAuxiliaryPackagesOnly: config.useAuxiliaryPackagesOnly,
98105
});
99106

100107
await publishToHomebrew(
@@ -105,11 +112,6 @@ export async function publishMongosh(
105112
!!config.isDryRun
106113
);
107114

108-
pushTags({
109-
useAuxiliaryPackagesOnly: false,
110-
isDryRun: config.isDryRun || false,
111-
});
112-
113115
console.info('mongosh: finished release process.');
114116
}
115117

0 commit comments

Comments
 (0)