Skip to content

Merge pull request #37 from wael-sudo2/fix/setup1 #30

Merge pull request #37 from wael-sudo2/fix/setup1

Merge pull request #37 from wael-sudo2/fix/setup1 #30

name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI
on:
push:
branches:
- main # Change 'main' to your branch name if necessary
jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
steps:
- name: Checkout code
uses: actions/checkout@v3
- 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
- name: Bump version
run: |
current_version=$(grep -oP '(?<=version=").*(?=")' setup.py)
new_version=$(echo $current_version | awk -F. '{$NF = $NF + 1;} 1' | sed 's/ /./g')
sed -i "s/version=\"$current_version\"/version=\"$new_version\"/" setup.py
- name: Build a binary wheel and a source tarball
run: python -m build
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/
continue-on-error: true
- name: Publish distribution 📦 to PyPI
if: github.ref == 'refs/heads/main' && success()
uses: pypa/gh-action-pypi-publish@release/v1
- name: Create GitHub Release
if: github.ref == 'refs/heads/main' && success()
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.bump_version.outputs.new_version }}
release_name: Release ${{ steps.bump_version.outputs.new_version }}
draft: false
prerelease: false