From 6a2ad8b4df1095dc878f22fe794834d3947e23de Mon Sep 17 00:00:00 2001 From: gagik Date: Thu, 20 Feb 2025 20:43:30 +0100 Subject: [PATCH 1/6] chore(ci): add automatic merging of the release tag The new system requires us to manually merge into main. This automates it through a workflow --- .github/workflows/merge-release-tag.yml | 54 +++++++++++++++++++++++++ packages/build/README.md | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/merge-release-tag.yml diff --git a/.github/workflows/merge-release-tag.yml b/.github/workflows/merge-release-tag.yml new file mode 100644 index 0000000000..ff41fdfc61 --- /dev/null +++ b/.github/workflows/merge-release-tag.yml @@ -0,0 +1,54 @@ +name: Merge Release Tag + +on: + push: + tags: + - 'mongosh@[0-9]+.[0-9]+.[0-9]+' + workflow_dispatch: + +jobs: + merge-release-tag: + runs-on: ubuntu-latest + + steps: + - 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: + ref: ${{ github.ref }} + fetch-depth: "0" + token: ${{ steps.app-token.outputs.token }} + + - name: Extract version from tag + id: version + run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF} | sed -n 's/refs\/tags\/mongosh@\([0-9]\+\.[0-9]\+\.[0-9]\+\)/\1/p')" >> $GITHUB_ENV + + - name: Validate release version + shell: bash + run: | + if [ -z "${RELEASE_VERSION}" ]; then + echo "RELEASE_TAG is not set or is empty" + exit 1 + fi + + if git rev-parse "release/v$RELEASE_VERSION" >/dev/null 2>&1; then + echo "Error: Branch release/v$RELEASE_TAG already exists" + echo "If this version has already been released consider using a different one." + exit 1 + fi + + - name: Create and push branch from tag + run: | + git checkout -b release/v$RELEASE_VERSION ${{ github.ref }} + git push origin release/v$RELEASE_VERSION + + - name: Merge branch into main + run: | + git checkout main + git merge release/v$RELEASE_VERSION + git push origin main + git push -d origin release/v$RELEASE_VERSION diff --git a/packages/build/README.md b/packages/build/README.md index 6df95c36ee..982ec11bb1 100644 --- a/packages/build/README.md +++ b/packages/build/README.md @@ -39,7 +39,7 @@ Execute the following steps to publish a new release: ``` Follow the instructions and verify the inferred release version is correct. 7. Wait for Evergreen to finish the publication stage. -8. The previous step will have pushed tags for the npm publishes. Check out the tag for `mongosh@` (not `v`), create a branch for it, push that branch and open a PR with it. Then immediately merge that branch **using the `git merge` CLI command into main** and push to main. **NEVER** use the Github PR merge functionality, since that would squash the commit and give it a new commit hash that is different from the one in the tag. +8. Ensure the release version bump has been automatically merged into the main branch from the `release/vx.x.x` branch. 9. Close the Jira ticket for the release, post an update in the `#mongosh` Slack channel and ping the docs team. ### Branches and Tags From 539413b59918e9ef3ed1c7570985115e56852f16 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 21 Feb 2025 10:39:32 +0100 Subject: [PATCH 2/6] refactor: use a GitHub actions and a more permissive regex --- .github/workflows/merge-release-tag.yml | 31 ++++++++++++++----------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/merge-release-tag.yml b/.github/workflows/merge-release-tag.yml index ff41fdfc61..12aaa8fa45 100644 --- a/.github/workflows/merge-release-tag.yml +++ b/.github/workflows/merge-release-tag.yml @@ -3,9 +3,12 @@ name: Merge Release Tag on: push: tags: - - 'mongosh@[0-9]+.[0-9]+.[0-9]+' + - 'mongosh@[0-9]+.[0-9]+.*' workflow_dispatch: +permissions: + contents: none # We use the github app to checkout and push tags + jobs: merge-release-tag: runs-on: ubuntu-latest @@ -24,31 +27,31 @@ jobs: token: ${{ steps.app-token.outputs.token }} - name: Extract version from tag - id: version - run: echo "RELEASE_VERSION=$(echo ${GITHUB_REF} | sed -n 's/refs\/tags\/mongosh@\([0-9]\+\.[0-9]\+\.[0-9]\+\)/\1/p')" >> $GITHUB_ENV + uses: actions-ecosystem/action-regex-match@d50fd2e7a37d0e617aea3d7ada663bd56862b9cc + id: version-match + with: + text: ${{ github.ref }} + regex: 'refs/tags/mongosh@([0-9]+\.[0-9]+\.*)' - name: Validate release version shell: bash + id: validate run: | - if [ -z "${RELEASE_VERSION}" ]; then - echo "RELEASE_TAG is not set or is empty" + if [[ -z "${{ steps.version-match.outputs.group1 }}" ]]; then + echo "Error: Could not extract version from tag" exit 1 fi - if git rev-parse "release/v$RELEASE_VERSION" >/dev/null 2>&1; then + if git rev-parse "release/v${{ steps.version-match.outputs.group1 }}" >/dev/null 2>&1; then echo "Error: Branch release/v$RELEASE_TAG already exists" echo "If this version has already been released consider using a different one." exit 1 fi + echo "::set-output name=version::${{ steps.version-match.outputs.group1 }}" - - name: Create and push branch from tag - run: | - git checkout -b release/v$RELEASE_VERSION ${{ github.ref }} - git push origin release/v$RELEASE_VERSION - - - name: Merge branch into main + - name: Merge release tag into main run: | + git checkout -b release/v${{ steps.validate.outputs.version }} ${{ github.ref }} git checkout main - git merge release/v$RELEASE_VERSION + git merge release/v${{ steps.validate.outputs.version }} git push origin main - git push -d origin release/v$RELEASE_VERSION From 21963c258995c7102d6aa2206703f77cbd2bf7a9 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 21 Feb 2025 10:47:49 +0100 Subject: [PATCH 3/6] docs: reword release process check --- .github/workflows/merge-release-tag.yml | 2 +- packages/build/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/merge-release-tag.yml b/.github/workflows/merge-release-tag.yml index 12aaa8fa45..f5f0f57533 100644 --- a/.github/workflows/merge-release-tag.yml +++ b/.github/workflows/merge-release-tag.yml @@ -7,7 +7,7 @@ on: workflow_dispatch: permissions: - contents: none # We use the github app to checkout and push tags + contents: none # We use the github app to checkout and push changes jobs: merge-release-tag: diff --git a/packages/build/README.md b/packages/build/README.md index 982ec11bb1..938d0da1d7 100644 --- a/packages/build/README.md +++ b/packages/build/README.md @@ -39,7 +39,7 @@ Execute the following steps to publish a new release: ``` Follow the instructions and verify the inferred release version is correct. 7. Wait for Evergreen to finish the publication stage. -8. Ensure the release version bump has been automatically merged into the main branch from the `release/vx.x.x` branch. +8. Ensure that the version bump was automatically merged into main and that it is synced up with the `mongosh@x.x.x` tag. 9. Close the Jira ticket for the release, post an update in the `#mongosh` Slack channel and ping the docs team. ### Branches and Tags From 8cedbec1a23ea56bc3396fe1861a768bce863f90 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 21 Feb 2025 12:17:05 +0100 Subject: [PATCH 4/6] fix: use stricter tag, use action for validation and rename to package-release --- .github/workflows/merge-release-tag.yml | 28 ++++++++----------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/.github/workflows/merge-release-tag.yml b/.github/workflows/merge-release-tag.yml index f5f0f57533..65ac055be9 100644 --- a/.github/workflows/merge-release-tag.yml +++ b/.github/workflows/merge-release-tag.yml @@ -3,7 +3,7 @@ name: Merge Release Tag on: push: tags: - - 'mongosh@[0-9]+.[0-9]+.*' + - 'mongosh@[0-9]+.[0-9]+.[0-9]+*' workflow_dispatch: permissions: @@ -31,27 +31,17 @@ jobs: id: version-match with: text: ${{ github.ref }} - regex: 'refs/tags/mongosh@([0-9]+\.[0-9]+\.*)' + regex: 'refs/tags/mongosh@([0-9]+\.[0-9]+\.[0-9]+.*)' - - name: Validate release version - shell: bash - id: validate - run: | - if [[ -z "${{ steps.version-match.outputs.group1 }}" ]]; then - echo "Error: Could not extract version from tag" - exit 1 - fi - - if git rev-parse "release/v${{ steps.version-match.outputs.group1 }}" >/dev/null 2>&1; then - echo "Error: Branch release/v$RELEASE_TAG already exists" - echo "If this version has already been released consider using a different one." - exit 1 - fi - echo "::set-output name=version::${{ steps.version-match.outputs.group1 }}" + - uses: actions/github-script@v7 + if: steps.version-match.outputs.group1 == '' + with: + script: | + core.setFailed('Could not extract version from tag: ${{ github.ref }}'); - name: Merge release tag into main run: | - git checkout -b release/v${{ steps.validate.outputs.version }} ${{ github.ref }} + git checkout -b package-release/v${{ steps.version-match.outputs.group1 }} ${{ github.ref }} git checkout main - git merge release/v${{ steps.validate.outputs.version }} + git merge package-release/v${{ steps.version-match.outputs.group1 }} git push origin main From 6525369e727d7af19a0cf6280232a5675b446629 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 21 Feb 2025 12:39:15 +0100 Subject: [PATCH 5/6] fix: simplify the workflow --- .github/workflows/merge-release-tag.yml | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/.github/workflows/merge-release-tag.yml b/.github/workflows/merge-release-tag.yml index 65ac055be9..37e3319f10 100644 --- a/.github/workflows/merge-release-tag.yml +++ b/.github/workflows/merge-release-tag.yml @@ -22,26 +22,11 @@ jobs: - uses: actions/checkout@v4 with: - ref: ${{ github.ref }} + ref: main fetch-depth: "0" token: ${{ steps.app-token.outputs.token }} - - name: Extract version from tag - uses: actions-ecosystem/action-regex-match@d50fd2e7a37d0e617aea3d7ada663bd56862b9cc - id: version-match - with: - text: ${{ github.ref }} - regex: 'refs/tags/mongosh@([0-9]+\.[0-9]+\.[0-9]+.*)' - - - uses: actions/github-script@v7 - if: steps.version-match.outputs.group1 == '' - with: - script: | - core.setFailed('Could not extract version from tag: ${{ github.ref }}'); - - name: Merge release tag into main run: | - git checkout -b package-release/v${{ steps.version-match.outputs.group1 }} ${{ github.ref }} - git checkout main - git merge package-release/v${{ steps.version-match.outputs.group1 }} + git merge ${{ github.ref }} -m "chore(release): merge changes from ${{ github.ref_name }}" git push origin main From d62c7569b6a753b76b9af83bca1cd51b754008d0 Mon Sep 17 00:00:00 2001 From: gagik Date: Fri, 21 Feb 2025 12:53:20 +0100 Subject: [PATCH 6/6] chore: explicitly define release candidate case --- .github/workflows/merge-release-tag.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/merge-release-tag.yml b/.github/workflows/merge-release-tag.yml index 37e3319f10..8f9583f589 100644 --- a/.github/workflows/merge-release-tag.yml +++ b/.github/workflows/merge-release-tag.yml @@ -3,7 +3,8 @@ name: Merge Release Tag on: push: tags: - - 'mongosh@[0-9]+.[0-9]+.[0-9]+*' + - 'mongosh@[0-9]+.[0-9]+.[0-9]+' + - 'mongosh@[0-9]+.[0-9]+.[0-9]-rc.[0-9]+' workflow_dispatch: permissions: