@@ -32,63 +32,101 @@ jobs:
32
32
- name : " Store version numbers in env variables"
33
33
# The awk command to increase the version number was copied from
34
34
# 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>
35
45
run : |
36
46
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
39
63
40
64
- name : " Ensure release tag does not already exist"
41
65
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
43
67
echo '❌ Release failed: tag for version ${{ inputs.version }} already exists' >> $GITHUB_STEP_SUMMARY
44
68
exit 1
45
69
fi
46
70
47
71
# 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
49
74
- 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 }}
51
76
run : |
52
77
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
53
78
exit 1
54
79
55
80
# 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
57
83
- 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' }}
59
85
run : |
60
86
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
61
87
exit 1
62
88
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
-
71
89
# Set commit author information to the user that triggered the release workflow
72
90
- name : " Set git author information"
73
91
run : |
74
92
GITHUB_USER_NAME=$(gh api users/${{ github.actor }} --jq '.name')
75
93
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}"
77
95
git config user.email "${GITHUB_USER_ID}+${{ github.actor }}@users.noreply.github.com"
78
96
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
+
79
113
# This step bumps version numbers in build.gradle and creates git artifacts for the release
80
114
- 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 }}"
82
116
83
117
- name : " Push release branch and tag"
84
118
run : |
85
- git push origin ${RELEASE_BRANCH}
119
+ git push origin ${{ env. RELEASE_BRANCH } }
86
120
git push origin r${{ env.RELEASE_VERSION }}
87
121
88
122
- name : " Create draft release with generated changelog"
89
123
run : |
124
+ if [[ "${{ inputs.version }}" =~ (alpha|beta|rc) ]]; then
125
+ PRERELEASE="--prerelease --latest=false"
126
+ fi
90
127
echo "RELEASE_URL=$(\
91
128
gh release create r${RELEASE_VERSION} \
129
+ ${PRERELEASE} \
92
130
--target ${{ env.RELEASE_BRANCH }} \
93
131
--title "Java Driver ${{ env.RELEASE_VERSION }} ($(date '+%B %d, %Y'))" \
94
132
--generate-notes \
0 commit comments