Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: check
on:
push:
branches: [main, master]
tags: ['v*']
pull_request:
branches: [main, master]

Expand Down
81 changes: 43 additions & 38 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,58 @@ name: release

on:
push:
tags: ['v*']
branches: [main, master]

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"
echo "🔍 Checking for version tags in this push to main/master..."

# 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 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 commit hash of the "Version" commit
VERSION_COMMIT=$(git log --oneline -1 --grep="Version" --format="%H")
echo "Found version commit: $VERSION_COMMIT"

# 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=$TAGS_ON_COMMIT" >> $GITHUB_OUTPUT
echo "✅ Version tag found for this commit: $TAGS_ON_COMMIT"
else
echo "⚠️ Version commit found but no tag points to it"
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
fi
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
echo "⚠️ No version commit found in this push"
echo "should_release=false" >> $GITHUB_OUTPUT
exit 0
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
Expand Down Expand Up @@ -91,11 +96,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:
Expand All @@ -106,8 +111,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
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down