Skip to content

Commit 187cfd2

Browse files
committed
WIP: move parts of release to GitHub Actions
1 parent 6c68140 commit 187cfd2

File tree

5 files changed

+97
-22
lines changed

5 files changed

+97
-22
lines changed

.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-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.json

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"precommit": "precommit",
7373
"preinstall": "node scripts/sort-workspaces.js",
7474
"bump": "npm run bump --workspace @mongosh/build",
75+
"publish": "npm run publish --workspace @mongosh/build",
7576
"bump-auxiliary": "npm run bump-auxiliary --workspace @mongosh/build",
7677
"publish-auxiliary": "npm run publish-auxiliary --workspace @mongosh/build"
7778
},

packages/build/src/index.ts

+1-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',

packages/build/src/release.ts

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

2727
export type ReleaseCommand =
28-
| 'bump-mongosh'
29-
| 'bump-packages'
28+
| 'bump'
3029
| 'compile'
3130
| 'package'
3231
| 'sign'
@@ -56,7 +55,7 @@ export async function release(
5655
redactConfig(config)
5756
);
5857

59-
if (command === 'bump-packages') {
58+
if (command === 'bump') {
6059
bumpIndependentPackages();
6160
if (!config.isAuxiliaryOnly) {
6261
await bumpMongoshReleasePackages();

0 commit comments

Comments
 (0)