Skip to content

Auto stash before merge of "main" and "origin/main" #139

Auto stash before merge of "main" and "origin/main"

Auto stash before merge of "main" and "origin/main" #139

# workflow automates the Python package publishing process
# to PyPI upon pushes to the main branch or manual triggers,
# auto-bumps version before publishing.
name: Publish to PyPI
on:
push:
branches:
- main
paths-ignore:
- '**.md'
- 'pyproject.toml'
- 'setup.py'
workflow_dispatch:
permissions:
contents: write
jobs:
deploy:
runs-on: ubuntu-latest
if: github.actor != 'github-actions[bot]'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GH_TOKEN }}
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install poetry
- name: Get current version from PyPI
run: |
current_version=$(pip index versions VedAstro 2>/dev/null | head -1 | grep -oP '\(\K[^)]+' || echo "0.0.0")
echo "CURRENT_VERSION=$current_version" >> $GITHUB_ENV
- name: Bump version
run: |
IFS=. read -r major minor patch <<< "${CURRENT_VERSION}"
patch=$((patch + 1))
new_version="${major}.${minor}.${patch}"
echo "NEW_VERSION=$new_version" >> $GITHUB_ENV
- name: Update version in pyproject.toml
run: |
sed -i "s/^version = \".*\"/version = \"$NEW_VERSION\"/" pyproject.toml
- name: Update version in setup.py
run: |
sed -i "s/version='.*'/version='$NEW_VERSION'/" setup.py
- name: Re-run poetry lockfile
run: poetry lock
- name: Install project dependencies
run: poetry install
- name: Build package
run: poetry build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}
skip-existing: true
- name: Commit version bump
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml setup.py
git commit -m "Auto bump version to $NEW_VERSION"
git push origin main