Skip to content

Commit 63239c7

Browse files
committed
Support creating release branches when releasing new versions
1 parent d216a5b commit 63239c7

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

.github/workflows/release.yml

+24-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ jobs:
5757
- name: "Store version numbers in env variables"
5858
run: |
5959
echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV
60+
echo RELEASE_VERSION_WITHOUT_STABILITY=$(echo ${{ inputs.version }} | awk -F- '{print $1}') >> $GITHUB_ENV
6061
echo RELEASE_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-2) >> $GITHUB_ENV
62+
echo DEVELOPMENT_BRANCH=v$(echo ${{ inputs.version }} | cut -d '.' -f-1).x >> $GITHUB_ENV
6163
6264
- name: "Ensure release tag does not already exist"
6365
run: |
@@ -66,16 +68,35 @@ jobs:
6668
exit 1
6769
fi
6870
69-
- name: "Fail if branch names don't match"
70-
if: ${{ github.ref_name != env.RELEASE_BRANCH }}
71+
# For patch releases (A.B.C where C != 0), we expect the release to be
72+
# triggered from the vA.B release branch
73+
- name: "Fail if patch release is created from wrong release branch"
74+
if: ${{ !endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name }}
7175
run: |
7276
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
7377
exit 1
7478
79+
# For non-patch releases (A.B.C where C == 0), we expect the release to
80+
# be triggered from the vA.x development branch or the vA.B release branch.
81+
# This includes pre-releases (e.g. alpha, beta, rc)
82+
- name: "Fail if non-patch release is created from wrong release branch"
83+
if: ${{ endsWith(env.RELEASE_VERSION_WITHOUT_STABILITY, '.0') && env.RELEASE_BRANCH != github.ref_name && env.DEVELOPMENT_BRANCH != github.ref_name }}
84+
run: |
85+
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
86+
exit 1
87+
7588
#
7689
# Preliminary checks done - commence the release process
7790
#
7891

92+
# Create the new release branch if we're releasing from the vA.x
93+
# development branch
94+
- name: "Create new release branch"
95+
if: ${{ github.ref_name != env.RELEASE_BRANCH }}
96+
run: |
97+
git checkout -b ${{ env.RELEASE_BRANCH }}
98+
git push origin ${{ env.RELEASE_BRANCH }}
99+
79100
- name: "Set up drivers-github-tools"
80101
uses: mongodb-labs/drivers-github-tools/setup@v2
81102
with:
@@ -90,7 +111,7 @@ jobs:
90111
EOL
91112
92113
- name: "Create draft release"
93-
run: echo "RELEASE_URL=$(gh release create ${{ inputs.version }} --target ${{ github.ref_name }} --title "${{ inputs.version }}" --notes-file release-message --draft)" >> "$GITHUB_ENV"
114+
run: echo "RELEASE_URL=$(gh release create ${{ inputs.version }} --target ${{ env.RELEASE_BRANCH }} --title "${{ inputs.version }}" --notes-file release-message --draft)" >> "$GITHUB_ENV"
94115

95116
- name: "Create release tag"
96117
uses: mongodb-labs/drivers-github-tools/tag-version@v2

0 commit comments

Comments
 (0)