Skip to content

Commit fc05298

Browse files
committed
WIP: move parts of release to GitHub Actions
1 parent 07a28ac commit fc05298

15 files changed

+169
-62
lines changed

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Bump packages
1+
name: Bump auxiliary package versions
22
on:
33
workflow_dispatch:
44
push:
@@ -38,19 +38,19 @@ jobs:
3838
3939
- name: Bump packages
4040
env:
41-
LAST_BUMP_COMMIT_MESSAGE: "chore(release): bump package versions"
41+
LAST_BUMP_COMMIT_MESSAGE: "chore(release): bump auxiliary package versions"
4242
run: |
43-
npm run bump-packages
43+
npm run bump-auxiliary
4444
git add .
4545
git commit --no-allow-empty -m "$LAST_BUMP_COMMIT_MESSAGE" || true
4646
4747
- name: Create Pull Request
4848
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
4949
with:
5050
token: ${{ steps.app-token.outputs.token }}
51-
commit-message: "chore(release): bump package versions"
52-
branch: ci/bump-packages
53-
title: "chore(release): bump package versions"
51+
commit-message: "chore(release): bump auxiliary package versions"
52+
branch: ci/bump-auxiliary-packages
53+
title: "chore(release): bump auxiliary package versions"
5454
labels: no-title-validation
5555
body: |
5656
- Bump package versions

.github/workflows/draft-release.yml renamed to .github/workflows/prepare-release-mongosh.yml

+34-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
name: Draft release
1+
name: Prepare mongosh release
22

33
on:
44
workflow_dispatch:
55
inputs:
6+
jiraTicket:
7+
description: 'Jira ticket for the release, e.g. MONGOSH-1234'
8+
required: true
9+
610
versionBump:
711
description: 'Version bump'
812
type: choice
@@ -22,6 +26,13 @@ jobs:
2226
prepare-release:
2327
runs-on: ubuntu-latest
2428
steps:
29+
- name: Create Github App Token
30+
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
31+
id: app-token
32+
with:
33+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
34+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
35+
2536
- name: Checkout
2637
uses: actions/checkout@v4
2738
with:
@@ -36,8 +47,6 @@ jobs:
3647

3748
- name: Determine Next Version
3849
shell: bash
39-
env:
40-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4150
run: |
4251
set -e
4352
@@ -51,6 +60,9 @@ jobs:
5160
else
5261
NEXT_VERSION=${{ github.event.inputs.exactVersion }}
5362
fi
63+
64+
# Remove the 'v' prefix from NEXT_VERSION if it exists
65+
NEXT_VERSION="${NEXT_VERSION#v}"
5466
5567
# Validates the version before using it
5668
npx semver v"${NEXT_VERSION}"
@@ -74,21 +86,26 @@ jobs:
7486
fi
7587
7688
- name: Bump mongosh and package versions
89+
shell: bash
90+
env:
91+
LAST_BUMP_COMMIT_MESSAGE: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
7792
run: |
7893
set -e
79-
echo Bumping mongosh versions to ${RELEASE_TAG} and packages
80-
81-
MONGOSH_RELEASE_VERSION=${RELEASE_TAG} npm run bump
82-
83-
- name: Create Draft Release
84-
run: |
85-
set -e
86-
echo Creating draft release for: "${RELEASE_TAG}"
94+
echo Bumping mongosh versions to ${NEXT_VERSION} and packages
8795
88-
git tag ${RELEASE_TAG}
89-
git push origin ${RELEASE_TAG}
90-
91-
shell: bash
92-
env:
93-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
MONGOSH_RELEASE_VERSION=${NEXT_VERSION} npm run bump
97+
98+
git add .
99+
git commit --no-allow-empty -m "$LAST_BUMP_COMMIT_MESSAGE" || true
94100
101+
- name: Create Pull Request
102+
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
103+
with:
104+
token: ${{ steps.app-token.outputs.token }}
105+
commit-message: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
106+
branch: release/${NEXT_VERSION}
107+
title: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
108+
body: |
109+
- [${{ github.event.inputs.jiraTicket }}](https://jira.mongodb.org/browse/${{ github.event.inputs.jiraTicket }})
110+
- This PR is for the release of mongosh v${NEXT_VERSION}.
111+
- **Do not merge manually, use the Release mongosh action instead.**

.github/workflows/release-packages.yml renamed to .github/workflows/release-auxiliary-packages.yml

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Publish
1+
name: Publish Auxiliary Packages
22
on:
33
# NOTE: avoid using the manual execution unless is the only way to fix some issue,
44
# rather retry failed jobs in case of flakes. The manual execution can potentially
@@ -53,9 +53,3 @@ jobs:
5353
git update-index --assume-unchanged .npmrc
5454
npm run publish-packages
5555
56-
- name: "Publish tags"
57-
run: |
58-
npx lerna list -a --json | \
59-
jq -r '.[] | .name + "@" + .version' | \
60-
xargs -i sh -c "git tag -a {} -m {} || true"
61-
git push --follow-tags

.github/workflows/release-mongosh.yml

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Release mongosh
2+
on:
3+
workflow_run:
4+
workflows: ["CheckQL", "Run Smoke Tests", "evergreen"]
5+
types: ["completed"]
6+
branches: ["release/**"]
7+
workflow_dispatch:
8+
9+
jobs:
10+
publish:
11+
if: |
12+
startsWith(github.head_ref, 'refs/heads/release/')
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Create Github App Token
17+
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
18+
id: app-token
19+
with:
20+
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
21+
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}
22+
23+
- uses: actions/checkout@v4
24+
with:
25+
# don't checkout a detatched HEAD
26+
ref: ${{ github.head_ref }}
27+
28+
- name: Extract version from the branch
29+
run: |
30+
set -e
31+
export NEXT_VERSION=$(echo "${GITHUB_REF}" | sed -n 's/refs\/heads\/release\/\(.*\)/\1/p')
32+
33+
echo "NEXT_VERSION=${NEXT_VERSION}" >> "$GITHUB_ENV"
34+
echo "RELEASE_TAG=v${NEXT_VERSION}" >> "$GITHUB_ENV"
35+
36+
- name: Validate release tag
37+
shell: bash
38+
run: |
39+
if [ -z "${RELEASE_TAG}" ]; then
40+
echo "RELEASE_TAG is not set or is empty"
41+
exit 1
42+
fi
43+
44+
if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
45+
echo "Error: Tag $RELEASE_TAG already exists"
46+
echo "If you are trying to re-create a draft release with this version, please delete the release and the tag first."
47+
echo "If this version has already been released consider using a different one."
48+
exit 1
49+
fi
50+
51+
- name: "Publish what is not already in NPM"
52+
env:
53+
NPM_TOKEN: ${{ secrets.DEVTOOLSBOT_NPM_TOKEN }}
54+
run: |
55+
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
56+
npm config list
57+
echo "Publishing packages as $(npm whoami)"
58+
git update-index --assume-unchanged .npmrc
59+
npm run publish-packages

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@
7272
"precommit": "precommit",
7373
"preinstall": "node scripts/sort-workspaces.js",
7474
"bump": "npm run bump --workspace @mongosh/build",
75-
"bump-packages": "npm run bump-packages --workspace @mongosh/build",
76-
"publish-packages": "lerna publish from-package --no-verify-access --no-push --no-git-tag-version --yes"
75+
"publish": "npm run publish --workspace @mongosh/build",
76+
"bump-auxiliary": "npm run bump-auxiliary --workspace @mongosh/build",
77+
"publish-auxiliary": "npm run publish-auxiliary --workspace @mongosh/build"
7778
},
7879
"config": {
7980
"unsafe-perm": true

packages/build/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
"evergreen-release": "ts-node -r ../../scripts/import-expansions.js src/index.ts",
2727
"release": "ts-node src/index.ts trigger-release",
2828
"prettier": "prettier",
29-
"bump": "ts-node src/index.ts bump-packages && ts-node src/index.ts bump-mongosh",
30-
"bump-packages": "ts-node src/index.ts bump-packages",
29+
"bump": "ts-node src/index.ts bump",
30+
"publish": "ts-node src/index.ts publish",
31+
"bump-auxiliary": "ts-node src/index.ts bump --auxiliary",
32+
"publish-auxiliary": "ts-node src/index.ts publish --auxiliary",
3133
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
3234
},
3335
"license": "Apache-2.0",

packages/build/src/config/config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@ export interface Config {
4646
artifactUrlExtraTag?: string;
4747
manpage?: ManPageConfig;
4848
isDryRun?: boolean;
49+
isAuxiliaryOnly?: boolean;
4950
bumpMongoshVersion?: string;
5051
}

packages/build/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ import type { Config, PackageVariant } from './config';
1010
export { getArtifactUrl, downloadMongoDb };
1111

1212
const validCommands: (ReleaseCommand | 'trigger-release')[] = [
13-
'bump-mongosh',
14-
'bump-packages',
13+
'bump',
1514
'compile',
1615
'package',
1716
'upload',
@@ -60,6 +59,7 @@ if (require.main === module) {
6059
}
6160

6261
config.isDryRun ||= process.argv.includes('--dry-run');
62+
config.isAuxiliaryOnly ||= process.argv.includes('--auxiliary');
6363

6464
await release(command, config);
6565
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { spawnSync } from '../helpers';
22
import {
3-
IGNORE_BUMP_PACKAGES,
3+
MONGOSH_RELEASE_ONLY_PACKAGES,
44
MONGOSH_RELEASE_PACKAGES,
55
PROJECT_ROOT,
66
} from './constants';
@@ -66,7 +66,7 @@ export function bumpIndependentPackages() {
6666
env: {
6767
...process.env,
6868
SKIP_BUMP_PACKAGES: [
69-
...IGNORE_BUMP_PACKAGES,
69+
...MONGOSH_RELEASE_ONLY_PACKAGES,
7070
...MONGOSH_RELEASE_PACKAGES,
7171
].join(','),
7272
},

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export const LERNA_BIN = path.resolve(
1111
/** Packages which get bumped only as part of the mongosh release. */
1212
export const MONGOSH_RELEASE_PACKAGES = ['mongosh', '@mongosh/cli-repl'];
1313

14-
/** Packages which always get ignored when doing a release or bump */
15-
export const IGNORE_BUMP_PACKAGES = [
14+
/** Packages which always get excluded when doing a release or bump */
15+
export const EXCLUDE_RELEASE_PACKAGES = [
1616
'@mongodb-js/eslint-config-mongosh',
1717
'@mongodb-js/tsconfig-mongosh',
1818
];

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

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ describe('npm-packages publishNpmPackages', function () {
3030
listNpmPackages.returns(packages);
3131

3232
publishNpmPackages(
33+
false,
3334
false,
3435
listNpmPackages,
3536
markBumpedFilesAsAssumeUnchanged,
@@ -69,6 +70,7 @@ describe('npm-packages publishNpmPackages', function () {
6970

7071
try {
7172
publishNpmPackages(
73+
false,
7274
false,
7375
listNpmPackages,
7476
markBumpedFilesAsAssumeUnchanged,

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

+46-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
import path from 'path';
2-
import { LERNA_BIN, PROJECT_ROOT } from './constants';
2+
import {
3+
EXCLUDE_RELEASE_PACKAGES,
4+
LERNA_BIN,
5+
MONGOSH_RELEASE_PACKAGES,
6+
PROJECT_ROOT,
7+
} from './constants';
38
import type { LernaPackageDescription } from './list';
49
import { listNpmPackages as listNpmPackagesFn } from './list';
510
import { spawnSync } from '../helpers/spawn-sync';
11+
import type { SpawnSyncOptionsWithStringEncoding } from 'child_process';
612

713
export function publishNpmPackages(
814
isDryRun: boolean,
15+
isAuxiliaryOnly = false,
916
listNpmPackages: typeof listNpmPackagesFn = listNpmPackagesFn,
1017
markBumpedFilesAsAssumeUnchangedFn: typeof markBumpedFilesAsAssumeUnchanged = markBumpedFilesAsAssumeUnchanged,
1118
spawnSyncFn: typeof spawnSync = spawnSync
1219
): void {
13-
const packages = listNpmPackages();
20+
const commandOptions: SpawnSyncOptionsWithStringEncoding = {
21+
stdio: 'inherit',
22+
cwd: PROJECT_ROOT,
23+
encoding: 'utf8',
24+
env: {
25+
...process.env,
26+
...(isDryRun ? { npm_config_dry_run: 'true' } : {}),
27+
},
28+
};
29+
let packages = listNpmPackages().filter(
30+
(packageConfig) => !EXCLUDE_RELEASE_PACKAGES.includes(packageConfig.name)
31+
);
1432

33+
if (isAuxiliaryOnly) {
34+
packages = packages.filter(
35+
(packageConfig) => !MONGOSH_RELEASE_PACKAGES.includes(packageConfig.name)
36+
);
37+
}
1538
// Lerna requires a clean repository for a publish from-package (--force-publish does not have any effect here)
1639
// we use git update-index --assume-unchanged on files we know have been bumped
1740
markBumpedFilesAsAssumeUnchangedFn(packages, true);
@@ -23,26 +46,36 @@ export function publishNpmPackages(
2346
'from-package',
2447
'--no-private',
2548
'--no-changelog',
26-
'--no-push',
2749
'--exact',
28-
'--no-git-tag-version',
50+
// During mongosh releases we handle the tags manually
51+
...(!isAuxiliaryOnly ? ['--no-git-tag-version', '--no-push'] : []),
2952
'--force-publish',
3053
'--yes',
3154
'--no-verify-access',
3255
],
33-
{
34-
stdio: 'inherit',
35-
cwd: PROJECT_ROOT,
36-
encoding: 'utf8',
37-
env: {
38-
...process.env,
39-
...(isDryRun ? { npm_config_dry_run: 'true' } : {}),
40-
},
41-
}
56+
commandOptions
4257
);
4358
} finally {
4459
markBumpedFilesAsAssumeUnchangedFn(packages, false);
4560
}
61+
62+
if (!isAuxiliaryOnly) {
63+
const mongoshVersion = packages.find(
64+
(packageConfig) => packageConfig.name === 'mongosh'
65+
)?.version;
66+
67+
if (!mongoshVersion) {
68+
throw new Error('Mongosh package not found');
69+
}
70+
71+
spawnSync(
72+
'git',
73+
['tag', '-a', mongoshVersion, '-m', mongoshVersion],
74+
commandOptions
75+
);
76+
77+
spawnSync('git', ['push', '--follow-tags'], commandOptions);
78+
}
4679
}
4780

4881
export function markBumpedFilesAsAssumeUnchanged(

0 commit comments

Comments
 (0)