diff --git a/.github/workflows/draft-release.yml b/.github/workflows/prepare-release-mongosh.yml similarity index 58% rename from .github/workflows/draft-release.yml rename to .github/workflows/prepare-release-mongosh.yml index 1b33a906c..a7702cbf8 100644 --- a/.github/workflows/draft-release.yml +++ b/.github/workflows/prepare-release-mongosh.yml @@ -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 @@ -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: @@ -36,8 +47,6 @@ jobs: - name: Determine Next Version shell: bash - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | set -e @@ -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}" @@ -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.** \ No newline at end of file diff --git a/.github/workflows/release-mongosh.yml b/.github/workflows/release-mongosh.yml new file mode 100644 index 000000000..0b1ae2292 --- /dev/null +++ b/.github/workflows/release-mongosh.yml @@ -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 \ No newline at end of file diff --git a/package.json b/package.json index 36585872d..ea58691bf 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/packages/build/src/index.ts b/packages/build/src/index.ts index 4066089b8..665e90d94 100644 --- a/packages/build/src/index.ts +++ b/packages/build/src/index.ts @@ -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',