Skip to content

Commit f4941fe

Browse files
author
Sam
committed
Add GitHub workflows for automated and manual PyPI publishing; update user-agent test to use regex matcher
1 parent 0a76e8d commit f4941fe

4 files changed

Lines changed: 38 additions & 214 deletions

File tree

.github/workflows/manual-release.yml

Lines changed: 0 additions & 140 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 20 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: Publish to PyPI
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
release:
5+
types: [published]
76

87
permissions:
98
contents: write
@@ -15,8 +14,7 @@ jobs:
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

Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,16 @@ dist: clean ## builds source and wheel package
8585

8686
install: clean ## install the package to the active Python's site-packages
8787
python3 setup.py install
88+
89+
bump-patch: ## bump patch version (0.0.X)
90+
bump2version patch --allow-dirty
91+
92+
bump-minor: ## bump minor version (0.X.0)
93+
bump2version minor --allow-dirty
94+
95+
bump-major: ## bump major version (X.0.0)
96+
bump2version major --allow-dirty
97+
98+
version: ## show current version
99+
@grep -m1 "current_version" setup.cfg | cut -d'=' -f2 | tr -d ' '
100+

setup.cfg

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
[bumpversion]
22
current_version = 0.1.4-beta
33
commit = True
4-
tag = True
4+
tag = False
5+
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(-(?P<release>.+))?
6+
serialize =
7+
{major}.{minor}.{patch}-{release}
8+
{major}.{minor}.{patch}
59

610
[bumpversion:file:setup.py]
711
search = version='{current_version}'

0 commit comments

Comments
 (0)