Skip to content

Commit e83f504

Browse files
authored
fix(ci): add publishing tags step when publishing auxiliary packages MONGOSH-1871 (#2332)
lerna publish doesn't automatically push tags when using from-package so we have to create and push the tags manually.
1 parent 7f9449e commit e83f504

16 files changed

+404
-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
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Temporary workflow just to fix currently not pushed tags for our release, will be removed.
2+
name: Push Tags for Auxiliary Packages
3+
on:
4+
workflow_dispatch:
5+
6+
permissions:
7+
contents: none # We use the github app to checkout and push tags
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
environment: Production
13+
14+
steps:
15+
- uses: mongodb-js/devtools-shared/actions/setup-bot-token@d638357cabd624ae626d9abb62cbac2760aea932
16+
id: app-token
17+
with:
18+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
19+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
20+
21+
- uses: actions/checkout@v4
22+
with:
23+
# don't checkout a detatched HEAD
24+
ref: ${{ github.head_ref }}
25+
26+
# this is important so git log can pick up on
27+
# the whole history to generate the list of AUTHORS
28+
fetch-depth: "0"
29+
token: ${{ steps.app-token.outputs.token }}
30+
31+
- name: "Use Node.js 20"
32+
uses: actions/setup-node@v4
33+
with:
34+
node-version: 20.16.0
35+
36+
- name: Install [email protected]
37+
run: npm install -g [email protected]
38+
39+
- name: Install Dependencies
40+
run: |
41+
npm ci
42+
43+
- name: "Pushing tags..."
44+
env:
45+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
46+
run: |
47+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
48+
npm config list
49+
npm run tags-auxiliary

.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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"precommit": "precommit",
7373
"preinstall": "node scripts/sort-workspaces.js",
7474
"bump-auxiliary": "npm run bump-auxiliary --workspace @mongosh/build",
75-
"publish-auxiliary": "npm run publish-auxiliary --workspace @mongosh/build"
75+
"publish-auxiliary": "npm run publish-auxiliary --workspace @mongosh/build",
76+
"tags-auxiliary": "npm run tags-auxiliary --workspace @mongosh/build"
7677
},
7778
"config": {
7879
"unsafe-perm": true

packages/build/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"publish": "ts-node src/index.ts publish",
3131
"bump-auxiliary": "ts-node src/index.ts bump --auxiliary",
3232
"publish-auxiliary": "ts-node src/index.ts publish --auxiliary",
33+
"tags-auxiliary": "ts-node src/index.ts temp-push-auxiliary-tags --auxiliary",
3334
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
3435
},
3536
"license": "Apache-2.0",

packages/build/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const validCommands: (ReleaseCommand | 'trigger-release')[] = [
2020
'download-crypt-shared-library',
2121
'download-and-list-artifacts',
2222
'trigger-release',
23+
'temp-push-auxiliary-tags',
2324
] as const;
2425

2526
const isValidCommand = (
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(

0 commit comments

Comments
 (0)