Skip to content

Commit 07a28ac

Browse files
committed
add bumping
1 parent 4f43369 commit 07a28ac

File tree

8 files changed

+119
-12
lines changed

8 files changed

+119
-12
lines changed

.github/workflows/draft-release.yml

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
name: Draft release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
versionBump:
7+
description: 'Version bump'
8+
type: choice
9+
required: true
10+
default: 'patch'
11+
options:
12+
- patch
13+
- minor
14+
- major
15+
- exact-version
16+
17+
exactVersion:
18+
description: 'Exact version: (Only effective selecting "exact-version" as version bump)'
19+
required: false
20+
21+
jobs:
22+
prepare-release:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
with:
28+
# NOTE: this is necessary to get the full history
29+
# and check if tags are already present
30+
fetch-depth: 0
31+
32+
- name: Setup Node.js Environment
33+
uses: actions/setup-node@v4
34+
with:
35+
node-version: 20.18.1
36+
37+
- name: Determine Next Version
38+
shell: bash
39+
env:
40+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41+
run: |
42+
set -e
43+
44+
VERSION_BUMP=${{ github.event.inputs.versionBump }}
45+
46+
if [[ "$VERSION_BUMP" == "major" || "$VERSION_BUMP" == "minor" || "$VERSION_BUMP" == "patch" ]]; then
47+
PREV_VERSION_TAG=$(gh api repos/:owner/:repo/releases --jq '. | map(select(.draft == false)) | .[0] | .tag_name')
48+
PREV_VERSION=$(npx semver --coerce ${PREV_VERSION_TAG})
49+
50+
NEXT_VERSION=$(npx semver -i $VERSION_BUMP $PREV_VERSION)
51+
else
52+
NEXT_VERSION=${{ github.event.inputs.exactVersion }}
53+
fi
54+
55+
# Validates the version before using it
56+
npx semver v"${NEXT_VERSION}"
57+
58+
npm version "${NEXT_VERSION}" --no-git-tag-version
59+
echo "RELEASE_TAG=v${NEXT_VERSION}" >> "$GITHUB_ENV"
60+
61+
- name: Validate release tag
62+
shell: bash
63+
run: |
64+
if [ -z "${RELEASE_TAG}" ]; then
65+
echo "RELEASE_TAG is not set or is empty"
66+
exit 1
67+
fi
68+
69+
if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
70+
echo "Error: Tag $RELEASE_TAG already exists"
71+
echo "If you are trying to re-create a draft release with this version, please delete the release and the tag first."
72+
echo "If this version has already been release consider using a different one."
73+
exit 1
74+
fi
75+
76+
- name: Bump mongosh and package versions
77+
run: |
78+
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}"
87+
88+
git tag ${RELEASE_TAG}
89+
git push origin ${RELEASE_TAG}
90+
91+
shell: bash
92+
env:
93+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
94+

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"prepare": "husky",
7272
"precommit": "precommit",
7373
"preinstall": "node scripts/sort-workspaces.js",
74+
"bump": "npm run bump --workspace @mongosh/build",
7475
"bump-packages": "npm run bump-packages --workspace @mongosh/build",
7576
"publish-packages": "lerna publish from-package --no-verify-access --no-push --no-git-tag-version --yes"
7677
},
@@ -100,6 +101,7 @@
100101
"@babel/compat-data": "^7.9.0",
101102
"@mongodb-js/monorepo-tools": "^1.1.10",
102103
"@mongodb-js/sbom-tools": "^0.7.0",
104+
"@pkgjs/nv": "^0.2.2",
103105
"@types/chai": "^4.2.5",
104106
"@types/mocha": "^5.2.7",
105107
"@types/node": "^14.14.6",
@@ -109,6 +111,7 @@
109111
"@types/which": "^1.3.2",
110112
"chai": "^4.2.0",
111113
"cross-env": "^6.0.3",
114+
"depcheck": "^1.4.7",
112115
"duplexpair": "^1.0.2",
113116
"find-up": "^5.0.0",
114117
"glob": "^10.3.12",
@@ -120,7 +123,7 @@
120123
"nyc": "^15.1.0",
121124
"pkg-up": "^3.1.0",
122125
"rimraf": "^3.0.2",
123-
"semver": "^7.5.4",
126+
"semver": "^7.6.3",
124127
"sinon": "^7.5.0",
125128
"sinon-chai": "^3.5.0",
126129
"terser-webpack-plugin": "^4.2.3",
@@ -132,9 +135,7 @@
132135
"webpack-bundle-analyzer": "^4.7.0",
133136
"webpack-cli": "^4.3.1",
134137
"which": "^2.0.2",
135-
"yaml": "^1.10.0",
136-
"depcheck": "^1.4.7",
137-
"@pkgjs/nv": "^0.2.2"
138+
"yaml": "^1.10.0"
138139
},
139140
"optionalDependencies": {
140141
"lerna": "^8.1.8"

packages/build/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
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",
2931
"reformat": "npm run prettier -- --write . && npm run eslint --fix"
3032
},
3133
"license": "Apache-2.0",

packages/build/src/config/config.ts

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

packages/build/src/index.ts

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

1212
const validCommands: (ReleaseCommand | 'trigger-release')[] = [
13-
'bump',
13+
'bump-mongosh',
14+
'bump-packages',
1415
'compile',
1516
'package',
1617
'upload',

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ import path from 'path';
1010
import { getPackagesInTopologicalOrder } from '@mongodb-js/monorepo-tools';
1111

1212
/** Bumps only the main mongosh release packages to the set version. */
13-
export async function bumpMongoshReleasePackages(
14-
version: string
15-
): Promise<void> {
13+
export async function bumpMongoshReleasePackages(): Promise<void> {
14+
const version = process.env.MONGOSH_RELEASE_VERSION;
15+
if (!version) {
16+
throw new Error(
17+
'MONGOSH_RELEASE_VERSION version not specified during mongosh bump'
18+
);
19+
}
1620
console.info(`mongosh: Bumping package versions to ${version}`);
1721
const monorepoRootPath = path.resolve(__dirname, '..', '..', '..', '..');
1822
const packages = await getPackagesInTopologicalOrder(monorepoRootPath);

packages/build/src/release.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import { runDownloadCryptLibrary } from './packaging/run-download-crypt-library'
2525
import { bumpMongoshReleasePackages } from './npm-packages/bump';
2626

2727
export type ReleaseCommand =
28-
| 'bump'
28+
| 'bump-mongosh'
29+
| 'bump-packages'
2930
| 'compile'
3031
| 'package'
3132
| 'sign'
@@ -55,9 +56,12 @@ export async function release(
5556
redactConfig(config)
5657
);
5758

58-
if (command === 'bump') {
59+
if (command === 'bump-packages') {
5960
bumpIndependentPackages();
60-
await bumpMongoshReleasePackages(config.version);
61+
return;
62+
}
63+
if (command === 'bump-mongosh') {
64+
await bumpMongoshReleasePackages();
6165
return;
6266
}
6367

0 commit comments

Comments
 (0)