Skip to content

Commit

Permalink
Update publish-to-test-pypi.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
wael-sudo2 authored Sep 30, 2024
1 parent a4ac19a commit 041e0b0
Showing 1 changed file with 25 additions and 46 deletions.
71 changes: 25 additions & 46 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,50 +10,29 @@ jobs:
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

id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10" # Use a specific version of Python

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Bump version
id: bump_version # Set an id to refer to this step's output
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
echo "::set-output name=new_version::$new_version" # Set new_version as an output
- 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: false # Catch errors if any

- name: Publish distribution 📦 to PyPI
if: github.ref == 'refs/heads/main' && always()
uses: pypa/gh-action-pypi-publish@release/v1

- name: Create GitHub Release
if: github.ref == 'refs/heads/main' && always()
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.bump_version.outputs.new_version }} # Reference the bumped version
release_name: Release ${{ steps.bump_version.outputs.new_version }}
draft: false
prerelease: false
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"

- name: Install pypa/build
run: python -m pip install build

- name: Build a binary wheel and a source tarball
run: python -m build --sdist --wheel --outdir dist/

- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/

- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}

0 comments on commit 041e0b0

Please sign in to comment.