2828
2929jobs :
3030 checks :
31- name : Check requirements
31+ name : Check requirements for PR to be merged
3232 runs-on : ubuntu-latest
3333 steps :
3434 - name : Fail if main branch was selected
@@ -102,7 +102,7 @@ jobs:
102102 run : python3 -m build
103103
104104 merge_and_bump :
105- name : Merge the changes into main and bump the version
105+ name : Test and apply merging and bumping
106106 needs : test_python_releases
107107 runs-on : ubuntu-latest
108108 outputs :
@@ -123,12 +123,6 @@ jobs:
123123 git config user.name "GitHub Actions"
124124 git config -l
125125
126- - name : Merge branch into main
127- run : |
128- git switch main
129- git branch -f ${{ github.ref_name }} origin/${{ github.ref_name }}
130- git merge ${{ github.ref_name }} --no-ff --no-edit
131-
132126 - name : Install Python
133127 uses : actions/setup-python@v5.1.1
134128 with :
@@ -140,7 +134,70 @@ jobs:
140134 python3 -m pip install pyproject-deplister
141135 pyproject-deplister --extra dev --path pyproject.toml | grep bump-my-version | sed 's/ //g' | xargs -I{} python3 -m pip install "{}"
142136
143- - name : Pass Inputs to Shell
137+ - name : Test merging PR into main
138+ run : |
139+ git fetch origin main
140+ git checkout -B temp_main_${{github.ref_name}}_${{github.run_id}} origin/main
141+ git branch -f ${{ github.ref_name }} origin/${{ github.ref_name }}
142+ git merge ${{ github.ref_name }} --no-ff --no-edit
143+
144+ - name : Test bumping version
145+ id : temp_bump
146+ shell : bash
147+ run : |
148+ bump-my-version bump ${{ inputs.version_level }} --commit --no-tag
149+ ([[ $? -gt 0 ]] && echo "bumped=false" || echo "bumped=true") >> $GITHUB_OUTPUT
150+
151+ - name : Fail if bumping failes
152+ if : steps.temp_bump.outputs.bumped == 'false'
153+ run : |
154+ echo "Bumping failed on temp branch."
155+ git reset --hard HEAD^
156+ exit 1
157+
158+ - name : Succeed if version is bumped
159+ if : steps.temp_bump.outputs.bumped == 'true'
160+ run : |
161+ echo "Version would be bumped to $(bump-my-version show current_version)!"
162+
163+ - name : Test merging into develop
164+ run : |
165+ git fetch origin develop
166+ git checkout -B temp_develop_${{github.ref_name}}_${{github.run_id}} origin/develop
167+ git merge temp_main_${{github.ref_name}}_${{github.run_id}}
168+
169+ - name : Get current main commit hash
170+ id : premerge
171+ run : |
172+ git fetch origin main
173+ echo "hash=$(git rev-parse origin/main)" >> $GITHUB_OUTPUT
174+
175+ - name : Merge PR
176+ run : |
177+ gh pr merge ${{ github.ref_name }} --merge --delete-branch --squash=false
178+
179+ - name : Wait for main to update
180+ id : waitmain
181+ run : |
182+ for i in {1..10}; do
183+ git fetch origin main
184+ NEW_HASH=$(git rev-parse origin/main)
185+ if [ "$NEW_HASH" != "${{ steps.premerge.outputs.hash }}" ]; then
186+ echo "Main branch updated."
187+ exit 0
188+ fi
189+ echo "Waiting for main branch to update..."
190+ sleep 6
191+ done
192+ echo "Timeout: main branch did not update in time."
193+ exit 1
194+
195+ - name : Checkout main
196+ run : |
197+ git switch main
198+ git pull origin main
199+
200+ - name : Bump version
144201 id : bump
145202 shell : bash
146203 run : |
@@ -203,21 +260,3 @@ jobs:
203260 --title="Release v${{ needs.merge_and_bump.outputs.new-version }}" \
204261 --generate-notes \
205262 --draft
206-
207- remove_branch :
208- name : Remove PR branch
209- needs : github_release
210- if : ${{ github.ref_name != 'develop' }}
211- runs-on : ubuntu-latest
212- steps :
213- - name : Checkout repository
214- uses : actions/checkout@v4
215- with :
216- ref : develop
217- fetch-depth : 0
218-
219- - name : Remove PR branch
220- uses : dawidd6/action-delete-branch@v3
221- with :
222- github_token : ${{ secrets.GITHUB_TOKEN }}
223- branches : ${{ github.ref_name }}
0 commit comments