11name : Publish to PyPI
22
33on :
4- push :
5- branches :
6- - main
4+ release :
5+ types : [published]
76
87permissions :
98 contents : write
1514 - name : Checkout code
1615 uses : actions/checkout@v4
1716 with :
18- fetch-depth : 0
19- token : ${{ secrets.GITHUB_TOKEN }}
17+ ref : ${{ github.event.release.tag_name }}
2018
2119 - name : Set up Python
2220 uses : actions/setup-python@v5
@@ -32,62 +30,25 @@ jobs:
3230 - name : Run tests
3331 run : python -m unittest discover -s tests -v
3432
35- - name : Configure git
33+ - name : Verify version matches tag
3634 run : |
37- git config user.name "github-actions[bot]"
38- git config user.email "github-actions[bot]@users.noreply.github.com"
35+ TAG="${{ github.event.release.tag_name }}"
36+ # Remove 'v' prefix if present
37+ TAG_VERSION="${TAG#v}"
3938
40- - name : Get current version
41- id : get_version
42- run : |
43- VERSION=$(python -c "import re; content=open('setup.py').read(); print(re.search(r\"version='([^']+)'\", content).group(1))")
44- echo "current_version=$VERSION" >> $GITHUB_OUTPUT
45-
46- - name : Bump version
47- id : bump_version
48- run : |
49- CURRENT_VERSION="${{ steps.get_version.outputs.current_version }}"
50-
51- # Extract version parts (handles versions like 0.1.4-beta)
52- BASE_VERSION=$(echo "$CURRENT_VERSION" | sed -E 's/(-[a-zA-Z0-9]+)?$//')
53- SUFFIX=$(echo "$CURRENT_VERSION" | grep -oE '\-[a-zA-Z0-9]+$' || echo "")
54-
55- # Split into major.minor.patch
56- IFS='.' read -r MAJOR MINOR PATCH <<< "$BASE_VERSION"
57-
58- # Bump patch version
59- NEW_PATCH=$((PATCH + 1))
60- NEW_VERSION="${MAJOR}.${MINOR}.${NEW_PATCH}${SUFFIX}"
61-
62- echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
63- echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
64-
65- - name : Update version in files
66- run : |
67- NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
68-
69- # Update setup.py
70- sed -i "s/version='[^']*'/version='$NEW_VERSION'/" setup.py
71-
72- # Update __init__.py
73- sed -i "s/__version__ = '[^']*'/__version__ = '$NEW_VERSION'/" ujeebu_python/__init__.py
74-
75- # Show changes
76- echo "Updated version to $NEW_VERSION"
77- git diff
39+ # Get version from setup.py
40+ SETUP_VERSION=$(python -c "import re; content=open('setup.py').read(); print(re.search(r\"version='([^']+)'\", content).group(1))")
7841
79- - name : Commit version bump
80- run : |
81- NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
82- git add setup.py ujeebu_python/__init__.py
83- git commit -m "Bump version to $NEW_VERSION [skip ci]"
84- git push
42+ if [ "$TAG_VERSION" != "$SETUP_VERSION" ]; then
43+ echo "❌ Version mismatch!"
44+ echo " Tag version: $TAG_VERSION"
45+ echo " setup.py version: $SETUP_VERSION"
46+ echo ""
47+ echo "Please update the version in setup.py and ujeebu_python/__init__.py before releasing."
48+ exit 1
49+ fi
8550
86- - name : Create and push tag
87- run : |
88- NEW_VERSION="${{ steps.bump_version.outputs.new_version }}"
89- git tag -a "v$NEW_VERSION" -m "Release v$NEW_VERSION"
90- git push origin "v$NEW_VERSION"
51+ echo "✅ Version matches: $TAG_VERSION"
9152
9253 - name : Build package
9354 run : python -m build
@@ -98,24 +59,10 @@ jobs:
9859 TWINE_PASSWORD : ${{ secrets.PYPI_API_TOKEN }}
9960 run : twine upload dist/*
10061
101- - name : Create GitHub Release
62+ - name : Upload release assets
10263 uses : softprops/action-gh-release@v1
10364 with :
104- tag_name : v${{ steps.bump_version.outputs.new_version }}
105- name : Release v${{ steps.bump_version.outputs.new_version }}
106- body : |
107- ## Release v${{ steps.bump_version.outputs.new_version }}
108-
109- This release was automatically generated.
110-
111- ### Installation
112- ```bash
113- pip install ujeebu_python==${{ steps.bump_version.outputs.new_version }}
114- ```
115- draft : false
116- prerelease : ${{ contains(steps.bump_version.outputs.new_version, 'beta') || contains(steps.bump_version.outputs.new_version, 'alpha') }}
117- files : |
118- dist/*
65+ files : dist/*
11966 env :
12067 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
12168
0 commit comments