From 1d1210d6e43d522b8c458028d7eb9eaa7e88f98c Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 20 Jun 2024 13:18:21 +0200 Subject: [PATCH 1/7] Support pre-releases in release tooling --- .github/workflows/release.yml | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0832b079955..3067b0e9c47 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -36,9 +36,23 @@ jobs: - name: "Store version numbers in env variables" # The awk command to increase the version number was copied from # StackOverflow: https://stackoverflow.com/a/61921674/3959933 + # Variables set here: + # RELEASE_VERSION: The version the deployment is expected to create + # RELEASE_VERSION_WITHOUT_SUFFIX: The version without any stability + # suffixes. Example: 5.2.0-beta0 => 5.2.0 + # NEXT_VERSION: The next version to be released. For pre-releases, the + # next version is a snapshot of the pre-release version. Examples: + # 5.2.0 => 5.2.1; 5.2.0-beta0 => 5.2.0 + # RELEASE_BRANCH: The name of the stable branch for this release series + # Example: 5.2.0 => 5.2.x run: | echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV - echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV + echo RELEASE_VERSION_WITHOUT_SUFFIX=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV + if [[ "${{ inputs.version }}" =~ (alpha|beta)[0-9]+$ ]]; then + echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV + else + echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV + fi echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV - name: "Ensure release tag does not already exist" @@ -49,17 +63,19 @@ jobs: fi # For patch releases (A.B.C where C != 0), we expect the release to be - # triggered from the A.B.x maintenance branch + # triggered from the A.B.x maintenance branch. We use the release version + # without suffixes to avoid mistakes when making pre-releases - name: "Fail if patch release is created from wrong release branch" - if: ${{ !endsWith(inputs.version, '.0') && env.RELEASE_BRANCH != github.ref_name }} + if: ${{ !endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.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 master or the A.B.x maintenance branch + # be triggered from master or the A.B.x maintenance branch. This includes + # pre-releases for any non-patch releases, e.g. 5.2.0-beta1 - name: "Fail if non-patch release is created from wrong release branch" - if: ${{ endsWith(inputs.version, '.0') && env.RELEASE_BRANCH != github.ref_name && github.ref_name != 'master' }} + if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.0') && env.RELEASE_BRANCH != github.ref_name && github.ref_name != 'master' }} run: | echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or master, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY exit 1 @@ -67,9 +83,9 @@ jobs: # If a non-patch release is created from a branch other than its # maintenance branch, create that branch from the current one and push it - name: "Create new release branch for non-patch release" - if: ${{ endsWith(inputs.version, '.0') && env.RELEASE_BRANCH != github.ref_name }} + if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.0') && env.RELEASE_BRANCH != github.ref_name }} run: | - echo '🆕 Creating new release branch ${RELEASE_BRANCH} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY + echo '🆕 Creating new release branch ${{ env.RELEASE_BRANCH }} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY git checkout -b ${RELEASE_BRANCH} - name: "Set git author information" @@ -88,8 +104,12 @@ jobs: - name: "Create draft release with generated changelog" run: | + if [[ "${{ inputs.version }}" =~ (alpha|beta) ]]; then + PRERELEASE="--prerelease --latest=false" + fi echo "RELEASE_URL=$(\ gh release create r${RELEASE_VERSION} \ + ${PRERELEASE} \ --target ${{ env.RELEASE_BRANCH }} \ --title "Java Driver ${{ env.RELEASE_VERSION }} ($(date '+%B %d, %Y'))" \ --generate-notes \ From 10e948f5e99ae28d0b42a7a09be1501d6421a5f1 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 20 Jun 2024 15:29:24 +0200 Subject: [PATCH 2/7] Prevent releases from wrong snapshot version in build.gradle --- .github/workflows/release.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3067b0e9c47..79f528f844c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -55,6 +55,14 @@ jobs: fi echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV + - name: "Ensure current snapshot version matches release version" + run: | + grep -q "version = '${RELEASE_VERSION_WITHOUT_SUFFIX}-SNAPSHOT'" build.gradle + if [[ $? != 0 ]]; then + echo '❌ Release failed: version in build.gradle is not a snapshot for release version ${{ inputs.version }}' >> $GITHUB_STEP_SUMMARY + exit 1 + fi + - name: "Ensure release tag does not already exist" run: | if [[ $(git tag -l r${RELEASE_VERSION}) == r${RELEASE_VERSION} ]]; then From ad3fc15e8dca4cadf17c14c55994fd95e28f5b89 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 20 Jun 2024 15:43:37 +0200 Subject: [PATCH 3/7] Support release candidates as pre-releases --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79f528f844c..a13b9dabe43 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -48,7 +48,7 @@ jobs: run: | echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV echo RELEASE_VERSION_WITHOUT_SUFFIX=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV - if [[ "${{ inputs.version }}" =~ (alpha|beta)[0-9]+$ ]]; then + if [[ "${{ inputs.version }}" =~ (alpha|beta|rc)[0-9]+$ ]]; then echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV else echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV @@ -112,7 +112,7 @@ jobs: - name: "Create draft release with generated changelog" run: | - if [[ "${{ inputs.version }}" =~ (alpha|beta) ]]; then + if [[ "${{ inputs.version }}" =~ (alpha|beta|rc) ]]; then PRERELEASE="--prerelease --latest=false" fi echo "RELEASE_URL=$(\ From 88ee4fca0ed6b7d03d415d814ed94279ed99e4ac Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 20 Jun 2024 15:54:33 +0200 Subject: [PATCH 4/7] Extract version bump to separate script --- .github/workflows/bump-and-tag.sh | 22 +++++++++++++--------- .github/workflows/bump-version.sh | 13 +++++++++++++ .github/workflows/release.yml | 2 +- 3 files changed, 27 insertions(+), 10 deletions(-) create mode 100755 .github/workflows/bump-version.sh diff --git a/.github/workflows/bump-and-tag.sh b/.github/workflows/bump-and-tag.sh index 84b7567427c..9e735586e91 100755 --- a/.github/workflows/bump-and-tag.sh +++ b/.github/workflows/bump-and-tag.sh @@ -1,18 +1,22 @@ #!/usr/bin/env bash set -e -# This script assumes that release X.Y.Z will always be created from X.Y.Z-SNAPSHOT" -echo "Replace snapshot version with release version ${RELEASE_VERSION} in build.gradle" -sed --in-place "s/version = '.*-SNAPSHOT'/version = '${RELEASE_VERSION}'/g" build.gradle +if [ "$#" -ne 3 ]; then + echo "Usage: $0 " >&2 + exit 1 +fi -echo "Create package commit for ${RELEASE_VERSION}" -git commit -m "Version: bump ${RELEASE_VERSION}" build.gradle +CURRENT_VERSION=$1 +RELEASE_VERSION=$2 +NEXT_VERSION=$3 + +SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]}) + +echo "Bump version in build.gradle to ${RELEASE_VERSION}" +${SCRIPT_DIR}/bump-version.sh "${RELEASE_VERSION_WITHOUT_SUFFIX}-SNAPSHOT" "${RELEASE_VERSION}" echo "Create release tag for ${RELEASE_VERSION}" git tag -a -m "${RELEASE_VERSION}" r${RELEASE_VERSION} echo "Bump to snapshot version for ${NEXT_VERSION}" -sed --in-place "s/version = '${RELEASE_VERSION}'/version = '${NEXT_VERSION}-SNAPSHOT'/g" build.gradle - -echo "Create commit for version bump to ${NEXT_VERSION}" -git commit -m "Version: bump ${NEXT_VERSION}-SNAPSHOT" build.gradle +${SCRIPT_DIR}/bump-version.sh "${RELEASE_VERSION}" "${NEXT_VERSION}-SNAPSHOT" diff --git a/.github/workflows/bump-version.sh b/.github/workflows/bump-version.sh new file mode 100755 index 00000000000..5f39df82d79 --- /dev/null +++ b/.github/workflows/bump-version.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash +set -e + +if [ "$#" -ne 2 ]; then + echo "Usage: $0 " >&2 + exit 1 +fi + +FROM_VERSION=$1 +TO_VERSION=$2 + +sed --in-place "s/version = '${FROM_VERSION}'/version = '${TO_VERSION}'/g" build.gradle +git commit -m "Version: bump ${TO_VERSION}" build.gradle diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a13b9dabe43..08f68778fdc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -103,7 +103,7 @@ jobs: # This step bumps version numbers in build.gradle and creates git artifacts for the release - name: "Bump version numbers and create release tag" - run: .github/workflows/bump-and-tag.sh + run: .github/workflows/bump-and-tag.sh "${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}" "${{ env.RELEASE_VERSION }}" "${{ env.NEXT_VERSION }}" - name: "Push release branch and tag" run: | From 38e5e63a7c70792430ecb57bd1f9b74f6c3c0a23 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 20 Jun 2024 16:14:32 +0200 Subject: [PATCH 5/7] Change branch creation behaviour for pre-releases --- .github/workflows/release.yml | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08f68778fdc..45e96be1e11 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -45,15 +45,17 @@ jobs: # 5.2.0 => 5.2.1; 5.2.0-beta0 => 5.2.0 # RELEASE_BRANCH: The name of the stable branch for this release series # Example: 5.2.0 => 5.2.x + # Example: 5.2.0-beta1 => run: | echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV echo RELEASE_VERSION_WITHOUT_SUFFIX=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV if [[ "${{ inputs.version }}" =~ (alpha|beta|rc)[0-9]+$ ]]; then echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV + echo RELEASE_BRANCH=${{ github.ref_name }} >> $GITHUB_ENV else echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV + echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV fi - echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV - name: "Ensure current snapshot version matches release version" run: | @@ -88,18 +90,26 @@ jobs: echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }} or master, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY exit 1 + - name: "Set git author information" + run: | + git config user.name "${GIT_AUTHOR_NAME}" + git config user.email "${GIT_AUTHOR_EMAIL}" + # If a non-patch release is created from a branch other than its # maintenance branch, create that branch from the current one and push it + # Pre-releases don't have this behaviour, so we can check the full release + # version including stability suffixes to exclude those - name: "Create new release branch for non-patch release" - if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX, '.0') && env.RELEASE_BRANCH != github.ref_name }} + if: ${{ endsWith(env.RELEASE_VERSION, '.0') && env.RELEASE_BRANCH != github.ref_name }} run: | echo '🆕 Creating new release branch ${{ env.RELEASE_BRANCH }} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY - git checkout -b ${RELEASE_BRANCH} - - - name: "Set git author information" - run: | - git config user.name "${GIT_AUTHOR_NAME}" - git config user.email "${GIT_AUTHOR_EMAIL}" + git checkout -b ${{ env.RELEASE_BRANCH }} + NEXT_MINOR_VERSION=$(echo "${{ env.RELEASE_VERSION }}" | awk -F. -v OFS=. '{$2 += 1 ; $NF = 0 ; print}') + echo '➡️ Bumping version for ${{ github.ref_name }} branch to ${NEXT_MINOR_VERSION}' >> $GITHUB_STEP_SUMMARY + git checkout ${{ github.ref_name }} + .github/workflows/bump-version.sh "${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}-SNAPSHOT" "${NEXT_MINOR_VERSION}-SNAPSHOT" + git push origin ${{ github.ref_name }} + git checkout ${{ env.RELEASE_BRANCH }} # This step bumps version numbers in build.gradle and creates git artifacts for the release - name: "Bump version numbers and create release tag" From 01f2adabb763e4382ed3d45be228e0404ab5fc0e Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Thu, 20 Jun 2024 16:14:48 +0200 Subject: [PATCH 6/7] Use github variables to generate commands This allows us to see the commands as they are run instead of having environment variables in them --- .github/workflows/release.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 45e96be1e11..8277748219d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -59,7 +59,7 @@ jobs: - name: "Ensure current snapshot version matches release version" run: | - grep -q "version = '${RELEASE_VERSION_WITHOUT_SUFFIX}-SNAPSHOT'" build.gradle + grep -q "version = '${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}-SNAPSHOT'" build.gradle if [[ $? != 0 ]]; then echo '❌ Release failed: version in build.gradle is not a snapshot for release version ${{ inputs.version }}' >> $GITHUB_STEP_SUMMARY exit 1 @@ -67,7 +67,7 @@ jobs: - name: "Ensure release tag does not already exist" run: | - if [[ $(git tag -l r${RELEASE_VERSION}) == r${RELEASE_VERSION} ]]; then + if [[ $(git tag -l r${{ env.RELEASE_VERSION }}) == r${{ env.RELEASE_VERSION }} ]]; then echo '❌ Release failed: tag for version ${{ inputs.version }} already exists' >> $GITHUB_STEP_SUMMARY exit 1 fi @@ -117,7 +117,7 @@ jobs: - name: "Push release branch and tag" run: | - git push origin ${RELEASE_BRANCH} + git push origin ${{ env.RELEASE_BRANCH }} git push origin r${{ env.RELEASE_VERSION }} - name: "Create draft release with generated changelog" From 714e4c2dbf8ada7240d6f69c067c78b71098de49 Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Mon, 24 Jun 2024 13:56:00 +0200 Subject: [PATCH 7/7] Fix output when bumping to next minor version --- .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 8277748219d..abc3e3a581e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -105,7 +105,7 @@ jobs: echo '🆕 Creating new release branch ${{ env.RELEASE_BRANCH }} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY git checkout -b ${{ env.RELEASE_BRANCH }} NEXT_MINOR_VERSION=$(echo "${{ env.RELEASE_VERSION }}" | awk -F. -v OFS=. '{$2 += 1 ; $NF = 0 ; print}') - echo '➡️ Bumping version for ${{ github.ref_name }} branch to ${NEXT_MINOR_VERSION}' >> $GITHUB_STEP_SUMMARY + echo "➡️ Bumping version for ${{ github.ref_name }} branch to ${NEXT_MINOR_VERSION}" >> $GITHUB_STEP_SUMMARY git checkout ${{ github.ref_name }} .github/workflows/bump-version.sh "${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}-SNAPSHOT" "${NEXT_MINOR_VERSION}-SNAPSHOT" git push origin ${{ github.ref_name }}