Skip to content

Commit

Permalink
WIP: move parts of release to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
gagik committed Jan 6, 2025
1 parent 6c68140 commit 187cfd2
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
name: Draft release
name: Prepare mongosh release

on:
workflow_dispatch:
inputs:
jiraTicket:
description: 'Jira ticket for the release, e.g. MONGOSH-1234'
required: true

versionBump:
description: 'Version bump'
type: choice
Expand All @@ -22,6 +26,13 @@ jobs:
prepare-release:
runs-on: ubuntu-latest
steps:
- name: Create Github App Token
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
id: app-token
with:
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}

- name: Checkout
uses: actions/checkout@v4
with:
Expand All @@ -36,8 +47,6 @@ jobs:

- name: Determine Next Version
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
set -e
Expand All @@ -51,6 +60,9 @@ jobs:
else
NEXT_VERSION=${{ github.event.inputs.exactVersion }}
fi
# Remove the 'v' prefix from NEXT_VERSION if it exists
NEXT_VERSION="${NEXT_VERSION#v}"
# Validates the version before using it
npx semver v"${NEXT_VERSION}"
Expand All @@ -74,21 +86,26 @@ jobs:
fi
- name: Bump mongosh and package versions
shell: bash
env:
LAST_BUMP_COMMIT_MESSAGE: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
run: |
set -e
echo Bumping mongosh versions to ${RELEASE_TAG} and packages
MONGOSH_RELEASE_VERSION=${RELEASE_TAG} npm run bump
- name: Create Draft Release
run: |
set -e
echo Creating draft release for: "${RELEASE_TAG}"
echo Bumping mongosh versions to ${NEXT_VERSION} and packages
git tag ${RELEASE_TAG}
git push origin ${RELEASE_TAG}
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MONGOSH_RELEASE_VERSION=${NEXT_VERSION} npm run bump
git add .
git commit --no-allow-empty -m "$LAST_BUMP_COMMIT_MESSAGE" || true
- name: Create Pull Request
uses: peter-evans/create-pull-request@5e914681df9dc83aa4e4905692ca88beb2f9e91f # 7.0.5
with:
token: ${{ steps.app-token.outputs.token }}
commit-message: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
branch: release/${NEXT_VERSION}
title: "chore(release): prepare for mongosh v${NEXT_VERSION} ${{ github.event.inputs.jiraTicket }}"
body: |
- [${{ github.event.inputs.jiraTicket }}](https://jira.mongodb.org/browse/${{ github.event.inputs.jiraTicket }})
- This PR is for the release of mongosh v${NEXT_VERSION}.
- **Do not merge manually, use the Release mongosh action instead.**
59 changes: 59 additions & 0 deletions .github/workflows/release-mongosh.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release mongosh
on:
workflow_run:
workflows: ["CheckQL", "Run Smoke Tests", "evergreen"]
types: ["completed"]
branches: ["release/**"]
workflow_dispatch:

jobs:
publish:
if: |
startsWith(github.head_ref, 'refs/heads/release/')
runs-on: ubuntu-latest

steps:
- name: Create Github App Token
uses: mongodb-js/devtools-shared/actions/setup-bot-token@main
id: app-token
with:
app-id: ${{ vars.DEVTOOLS_BOT_APP_ID }}
private-key: ${{ secrets.DEVTOOLS_BOT_PRIVATE_KEY }}

- uses: actions/checkout@v4
with:
# don't checkout a detatched HEAD
ref: ${{ github.head_ref }}

- name: Extract version from the branch
run: |
set -e
export NEXT_VERSION=$(echo "${GITHUB_REF}" | sed -n 's/refs\/heads\/release\/\(.*\)/\1/p')
echo "NEXT_VERSION=${NEXT_VERSION}" >> "$GITHUB_ENV"
echo "RELEASE_TAG=v${NEXT_VERSION}" >> "$GITHUB_ENV"
- name: Validate release tag
shell: bash
run: |
if [ -z "${RELEASE_TAG}" ]; then
echo "RELEASE_TAG is not set or is empty"
exit 1
fi
if git rev-parse "$RELEASE_TAG" >/dev/null 2>&1; then
echo "Error: Tag $RELEASE_TAG already exists"
echo "If you are trying to re-create a draft release with this version, please delete the release and the tag first."
echo "If this version has already been released consider using a different one."
exit 1
fi
- name: "Publish what is not already in NPM"
env:
NPM_TOKEN: ${{ secrets.DEVTOOLSBOT_NPM_TOKEN }}
run: |
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
npm config list
echo "Publishing packages as $(npm whoami)"
git update-index --assume-unchanged .npmrc
npm run publish-packages
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"precommit": "precommit",
"preinstall": "node scripts/sort-workspaces.js",
"bump": "npm run bump --workspace @mongosh/build",
"publish": "npm run publish --workspace @mongosh/build",
"bump-auxiliary": "npm run bump-auxiliary --workspace @mongosh/build",
"publish-auxiliary": "npm run publish-auxiliary --workspace @mongosh/build"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import type { Config, PackageVariant } from './config';
export { getArtifactUrl, downloadMongoDb };

const validCommands: (ReleaseCommand | 'trigger-release')[] = [
'bump-mongosh',
'bump-packages',
'bump',
'compile',
'package',
'upload',
Expand Down
5 changes: 2 additions & 3 deletions packages/build/src/release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import { runDownloadCryptLibrary } from './packaging/run-download-crypt-library'
import { bumpMongoshReleasePackages } from './npm-packages/bump';

export type ReleaseCommand =
| 'bump-mongosh'
| 'bump-packages'
| 'bump'
| 'compile'
| 'package'
| 'sign'
Expand Down Expand Up @@ -56,7 +55,7 @@ export async function release(
redactConfig(config)
);

if (command === 'bump-packages') {
if (command === 'bump') {
bumpIndependentPackages();
if (!config.isAuxiliaryOnly) {
await bumpMongoshReleasePackages();
Expand Down

0 comments on commit 187cfd2

Please sign in to comment.