From 63239c710a3948c7174760a239eb3113eba2c21b Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 3 Mar 2025 11:11:56 +0100 Subject: [PATCH 1/3] Support creating release branches when releasing new versions --- .github/workflows/release.yml | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7d22c6c6c..13dc385d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -57,7 +57,9 @@ jobs: - name: "Store version numbers in env variables" run: | echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV + echo RELEASE_VERSION_WITHOUT_STABILITY=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV echo RELEASE_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-2) >> $GITHUB_ENV + echo DEVELOPMENT_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-1).x >> $GITHUB_ENV - name: "Ensure release tag does not already exist" run: | @@ -66,16 +68,35 @@ jobs: exit 1 fi - - name: "Fail if branch names don't match" - if: ${{ github.ref_name != env.RELEASE_BRANCH }} + # For patch releases (A.B.C where C != 0), we expect the release to be + # triggered from the vA.B release branch + - name: "Fail if patch release is created from wrong release branch" + if: ${{ !endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name }} run: | echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY exit 1 + # For non-patch releases (A.B.C where C == 0), we expect the release to + # be triggered from the vA.x development branch or the vA.B release branch. + # This includes pre-releases (e.g. alpha, beta, rc) + - name: "Fail if non-patch release is created from wrong release branch" + if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name && env.DEVELOPMENT_BRANCH != github.ref_name }} + run: | + echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or ${{ env.DEVELOPMENT_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY + exit 1 + # # Preliminary checks done - commence the release process # + # Create the new release branch if we're releasing from the vA.x + # development branch + - name: "Create new release branch" + if: ${{ github.ref_name != env.RELEASE_BRANCH }} + run: | + git checkout -b ${{ env.RELEASE_BRANCH }} + git push origin ${{ env.RELEASE_BRANCH }} + - name: "Set up drivers-github-tools" uses: mongodb-labs/drivers-github-tools/setup@v2 with: @@ -90,7 +111,7 @@ jobs: EOL - name: "Create draft release" - run: echo "RELEASE_URL=$(gh release create ${{ inputs.version }} --target ${{ github.ref_name }} --title "${{ inputs.version }}" --notes-file release-message --draft)" >> "$GITHUB_ENV" + run: echo "RELEASE_URL=$(gh release create ${{ inputs.version }} --target ${{ env.RELEASE_BRANCH }} --title "${{ inputs.version }}" --notes-file release-message --draft)" >> "$GITHUB_ENV" - name: "Create release tag" uses: mongodb-labs/drivers-github-tools/tag-version@v2 From 90f9a3032c6014fe4a11723ea6c9a4be69b9e68c Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 3 Mar 2025 13:46:05 +0100 Subject: [PATCH 2/3] Use same logic as in laravel integration --- .github/workflows/release.yml | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 13dc385d9..69f24715a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,7 +59,7 @@ jobs: echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV echo RELEASE_VERSION_WITHOUT_STABILITY=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV echo RELEASE_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-2) >> $GITHUB_ENV - echo DEVELOPMENT_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-1).x >> $GITHUB_ENV + echo DEV_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-1).x >> $GITHUB_ENV - name: "Ensure release tag does not already exist" run: | @@ -69,7 +69,7 @@ jobs: fi # For patch releases (A.B.C where C != 0), we expect the release to be - # triggered from the vA.B release branch + # triggered from the A.B maintenance branch - name: "Fail if patch release is created from wrong release branch" if: ${{ !endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name }} run: | @@ -77,26 +77,26 @@ jobs: exit 1 # For non-patch releases (A.B.C where C == 0), we expect the release to - # be triggered from the vA.x development branch or the vA.B release branch. - # This includes pre-releases (e.g. alpha, beta, rc) + # be triggered from the A.x maintenance branch or A.x development branch - name: "Fail if non-patch release is created from wrong release branch" - if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name && env.DEVELOPMENT_BRANCH != github.ref_name }} + if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name && env.DEV_BRANCH != github.ref_name }} run: | - echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or ${{ env.DEVELOPMENT_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY + echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or ${{ env.DEV_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY exit 1 + # If a non-patch release is created from its A.x development branch, + # create the A.B maintenance branch from the current one and push it + - name: "Create and push new release branch for non-patch release" + if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.DEV_BRANCH == github.ref_name }} + run: | + echo '🆕 Creating new release branch ${RELEASE_BRANCH} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY + git checkout -b ${RELEASE_BRANCH} + git push origin ${RELEASE_BRANCH} + # # Preliminary checks done - commence the release process # - # Create the new release branch if we're releasing from the vA.x - # development branch - - name: "Create new release branch" - if: ${{ github.ref_name != env.RELEASE_BRANCH }} - run: | - git checkout -b ${{ env.RELEASE_BRANCH }} - git push origin ${{ env.RELEASE_BRANCH }} - - name: "Set up drivers-github-tools" uses: mongodb-labs/drivers-github-tools/setup@v2 with: From 69c381eb343daa798cb97a92c1c0458891b410b4 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 3 Mar 2025 15:39:58 +0100 Subject: [PATCH 3/3] Update .github/workflows/release.yml Co-authored-by: Jeremy Mikola --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 69f24715a..bfb418866 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -77,7 +77,7 @@ jobs: exit 1 # For non-patch releases (A.B.C where C == 0), we expect the release to - # be triggered from the A.x maintenance branch or A.x development branch + # be triggered from the A.B maintenance branch or A.x development branch - name: "Fail if non-patch release is created from wrong release branch" if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name && env.DEV_BRANCH != github.ref_name }} run: |