ci: bump version to 4.1.0 #80
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Publish Python Package | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- 'setup.py' | |
jobs: | |
check-version-changed: | |
runs-on: ubuntu-latest | |
outputs: | |
version_changed: ${{ steps.version-change.outputs.version_changed }} | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Fetch all history for all tags and branches | |
run: git fetch --unshallow | |
- name: Check if version changed | |
id: version-change | |
run: | | |
# Get the latest commit on main before the merge | |
MAIN_COMMIT=$(git rev-parse origin/main^1) | |
# Get the version from the main branch before the merge | |
MAIN_VERSION=$(git show "$MAIN_COMMIT:setup.py" | grep -Po "version='\K.*?(?=')") | |
# Get the version from the latest commit on the incoming branch | |
HEAD_VERSION=$(grep -Po "version='\K.*?(?=')" setup.py) | |
echo "Main version: $MAIN_VERSION" | |
echo "Head version: $HEAD_VERSION" | |
# Compare versions | |
if [ "$MAIN_VERSION" != "$HEAD_VERSION" ]; then | |
echo "Version changed" | |
echo "version_changed=true" >> $GITHUB_OUTPUT | |
else | |
echo "Version not changed" | |
echo "version_changed=false" >> $GITHUB_OUTPUT | |
fi | |
publish: | |
needs: check-version-changed | |
if: needs.check-version-changed.outputs.version_changed == 'true' | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out code | |
uses: actions/checkout@v4 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install setuptools wheel twine | |
- name: Build and publish | |
env: | |
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }} | |
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }} | |
run: | | |
python setup.py sdist bdist_wheel | |
twine upload dist/* |