@@ -32,63 +32,101 @@ jobs:
3232 - name : " Store version numbers in env variables"
3333 # The awk command to increase the version number was copied from
3434 # StackOverflow: https://stackoverflow.com/a/61921674/3959933
35+ # Variables set here:
36+ # RELEASE_VERSION: The version the deployment is expected to create
37+ # RELEASE_VERSION_WITHOUT_SUFFIX: The version without any stability
38+ # suffixes. Example: 5.2.0-beta0 => 5.2.0
39+ # NEXT_VERSION: The next version to be released. For pre-releases, the
40+ # next version is a snapshot of the pre-release version. Examples:
41+ # 5.2.0 => 5.2.1; 5.2.0-beta0 => 5.2.0
42+ # RELEASE_BRANCH: The name of the stable branch for this release series
43+ # Example: 5.2.0 => 5.2.x
44+ # Example: 5.2.0-beta1 => <current branch>
3545 run : |
3646 echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV
37- echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV
38- echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV
47+ echo RELEASE_VERSION_WITHOUT_SUFFIX=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV
48+ if [[ "${{ inputs.version }}" =~ (alpha|beta|rc)[0-9]+$ ]]; then
49+ echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV
50+ echo RELEASE_BRANCH=${{ github.ref_name }} >> $GITHUB_ENV
51+ else
52+ echo NEXT_VERSION=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF += 1 ; print}') >> $GITHUB_ENV
53+ echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | awk -F. -v OFS=. '{$NF = "x" ; print}') >> $GITHUB_ENV
54+ fi
55+
56+ - name : " Ensure current snapshot version matches release version"
57+ run : |
58+ grep -q "version = '${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}-SNAPSHOT'" build.gradle
59+ if [[ $? != 0 ]]; then
60+ echo '❌ Release failed: version in build.gradle is not a snapshot for release version ${{ inputs.version }}' >> $GITHUB_STEP_SUMMARY
61+ exit 1
62+ fi
3963
4064 - name : " Ensure release tag does not already exist"
4165 run : |
42- if [[ $(git tag -l r${RELEASE_VERSION} ) == r${RELEASE_VERSION} ]]; then
66+ if [[ $(git tag -l r${{ env. RELEASE_VERSION }} ) == r${{ env. RELEASE_VERSION } } ]]; then
4367 echo '❌ Release failed: tag for version ${{ inputs.version }} already exists' >> $GITHUB_STEP_SUMMARY
4468 exit 1
4569 fi
4670
4771 # For patch releases (A.B.C where C != 0), we expect the release to be
48- # triggered from the A.B.x maintenance branch
72+ # triggered from the A.B.x maintenance branch. We use the release version
73+ # without suffixes to avoid mistakes when making pre-releases
4974 - name : " Fail if patch release is created from wrong release branch"
50- if : ${{ !endsWith(inputs.version , '.0') && env.RELEASE_BRANCH != github.ref_name }}
75+ if : ${{ !endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX , '.0') && env.RELEASE_BRANCH != github.ref_name }}
5176 run : |
5277 echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
5378 exit 1
5479
5580 # For non-patch releases (A.B.C where C == 0), we expect the release to
56- # be triggered from master or the A.B.x maintenance branch
81+ # be triggered from master or the A.B.x maintenance branch. This includes
82+ # pre-releases for any non-patch releases, e.g. 5.2.0-beta1
5783 - name : " Fail if non-patch release is created from wrong release branch"
58- if : ${{ endsWith(inputs.version , '.0') && env.RELEASE_BRANCH != github.ref_name && github.ref_name != 'master' }}
84+ if : ${{ endsWith(env.RELEASE_VERSION_WITHOUT_SUFFIX , '.0') && env.RELEASE_BRANCH != github.ref_name && github.ref_name != 'master' }}
5985 run : |
6086 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
6187 exit 1
6288
63- # If a non-patch release is created from a branch other than its
64- # maintenance branch, create that branch from the current one and push it
65- - name : " Create new release branch for non-patch release"
66- if : ${{ endsWith(inputs.version, '.0') && env.RELEASE_BRANCH != github.ref_name }}
67- run : |
68- echo '🆕 Creating new release branch ${RELEASE_BRANCH} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
69- git checkout -b ${RELEASE_BRANCH}
70-
7189 # Set commit author information to the user that triggered the release workflow
7290 - name : " Set git author information"
7391 run : |
7492 GITHUB_USER_NAME=$(gh api users/${{ github.actor }} --jq '.name')
7593 GITHUB_USER_ID=$(gh api users/${{ github.actor }} --jq '.id')
76- git config user.name "${GITHUB_USER_NAME}} "
94+ git config user.name "${GITHUB_USER_NAME}"
7795 git config user.email "${GITHUB_USER_ID}+${{ github.actor }}@users.noreply.github.com"
7896
97+ # If a non-patch release is created from a branch other than its
98+ # maintenance branch, create that branch from the current one and push it
99+ # Pre-releases don't have this behaviour, so we can check the full release
100+ # version including stability suffixes to exclude those
101+ - name : " Create new release branch for non-patch release"
102+ if : ${{ endsWith(env.RELEASE_VERSION, '.0') && env.RELEASE_BRANCH != github.ref_name }}
103+ run : |
104+ echo '🆕 Creating new release branch ${{ env.RELEASE_BRANCH }} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
105+ git checkout -b ${{ env.RELEASE_BRANCH }}
106+ NEXT_MINOR_VERSION=$(echo "${{ env.RELEASE_VERSION }}" | awk -F. -v OFS=. '{$2 += 1 ; $NF = 0 ; print}')
107+ echo "➡️ Bumping version for ${{ github.ref_name }} branch to ${NEXT_MINOR_VERSION}" >> $GITHUB_STEP_SUMMARY
108+ git checkout ${{ github.ref_name }}
109+ .github/workflows/bump-version.sh "${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}-SNAPSHOT" "${NEXT_MINOR_VERSION}-SNAPSHOT"
110+ git push origin ${{ github.ref_name }}
111+ git checkout ${{ env.RELEASE_BRANCH }}
112+
79113 # This step bumps version numbers in build.gradle and creates git artifacts for the release
80114 - name : " Bump version numbers and create release tag"
81- run : .github/workflows/bump-and-tag.sh
115+ run : .github/workflows/bump-and-tag.sh "${{ env.RELEASE_VERSION_WITHOUT_SUFFIX }}" "${{ env.RELEASE_VERSION }}" "${{ env.NEXT_VERSION }}"
82116
83117 - name : " Push release branch and tag"
84118 run : |
85- git push origin ${RELEASE_BRANCH}
119+ git push origin ${{ env. RELEASE_BRANCH } }
86120 git push origin r${{ env.RELEASE_VERSION }}
87121
88122 - name : " Create draft release with generated changelog"
89123 run : |
124+ if [[ "${{ inputs.version }}" =~ (alpha|beta|rc) ]]; then
125+ PRERELEASE="--prerelease --latest=false"
126+ fi
90127 echo "RELEASE_URL=$(\
91128 gh release create r${RELEASE_VERSION} \
129+ ${PRERELEASE} \
92130 --target ${{ env.RELEASE_BRANCH }} \
93131 --title "Java Driver ${{ env.RELEASE_VERSION }} ($(date '+%B %d, %Y'))" \
94132 --generate-notes \
0 commit comments