From 3bd706858afb37ff006c5f67f53cb8f6b82009c8 Mon Sep 17 00:00:00 2001 From: Peter Somhorst Date: Tue, 16 Sep 2025 16:23:12 +0200 Subject: [PATCH 1/2] Update github release workflow --- .github/workflows/release_github.yml | 93 ++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml index 5e558b237..8cb181414 100644 --- a/.github/workflows/release_github.yml +++ b/.github/workflows/release_github.yml @@ -28,7 +28,7 @@ env: jobs: checks: - name: Check requirements + name: Check requirements for PR to be merged runs-on: ubuntu-latest steps: - name: Fail if main branch was selected @@ -102,7 +102,7 @@ jobs: run: python3 -m build merge_and_bump: - name: Merge the changes into main and bump the version + name: Test and apply merging and bumping needs: test_python_releases runs-on: ubuntu-latest outputs: @@ -123,12 +123,6 @@ jobs: git config user.name "GitHub Actions" git config -l - - name: Merge branch into main - run: | - git switch main - git branch -f ${{ github.ref_name }} origin/${{ github.ref_name }} - git merge ${{ github.ref_name }} --no-ff --no-edit - - name: Install Python uses: actions/setup-python@v5.1.1 with: @@ -140,7 +134,70 @@ jobs: python3 -m pip install pyproject-deplister pyproject-deplister --extra dev --path pyproject.toml | grep bump-my-version | sed 's/ //g' | xargs -I{} python3 -m pip install "{}" - - name: Pass Inputs to Shell + - name: Test merging PR into main + run: | + git fetch origin main + git checkout -B temp_main_${{github.ref_name}}_${{github.run_id}} origin/main + git branch -f ${{ github.ref_name }} origin/${{ github.ref_name }} + git merge ${{ github.ref_name }} --no-ff --no-edit + + - name: Test bumping version + id: temp_bump + shell: bash + run: | + bump-my-version bump ${{ inputs.version_level }} --commit --no-tag + ([[ $? -gt 0 ]] && echo "bumped=false" || echo "bumped=true") >> $GITHUB_OUTPUT + + - name: Fail if bumping failes + if: steps.temp_bump.outputs.bumped == 'false' + run: | + echo "Bumping failed on temp branch." + git reset --hard HEAD^ + exit 1 + + - name: Succeed if version is bumped + if: steps.temp_bump.outputs.bumped == 'true' + run: | + echo "Version would be bumped to $(bump-my-version show current_version)!" + + - name: Test merging into develop + run: | + git fetch origin develop + git checkout -B temp_develop_${{github.ref_name}}_${{github.run_id}} origin/develop + git merge temp_main_${{github.ref_name}}_${{github.run_id}} + + - name: Get current main commit hash + id: premerge + run: | + git fetch origin main + echo "hash=$(git rev-parse origin/main)" >> $GITHUB_OUTPUT + + - name: Merge PR + run: | + gh pr merge ${{ github.ref_name }} --merge --delete-branch --squash=false + + - name: Wait for main to update + id: waitmain + run: | + for i in {1..10}; do + git fetch origin main + NEW_HASH=$(git rev-parse origin/main) + if [ "$NEW_HASH" != "${{ steps.premerge.outputs.hash }}" ]; then + echo "Main branch updated." + exit 0 + fi + echo "Waiting for main branch to update..." + sleep 6 + done + echo "Timeout: main branch did not update in time." + exit 1 + + - name: Checkout main + run: | + git switch main + git pull origin main + + - name: Bump version id: bump shell: bash run: | @@ -203,21 +260,3 @@ jobs: --title="Release v${{ needs.merge_and_bump.outputs.new-version }}" \ --generate-notes \ --draft - - remove_branch: - name: Remove PR branch - needs: github_release - if: ${{ github.ref_name != 'develop' }} - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - ref: develop - fetch-depth: 0 - - - name: Remove PR branch - uses: dawidd6/action-delete-branch@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branches: ${{ github.ref_name }} From 445d4cda9de569cf02816680a05c86458060bec5 Mon Sep 17 00:00:00 2001 From: Peter Somhorst Date: Tue, 16 Sep 2025 16:33:58 +0200 Subject: [PATCH 2/2] Add admin flag to merge PR --- .github/workflows/release_github.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release_github.yml b/.github/workflows/release_github.yml index 8cb181414..03dc138e1 100644 --- a/.github/workflows/release_github.yml +++ b/.github/workflows/release_github.yml @@ -174,7 +174,7 @@ jobs: - name: Merge PR run: | - gh pr merge ${{ github.ref_name }} --merge --delete-branch --squash=false + gh pr merge ${{ github.ref_name }} --merge --delete-branch --squash=false --admin - name: Wait for main to update id: waitmain