From 6242ffffde1d694d0d859f214b4322099c3555de Mon Sep 17 00:00:00 2001 From: Joseph Hughes Date: Sat, 5 Sep 2026 07:39:09 -0500 Subject: [PATCH] ci(release): do not repeat a release that is already underway Preparing a release triggered on any push to the release branch, so hand-editing the generated changelog on that branch prepended a second section for the same version and failed trying to open a pull request that already existed. The release is now prepared only when the release branch is first pushed, leaving the branch open to corrections before it is merged. Skipping an already released version reported success, so a later push to main would attempt to upload the same version to PyPI again and open a second pull request resetting develop. The release job now reports whether it created a release, and the publish and reset jobs check it. --- .github/workflows/release.yml | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bcb1b38..d34cfd4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,8 +44,9 @@ jobs: prep: name: Prepare release - # runs on workflow_dispatch, or when a release branch is pushed - if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name != 'main') }} + # runs on workflow_dispatch, or when a release branch is first pushed. + # later pushes to the release branch must not prepare the release again. + if: ${{ github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.ref_name != 'main' && github.event.created) }} runs-on: ubuntu-latest permissions: contents: write @@ -195,6 +196,7 @@ jobs: shell: bash outputs: version: ${{ steps.release.outputs.version }} + released: ${{ steps.release.outputs.released }} steps: - name: Checkout main branch @@ -214,8 +216,10 @@ jobs: # skip if this version has already been released if git rev-parse -q --verify "refs/tags/$version" >/dev/null; then echo "tag $version already exists, nothing to release" + echo "released=false" >> $GITHUB_OUTPUT exit 0 fi + echo "released=true" >> $GITHUB_OUTPUT # pull this release's notes back out of the cumulative changelog notes=$(awk -v hdr="### Version $version" ' @@ -233,7 +237,7 @@ jobs: name: Publish package # runs after the release is created, or after a draft release is published manually needs: release - if: ${{ always() && github.repository_owner == 'MODFLOW-ORG' && ((github.event_name == 'push' && needs.release.result == 'success') || github.event_name == 'release') }} + if: ${{ always() && github.repository_owner == 'MODFLOW-ORG' && ((github.event_name == 'push' && needs.release.outputs.released == 'true') || github.event_name == 'release') }} runs-on: ubuntu-latest permissions: contents: read @@ -275,7 +279,7 @@ jobs: name: Reset develop # runs after the release is created, opens a PR merging main back into develop needs: release - if: ${{ github.event_name == 'push' && github.ref_name == 'main' }} + if: ${{ github.event_name == 'push' && github.ref_name == 'main' && needs.release.outputs.released == 'true' }} runs-on: ubuntu-latest permissions: contents: write