From d4fbab7b0f9f45d43b1485e2a9b19af533ea34fb Mon Sep 17 00:00:00 2001 From: jnnsbrr Date: Wed, 24 Sep 2025 12:12:04 +0200 Subject: [PATCH 1/4] improve workflow for actual releases --- .github/workflows/check.yml | 1 - .github/workflows/release.yml | 89 ++++++++++++++++++++--------------- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 7fb7963..064b0c5 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -3,7 +3,6 @@ name: check on: push: branches: [main, master] - tags: ['v*'] pull_request: branches: [main, master] diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f0cb3e2..7c175d5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,53 +2,66 @@ name: release on: push: + branches: [main, master] tags: ['v*'] jobs: - check-tag: + release: runs-on: ubuntu-latest - outputs: - should-release: ${{ steps.check.outputs.should-release }} + permissions: + contents: write + steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 # Fetch all history and tags fetch-tags: true # Ensure all tags are fetched for version resolution + token: ${{ secrets.GITHUB_TOKEN }} - - name: Check if tag is on main/master branch - id: check + - name: Detect version and tag + id: version run: | - # Get the commit that the tag points to - TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref_name }}) - echo "Tag ${{ github.ref_name }} points to commit: $TAG_COMMIT" - - # Check if this commit is reachable from main or master - if git branch -r --contains $TAG_COMMIT | grep -E "(origin/main|origin/master)" > /dev/null; then - echo "✅ Tag ${{ github.ref_name }} is on main/master branch" - echo "should-release=true" >> $GITHUB_OUTPUT + # Check if this is a tag push + if [[ "${{ github.ref }}" == refs/tags/* ]]; then + # Direct tag push - use the tag version + VERSION=${GITHUB_REF#refs/tags/v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "is_tag_push=true" >> $GITHUB_OUTPUT + echo "tag_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT + echo "✅ Direct tag push detected: v$VERSION" else - echo "⚠️ Tag ${{ github.ref_name }} is NOT on main/master branch" - echo "Available branches containing this commit:" - git branch -r --contains $TAG_COMMIT - echo "This release will be skipped for security reasons." - echo "To release, merge your changes to main/master first, then tag from there." - echo "should-release=false" >> $GITHUB_OUTPUT + # Branch push - check if there are new tags + echo "🔍 Checking for new tags in this push..." + + # Get the latest tag + LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + + if [ -n "$LATEST_TAG" ]; then + # Check if this tag was created in this push + if git log --oneline -1 --grep="Version" | grep -q "Version"; then + VERSION=${LATEST_TAG#v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "is_tag_push=false" >> $GITHUB_OUTPUT + echo "tag_name=$LATEST_TAG" >> $GITHUB_OUTPUT + echo "✅ New tag detected in merge: $LATEST_TAG" + else + echo "⚠️ No new version tag found in this push" + echo "should_release=false" >> $GITHUB_OUTPUT + exit 0 + fi + else + echo "⚠️ No tags found in repository" + echo "should_release=false" >> $GITHUB_OUTPUT + exit 0 + fi fi - release: - needs: check-tag - if: needs.check-tag.outputs.should-release == 'true' - runs-on: ubuntu-latest - permissions: - contents: write - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Fetch all history and tags - fetch-tags: true # Ensure all tags are fetched for version resolution + - name: Check if release should proceed + if: steps.version.outputs.should_release == 'false' + run: | + echo "Skipping release - no version tag found" + exit 0 - name: Set up Python uses: actions/setup-python@v5 @@ -91,11 +104,11 @@ jobs: run: | pip install dist/*.whl - - name: Extract version - id: get_version + - name: Display release info run: | - VERSION=${GITHUB_REF#refs/tags/v} - echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "🚀 Releasing version: ${{ steps.version.outputs.version }}" + echo "📦 Tag name: ${{ steps.version.outputs.tag_name }}" + echo "🏷️ Is tag push: ${{ steps.version.outputs.is_tag_push }}" - name: Publish to PyPI env: @@ -106,8 +119,8 @@ jobs: - name: Create Release uses: softprops/action-gh-release@v1 with: - tag_name: ${{ github.ref }} - name: Release of version ${{ steps.get_version.outputs.version }} + tag_name: ${{ steps.version.outputs.tag_name }} + name: Release of version ${{ steps.version.outputs.version }} body: | Changes in this Release - Automated release notes From 8653fe01921cca8dc84914ab97222957c4bc43f6 Mon Sep 17 00:00:00 2001 From: jnnsbrr Date: Wed, 24 Sep 2025 12:21:14 +0200 Subject: [PATCH 2/4] improve workflow for actual releases --- .github/workflows/release.yml | 42 +++++++++++++---------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7c175d5..ad2b0d6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,7 +3,6 @@ name: release on: push: branches: [main, master] - tags: ['v*'] jobs: release: @@ -22,39 +21,28 @@ jobs: - name: Detect version and tag id: version run: | - # Check if this is a tag push - if [[ "${{ github.ref }}" == refs/tags/* ]]; then - # Direct tag push - use the tag version - VERSION=${GITHUB_REF#refs/tags/v} - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "is_tag_push=true" >> $GITHUB_OUTPUT - echo "tag_name=${{ github.ref_name }}" >> $GITHUB_OUTPUT - echo "✅ Direct tag push detected: v$VERSION" - else - # Branch push - check if there are new tags - echo "🔍 Checking for new tags in this push..." - - # Get the latest tag + echo "🔍 Checking for version tags in this push to main/master..." + + # Check if this push contains a commit with "Version" in the message + # This indicates a release was created locally and pushed + if git log --oneline -1 --grep="Version" | grep -q "Version"; then + # Get the latest tag that exists on this branch LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") if [ -n "$LATEST_TAG" ]; then - # Check if this tag was created in this push - if git log --oneline -1 --grep="Version" | grep -q "Version"; then - VERSION=${LATEST_TAG#v} - echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "is_tag_push=false" >> $GITHUB_OUTPUT - echo "tag_name=$LATEST_TAG" >> $GITHUB_OUTPUT - echo "✅ New tag detected in merge: $LATEST_TAG" - else - echo "⚠️ No new version tag found in this push" - echo "should_release=false" >> $GITHUB_OUTPUT - exit 0 - fi + VERSION=${LATEST_TAG#v} + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "tag_name=$LATEST_TAG" >> $GITHUB_OUTPUT + echo "✅ New version tag detected in this push: $LATEST_TAG" else - echo "⚠️ No tags found in repository" + echo "⚠️ Version commit found but no tag detected" echo "should_release=false" >> $GITHUB_OUTPUT exit 0 fi + else + echo "⚠️ No version commit found in this push" + echo "should_release=false" >> $GITHUB_OUTPUT + exit 0 fi - name: Check if release should proceed From 727831958816cd341f74ffad4d39d4028f17a338 Mon Sep 17 00:00:00 2001 From: jnnsbrr Date: Wed, 24 Sep 2025 12:21:22 +0200 Subject: [PATCH 3/4] Version 1.6.3 --- CITATION.cff | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CITATION.cff b/CITATION.cff index 90f5577..10154e5 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,7 +2,7 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'pycoupler: dynamic model coupling of LPJmL' -version: 1.6.2 +version: 1.6.3 date-released: '2025-09-22' abstract: An LPJmL-Python interface for operating LPJmL in a Python environment and coupling it with Python models, programmes or simple programming scripts. From 417f76ac176fec513f7f6b538d5d0f2199733280 Mon Sep 17 00:00:00 2001 From: jnnsbrr Date: Wed, 24 Sep 2025 12:30:35 +0200 Subject: [PATCH 4/4] improve workflow for actual releases --- .github/workflows/release.yml | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ad2b0d6..ac1b581 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,16 +26,20 @@ jobs: # Check if this push contains a commit with "Version" in the message # This indicates a release was created locally and pushed if git log --oneline -1 --grep="Version" | grep -q "Version"; then - # Get the latest tag that exists on this branch - LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "") + # Get the commit hash of the "Version" commit + VERSION_COMMIT=$(git log --oneline -1 --grep="Version" --format="%H") + echo "Found version commit: $VERSION_COMMIT" - if [ -n "$LATEST_TAG" ]; then - VERSION=${LATEST_TAG#v} + # Find tags that point to this specific commit + TAGS_ON_COMMIT=$(git tag --points-at $VERSION_COMMIT | grep "^v" | head -1) + + if [ -n "$TAGS_ON_COMMIT" ]; then + VERSION=${TAGS_ON_COMMIT#v} echo "version=$VERSION" >> $GITHUB_OUTPUT - echo "tag_name=$LATEST_TAG" >> $GITHUB_OUTPUT - echo "✅ New version tag detected in this push: $LATEST_TAG" + echo "tag_name=$TAGS_ON_COMMIT" >> $GITHUB_OUTPUT + echo "✅ Version tag found for this commit: $TAGS_ON_COMMIT" else - echo "⚠️ Version commit found but no tag detected" + echo "⚠️ Version commit found but no tag points to it" echo "should_release=false" >> $GITHUB_OUTPUT exit 0 fi