Skip to content

Upload Python Package to PyPi #2

Upload Python Package to PyPi

Upload Python Package to PyPi #2

name: Upload Python Package to PyPi
on:
# push:
# branches:
# - main
workflow_dispatch:
release:
types: [published]
permissions: # Ensure the workflow has permission to push changes
contents: write # Allow write access for pushing to the repository
jobs:
bump_version:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
with:
persist-credentials: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install dependencies
run: python -m pip install -r requirements.txt # Install other dependencies if needed
- name: Bump beta version
run: |
VERSION_FILE="cmbagent/version.py"
current_version=$(grep -Eo '__version__ = "[^"]*' "$VERSION_FILE" | cut -d'"' -f2)
if [[ $current_version =~ ^([0-9]+)\.([0-9]+)\.([0-9]+)\.beta([0-9]+)$ ]]; then
major="${BASH_REMATCH[1]}"
minor="${BASH_REMATCH[2]}"
patch="${BASH_REMATCH[3]}"
beta="${BASH_REMATCH[4]}"
# Increment the beta version
new_beta=$((beta + 1))
new_version="${major}.${minor}.${patch}.beta${new_beta}"
# Update the version in version.py
sed -i "s/__version__ = \"$current_version\"/__version__ = \"$new_version\"/" "$VERSION_FILE"
echo "Version bumped to: $new_version"
else
echo "Current version format is not valid for beta versioning."
exit 1
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Commit and push version bump
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add cmbagent/version.py
git commit -m "Bump beta version to $new_version"
git push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
deploy:
needs: bump_version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build
- name: Build package
run: python -m build
- name: Publish package
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
with:
user: __token__
password: ${{ secrets.PYPI_API_TOKEN }}