Skip to content

Commit 6c68140

Browse files
committed
add bumping
1 parent 69c8d6e commit 6c68140

File tree

4 files changed

+100
-3
lines changed

4 files changed

+100
-3
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.json

+1
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-auxiliary": "npm run bump-auxiliary --workspace @mongosh/build",
7576
"publish-auxiliary": "npm run publish-auxiliary --workspace @mongosh/build"
7677
},

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/release.ts

+3-2
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,7 +56,7 @@ export async function release(
5556
redactConfig(config)
5657
);
5758

58-
if (command === 'bump') {
59+
if (command === 'bump-packages') {
5960
bumpIndependentPackages();
6061
if (!config.isAuxiliaryOnly) {
6162
await bumpMongoshReleasePackages();

0 commit comments

Comments
 (0)