Skip to content

Commit f7e5758

Browse files
authored
PHPORM-205: Automate branch creation when releasing (#3145)
* Automate branch creation when releasing * Apply feedback from code review
1 parent a516427 commit f7e5758

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

.github/workflows/release.yml

+22-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ jobs:
3232
run: |
3333
echo RELEASE_VERSION=${{ inputs.version }} >> $GITHUB_ENV
3434
echo RELEASE_BRANCH=$(echo ${{ inputs.version }} | cut -d '.' -f-2) >> $GITHUB_ENV
35+
echo DEV_BRANCH=$(echo ${{ inputs.version }} | cut -d '.' - f-1).x >> $GITHUB_ENV
3536
3637
- name: "Ensure release tag does not already exist"
3738
run: |
@@ -40,12 +41,31 @@ jobs:
4041
exit 1
4142
fi
4243
43-
- name: "Fail if branch names don't match"
44-
if: ${{ github.ref_name != env.RELEASE_BRANCH }}
44+
# For patch releases (A.B.C where C != 0), we expect the release to be
45+
# triggered from the A.B maintenance branch
46+
- name: "Fail if patch release is created from wrong release branch"
47+
if: ${{ !endsWith(inputs.version, '.0') && env.RELEASE_BRANCH != github.ref_name }}
4548
run: |
4649
echo '❌ Release failed due to branch mismatch: expected ${{ inputs.version }} to be released from ${{ env.RELEASE_BRANCH }}, got ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
4750
exit 1
4851
52+
# For non-patch releases (A.B.C where C == 0), we expect the release to
53+
# be triggered from the A.x maintenance branch or A.x development branch
54+
- name: "Fail if non-patch release is created from wrong release branch"
55+
if: ${{ endsWith(inputs.version, '.0') && env.RELEASE_BRANCH != github.ref_name && env.DEV_BRANCH != github.ref_name }}
56+
run: |
57+
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
58+
exit 1
59+
60+
# If a non-patch release is created from its A.x development branch,
61+
# create the A.B maintenance branch from the current one and push it
62+
- name: "Create and push new release branch for non-patch release"
63+
if: ${{ endsWith(inputs.version, '.0') && env.DEV_BRANCH == github.ref_name }}
64+
run: |
65+
echo '🆕 Creating new release branch ${RELEASE_BRANCH} from ${{ github.ref_name }}' >> $GITHUB_STEP_SUMMARY
66+
git checkout -b ${RELEASE_BRANCH}
67+
git push origin ${RELEASE_BRANCH}
68+
4969
#
5070
# Preliminary checks done - commence the release process
5171
#

0 commit comments

Comments
 (0)