@@ -2,53 +2,66 @@ name: release
22
33on :
44 push :
5+ branches : [main, master]
56 tags : ['v*']
67
78jobs :
8- check-tag :
9+ release :
910 runs-on : ubuntu-latest
10- outputs :
11- should-release : ${{ steps.check.outputs.should-release }}
11+ permissions :
12+ contents : write
13+
1214 steps :
1315 - name : Checkout code
1416 uses : actions/checkout@v4
1517 with :
1618 fetch-depth : 0 # Fetch all history and tags
1719 fetch-tags : true # Ensure all tags are fetched for version resolution
20+ token : ${{ secrets.GITHUB_TOKEN }}
1821
19- - name : Check if tag is on main/master branch
20- id : check
22+ - name : Detect version and tag
23+ id : version
2124 run : |
22- # Get the commit that the tag points to
23- TAG_COMMIT=$(git rev-list -n 1 ${{ github.ref_name }})
24- echo "Tag ${{ github.ref_name }} points to commit: $TAG_COMMIT"
25-
26- # Check if this commit is reachable from main or master
27- if git branch -r --contains $TAG_COMMIT | grep -E "(origin/main|origin/master) " > /dev/null; then
28- echo "✅ Tag ${{ github.ref_name }} is on main/master branch"
29- echo "should-release=true" >> $GITHUB_OUTPUT
25+ # Check if this is a tag push
26+ if [[ " ${{ github.ref }}" == refs/tags/* ]]; then
27+ # Direct tag push - use the tag version
28+ VERSION=${GITHUB_REF#refs/tags/v}
29+ echo "version=$VERSION" >> $GITHUB_OUTPUT
30+ echo "is_tag_push=true " >> $GITHUB_OUTPUT
31+ echo "tag_name= ${{ github.ref_name }}" >> $GITHUB_OUTPUT
32+ echo "✅ Direct tag push detected: v$VERSION"
3033 else
31- echo "⚠️ Tag ${{ github.ref_name }} is NOT on main/master branch"
32- echo "Available branches containing this commit:"
33- git branch -r --contains $TAG_COMMIT
34- echo "This release will be skipped for security reasons."
35- echo "To release, merge your changes to main/master first, then tag from there."
36- echo "should-release=false" >> $GITHUB_OUTPUT
34+ # Branch push - check if there are new tags
35+ echo "🔍 Checking for new tags in this push..."
36+
37+ # Get the latest tag
38+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
39+
40+ if [ -n "$LATEST_TAG" ]; then
41+ # Check if this tag was created in this push
42+ if git log --oneline -1 --grep="Version" | grep -q "Version"; then
43+ VERSION=${LATEST_TAG#v}
44+ echo "version=$VERSION" >> $GITHUB_OUTPUT
45+ echo "is_tag_push=false" >> $GITHUB_OUTPUT
46+ echo "tag_name=$LATEST_TAG" >> $GITHUB_OUTPUT
47+ echo "✅ New tag detected in merge: $LATEST_TAG"
48+ else
49+ echo "⚠️ No new version tag found in this push"
50+ echo "should_release=false" >> $GITHUB_OUTPUT
51+ exit 0
52+ fi
53+ else
54+ echo "⚠️ No tags found in repository"
55+ echo "should_release=false" >> $GITHUB_OUTPUT
56+ exit 0
57+ fi
3758 fi
3859
39- release :
40- needs : check-tag
41- if : needs.check-tag.outputs.should-release == 'true'
42- runs-on : ubuntu-latest
43- permissions :
44- contents : write
45-
46- steps :
47- - name : Checkout code
48- uses : actions/checkout@v4
49- with :
50- fetch-depth : 0 # Fetch all history and tags
51- fetch-tags : true # Ensure all tags are fetched for version resolution
60+ - name : Check if release should proceed
61+ if : steps.version.outputs.should_release == 'false'
62+ run : |
63+ echo "Skipping release - no version tag found"
64+ exit 0
5265
5366 - name : Set up Python
5467 uses : actions/setup-python@v5
@@ -91,11 +104,11 @@ jobs:
91104 run : |
92105 pip install dist/*.whl
93106
94- - name : Extract version
95- id : get_version
107+ - name : Display release info
96108 run : |
97- VERSION=${GITHUB_REF#refs/tags/v}
98- echo "version=$VERSION" >> $GITHUB_OUTPUT
109+ echo "🚀 Releasing version: ${{ steps.version.outputs.version }}"
110+ echo "📦 Tag name: ${{ steps.version.outputs.tag_name }}"
111+ echo "🏷️ Is tag push: ${{ steps.version.outputs.is_tag_push }}"
99112
100113 - name : Publish to PyPI
101114 env :
@@ -106,8 +119,8 @@ jobs:
106119 - name : Create Release
107120 uses : softprops/action-gh-release@v1
108121 with :
109- tag_name : ${{ github.ref }}
110- name : Release of version ${{ steps.get_version .outputs.version }}
122+ tag_name : ${{ steps.version.outputs.tag_name }}
123+ name : Release of version ${{ steps.version .outputs.version }}
111124 body : |
112125 Changes in this Release
113126 - Automated release notes
0 commit comments