Skip to content

Commit e80c901

Browse files
committed
Merge remote-tracking branch 'origin/main' into MONGOSH-1989-custom-log-entries
2 parents 684e216 + b9bdee8 commit e80c901

File tree

13 files changed

+346
-88
lines changed

13 files changed

+346
-88
lines changed

.github/workflows/bump-auxiliary-packages.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
1818
- uses: actions/checkout@v4
1919
with:
20-
# don't checkout a detatched HEAD
20+
# don't checkout a detached HEAD
2121
ref: ${{ github.head_ref }}
2222

2323
# this is important so git log can pick up on

.github/workflows/cron-tasks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828

2929
- uses: actions/checkout@v4
3030
with:
31-
# don't checkout a detatched HEAD
31+
# don't checkout a detached HEAD
3232
ref: ${{ github.head_ref }}
3333

3434
# this is important so git log can pick up on

.github/workflows/update-node-js.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222

2323
- uses: actions/checkout@v4
2424
with:
25-
# don't checkout a detatched HEAD
25+
# don't checkout a detached HEAD
2626
ref: ${{ github.head_ref }}
2727
token: ${{ steps.app-token.outputs.token }}
2828

THIRD_PARTY_NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **mongosh**.
2-
This document was automatically generated on Mon Jan 27 2025.
2+
This document was automatically generated on Tue Jan 28 2025.
33

44
## List of dependencies
55

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { bumpAuxiliaryPackages } from './bump';
22
export { publishToNpm } from './publish';
3+
export { pushTags } from './push-tags';

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

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -25,62 +25,6 @@ describe('npm-packages publishToNpm', function () {
2525
spawnSync = sinon.stub();
2626
});
2727

28-
it('throws if mongosh is not existent when publishing all', function () {
29-
const packages = [{ name: 'packageA', version: '0.7.0' }];
30-
listNpmPackages.returns(packages);
31-
32-
expect(() =>
33-
publishToNpm(
34-
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
35-
listNpmPackages,
36-
markBumpedFilesAsAssumeUnchanged,
37-
spawnSync
38-
)
39-
).throws('mongosh package not found');
40-
});
41-
42-
it('takes mongosh version and pushes tags', function () {
43-
const packages = [
44-
{ name: 'packageA', version: '0.7.0' },
45-
{ name: 'mongosh', version: '1.2.0' },
46-
];
47-
listNpmPackages.returns(packages);
48-
49-
publishToNpm(
50-
{ isDryRun: false, useAuxiliaryPackagesOnly: false },
51-
listNpmPackages,
52-
markBumpedFilesAsAssumeUnchanged,
53-
spawnSync
54-
);
55-
56-
expect(spawnSync).calledWith('git', ['tag', '-a', '1.2.0', '-m', '1.2.0']);
57-
expect(spawnSync).calledWith('git', ['push', '--follow-tags']);
58-
});
59-
60-
it('does not manually push tags with auxiliary packages', function () {
61-
const packages = [
62-
{ name: 'packageA', version: '0.7.0' },
63-
{ name: 'mongosh', version: '1.2.0' },
64-
];
65-
listNpmPackages.returns(packages);
66-
67-
publishToNpm(
68-
{ isDryRun: false, useAuxiliaryPackagesOnly: true },
69-
listNpmPackages,
70-
markBumpedFilesAsAssumeUnchanged,
71-
spawnSync
72-
);
73-
74-
expect(spawnSync).not.calledWith('git', [
75-
'tag',
76-
'-a',
77-
'1.2.0',
78-
'-m',
79-
'1.2.0',
80-
]);
81-
expect(spawnSync).not.calledWith('git', ['push', '--follow-tags']);
82-
});
83-
8428
it('calls lerna to publish packages for a real version', function () {
8529
const packages = [
8630
{ name: 'packageA', version: '0.7.0' },

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

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,17 @@ export function publishToNpm(
2525
...(isDryRun ? { npm_config_dry_run: 'true' } : {}),
2626
},
2727
};
28-
let packages = listNpmPackages().filter(
28+
const allReleasablePackages = listNpmPackages().filter(
2929
(packageConfig) => !EXCLUDE_RELEASE_PACKAGES.includes(packageConfig.name)
3030
);
3131

32-
if (useAuxiliaryPackagesOnly) {
33-
packages = packages.filter(
34-
(packageConfig) => !MONGOSH_RELEASE_PACKAGES.includes(packageConfig.name)
35-
);
36-
}
32+
const packages: LernaPackageDescription[] = useAuxiliaryPackagesOnly
33+
? allReleasablePackages.filter(
34+
(packageConfig) =>
35+
!MONGOSH_RELEASE_PACKAGES.includes(packageConfig.name)
36+
)
37+
: allReleasablePackages;
38+
3739
// Lerna requires a clean repository for a publish from-package
3840
// we use git update-index --assume-unchanged on files we know have been bumped
3941
markBumpedFilesAsAssumeUnchangedFn(packages, true);
@@ -54,24 +56,6 @@ export function publishToNpm(
5456
} finally {
5557
markBumpedFilesAsAssumeUnchangedFn(packages, false);
5658
}
57-
58-
if (!useAuxiliaryPackagesOnly) {
59-
const mongoshVersion = packages.find(
60-
(packageConfig) => packageConfig.name === 'mongosh'
61-
)?.version;
62-
63-
if (!mongoshVersion) {
64-
throw new Error('mongosh package not found');
65-
}
66-
67-
spawnSync(
68-
'git',
69-
['tag', '-a', mongoshVersion, '-m', mongoshVersion],
70-
commandOptions
71-
);
72-
73-
spawnSync('git', ['push', '--follow-tags'], commandOptions);
74-
}
7559
}
7660

7761
export function markBumpedFilesAsAssumeUnchanged(
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
import { expect } from 'chai';
2+
import { existsTag, pushTags } from './push-tags';
3+
import sinon from 'sinon';
4+
import { MONGOSH_RELEASE_PACKAGES } from './constants';
5+
6+
describe('pushing tags', function () {
7+
let spawnSync: sinon.SinonStub;
8+
let listNpmPackages: sinon.SinonStub;
9+
10+
describe('existsTag', function () {
11+
it('returns true with existing tags', function () {
12+
expect(existsTag('v1.0.0')).equals(true);
13+
});
14+
15+
it('return false with tags that do not exist', function () {
16+
expect(existsTag('this-tag-will-never-exist-12345')).equals(false);
17+
});
18+
});
19+
20+
describe('pushTags', function () {
21+
const mongoshVersion = '1.2.0';
22+
const allReleasablePackages = [
23+
{ name: 'packageA', version: '0.7.0' },
24+
{ name: 'packageB', version: '1.7.0' },
25+
{ name: 'packageC', version: '1.3.0' },
26+
{ name: 'mongosh', version: mongoshVersion },
27+
{ name: '@mongosh/cli-repl', version: mongoshVersion },
28+
];
29+
const auxiliaryPackages = allReleasablePackages.filter(
30+
(p) => !MONGOSH_RELEASE_PACKAGES.includes(p.name)
31+
);
32+
const mongoshReleasePackages = allReleasablePackages.filter((p) =>
33+
MONGOSH_RELEASE_PACKAGES.includes(p.name)
34+
);
35+
let existsVersionTag: sinon.SinonStub;
36+
37+
beforeEach(function () {
38+
spawnSync = sinon.stub();
39+
spawnSync.returns(undefined);
40+
41+
listNpmPackages = sinon.stub();
42+
listNpmPackages.returns(allReleasablePackages);
43+
existsVersionTag = sinon.stub();
44+
existsVersionTag.returns(false);
45+
});
46+
47+
afterEach(function () {
48+
sinon.restore();
49+
});
50+
51+
it('throws if mongosh is not existent when publishing all', function () {
52+
const packages = [{ name: 'packageA', version: '0.7.0' }];
53+
listNpmPackages.returns(packages);
54+
55+
expect(() =>
56+
pushTags(
57+
{ useAuxiliaryPackagesOnly: false },
58+
listNpmPackages,
59+
existsVersionTag,
60+
spawnSync
61+
)
62+
).throws('mongosh package not found');
63+
});
64+
65+
it('takes mongosh version and pushes tags when releasing', function () {
66+
pushTags(
67+
{
68+
useAuxiliaryPackagesOnly: false,
69+
},
70+
listNpmPackages,
71+
existsVersionTag,
72+
spawnSync
73+
);
74+
75+
for (const packageInfo of allReleasablePackages) {
76+
expect(spawnSync).calledWith('git', [
77+
'tag',
78+
'-a',
79+
`${packageInfo.name}@${packageInfo.version}`,
80+
'-m',
81+
`${packageInfo.name}@${packageInfo.version}`,
82+
]);
83+
}
84+
85+
expect(spawnSync).calledWith('git', [
86+
'tag',
87+
'-a',
88+
`v${mongoshVersion}`,
89+
'-m',
90+
`v${mongoshVersion}`,
91+
]);
92+
expect(spawnSync).calledWith('git', ['push', '--follow-tags']);
93+
});
94+
95+
it('pushes only package tags when using auxiliary packages', function () {
96+
pushTags(
97+
{
98+
useAuxiliaryPackagesOnly: true,
99+
},
100+
listNpmPackages,
101+
existsVersionTag,
102+
spawnSync
103+
);
104+
105+
for (const packageInfo of auxiliaryPackages) {
106+
expect(spawnSync).calledWith('git', [
107+
'tag',
108+
'-a',
109+
`${packageInfo.name}@${packageInfo.version}`,
110+
'-m',
111+
`${packageInfo.name}@${packageInfo.version}`,
112+
]);
113+
}
114+
115+
for (const packageInfo of mongoshReleasePackages) {
116+
expect(spawnSync).not.calledWith('git', [
117+
'tag',
118+
'-a',
119+
`${packageInfo.name}@${packageInfo.version}`,
120+
'-m',
121+
`${packageInfo.name}@${packageInfo.version}`,
122+
]);
123+
}
124+
125+
expect(spawnSync).not.calledWith('git', [
126+
'tag',
127+
'-a',
128+
`v${mongoshVersion}`,
129+
'-m',
130+
`v${mongoshVersion}`,
131+
]);
132+
expect(spawnSync).calledWith('git', ['push', '--follow-tags']);
133+
});
134+
135+
it('skips pushing version tags which already exist', function () {
136+
const packagesToSkip = [
137+
allReleasablePackages[0],
138+
allReleasablePackages[1],
139+
];
140+
141+
for (const packageInfo of packagesToSkip) {
142+
existsVersionTag
143+
.withArgs(`${packageInfo.name}@${packageInfo.version}`)
144+
.returns(true);
145+
}
146+
147+
pushTags(
148+
{
149+
useAuxiliaryPackagesOnly: true,
150+
},
151+
listNpmPackages,
152+
existsVersionTag,
153+
spawnSync
154+
);
155+
156+
for (const packageInfo of auxiliaryPackages.filter(
157+
(p) => !packagesToSkip.includes(p)
158+
)) {
159+
expect(spawnSync).calledWith('git', [
160+
'tag',
161+
'-a',
162+
`${packageInfo.name}@${packageInfo.version}`,
163+
'-m',
164+
`${packageInfo.name}@${packageInfo.version}`,
165+
]);
166+
}
167+
168+
for (const packageInfo of [
169+
...mongoshReleasePackages,
170+
...packagesToSkip,
171+
]) {
172+
expect(spawnSync).not.calledWith('git', [
173+
'tag',
174+
'-a',
175+
`${packageInfo.name}@${packageInfo.version}`,
176+
'-m',
177+
`${packageInfo.name}@${packageInfo.version}`,
178+
]);
179+
}
180+
181+
expect(spawnSync).not.calledWith('git', [
182+
'tag',
183+
'-a',
184+
`v${mongoshVersion}`,
185+
'-m',
186+
`v${mongoshVersion}`,
187+
]);
188+
expect(spawnSync).calledWith('git', ['push', '--follow-tags']);
189+
});
190+
191+
it('skips mongosh release tag push if it exists', function () {
192+
existsVersionTag.withArgs(`v${mongoshVersion}`).returns(true);
193+
194+
pushTags(
195+
{
196+
useAuxiliaryPackagesOnly: false,
197+
},
198+
listNpmPackages,
199+
existsVersionTag,
200+
spawnSync
201+
);
202+
203+
expect(spawnSync).not.calledWith('git', [
204+
'tag',
205+
'-a',
206+
`v${mongoshVersion}`,
207+
'-m',
208+
`v${mongoshVersion}`,
209+
]);
210+
expect(spawnSync).calledWith('git', ['push', '--follow-tags']);
211+
});
212+
});
213+
});

0 commit comments

Comments
 (0)