Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 66 additions & 27 deletions .github/workflows/release_github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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 --admin

- 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: |
Expand Down Expand Up @@ -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 }}
Loading