Skip to content

Auto Version Bump and Publish #8

Auto Version Bump and Publish

Auto Version Bump and Publish #8

Workflow file for this run

name: Auto Version Bump and Publish
on:
push:
branches: [ main ]
paths:
- 'cpulimiter/**'
- 'setup.py'
- 'pyproject.toml'
workflow_dispatch: # Allow manual trigger
jobs:
bump-version:
if: "!contains(github.event.head_commit.message, '[skip-version]')"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine bump2version setuptools
- name: Configure Git
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
- name: Bump patch version
run: |
# Get current version from setup.py
current_version=$(python setup.py --version)
echo "Current version: $current_version"
# Bump patch version (e.g., 1.0.0 -> 1.0.1)
python -c "
import re
with open('setup.py', 'r') as f:
content = f.read()
version_match = re.search(r'version=\"([^\"]+)\"', content)
if version_match:
old_version = version_match.group(1)
version_parts = old_version.split('.')
version_parts[-1] = str(int(version_parts[-1]) + 1)
new_version = '.'.join(version_parts)
new_content = content.replace(f'version=\"{old_version}\"', f'version=\"{new_version}\"')
with open('setup.py', 'w') as f:
f.write(new_content)
print(f'Updated version from {old_version} to {new_version}')
"
# Update pyproject.toml as well
python -c "
import re
with open('pyproject.toml', 'r') as f:
content = f.read()
version_match = re.search(r'version = \"([^\"]+)\"', content)
if version_match:
old_version = version_match.group(1)
version_parts = old_version.split('.')
version_parts[-1] = str(int(version_parts[-1]) + 1)
new_version = '.'.join(version_parts)
new_content = content.replace(f'version = \"{old_version}\"', f'version = \"{new_version}\"')
with open('pyproject.toml', 'w') as f:
f.write(new_content)
print(f'Updated pyproject.toml version from {old_version} to {new_version}')
"
- name: Get new version
id: version
run: |
new_version=$(python setup.py --version)
echo "new_version=$new_version" >> $GITHUB_OUTPUT
echo "New version: $new_version"
- name: Build package
run: python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*
- name: Commit version bump
run: |
git add setup.py pyproject.toml
git commit -m "🚀 Bump version to ${{ steps.version.outputs.new_version }} [skip-version]"
git tag "v${{ steps.version.outputs.new_version }}"
git push origin main
git push origin "v${{ steps.version.outputs.new_version }}"