Skip to content

Commit

Permalink
Create python-publish.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
borisbolliet committed Oct 2, 2024
1 parent a4af47d commit 731534a
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
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 bump2version
run: python -m pip install bump2version

- name: Bump version (patch)
run: |
bump2version patch --current-version $(grep -Eo '__version__ = "[^"]*' cmbagent/version.py | cut -d'"' -f2) --new-version $(bump2version --dry-run --list patch | grep new_version | sed -r s,"^.*=",,) cmbagent/version.py
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 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 }}

0 comments on commit 731534a

Please sign in to comment.