|
1 |
| -name: Upload Python Package to PyPI |
| 1 | +name: Publish Python Distribution [PyPi & GH Release | TestPyPi] |
2 | 2 |
|
3 | 3 | on:
|
4 | 4 | push:
|
5 | 5 | branches:
|
6 | 6 | - main
|
| 7 | + tags: |
| 8 | + - '*' |
7 | 9 | workflow_dispatch:
|
8 | 10 |
|
9 | 11 | jobs:
|
10 |
| - deploy: |
| 12 | + prepare-and-check: |
11 | 13 | runs-on: ubuntu-latest
|
12 |
| - |
| 14 | + outputs: |
| 15 | + publish_to_pypi: ${{ steps.version_check.outputs.publish_to_pypi }} |
| 16 | + publish_to_testpypi: ${{ steps.version_check.outputs.publish_to_testpypi }} |
13 | 17 | steps:
|
14 |
| - - uses: actions/checkout@v2 |
| 18 | + - uses: actions/checkout@v4 |
15 | 19 |
|
16 | 20 | - name: Set up Python
|
17 |
| - uses: actions/setup-python@v2 |
| 21 | + uses: actions/setup-python@v5 |
18 | 22 | with:
|
19 | 23 | python-version: '3.x'
|
20 | 24 |
|
21 |
| - - name: Install dependencies |
| 25 | + - name: Install dependencies for version check |
22 | 26 | run: |
|
23 | 27 | python -m pip install --upgrade pip
|
24 |
| - pip install setuptools wheel twine requests |
25 |
| - pip install -r requirements.txt |
| 28 | + pip install requests |
26 | 29 |
|
27 |
| - # Check if the current version is already on PyPI |
28 |
| - - name: Check version on PyPI |
| 30 | + - name: Check version on PyPI or TestPyPI |
29 | 31 | id: version_check
|
30 | 32 | run: |
|
31 |
| - python3 check_version.py |
32 |
| - continue-on-error: true |
| 33 | + python3 check_version.py ${{ github.ref }} |
| 34 | + env: |
| 35 | + GITHUB_OUTPUT: ${{ github.output }} |
| 36 | + |
| 37 | + build-and-publish: |
| 38 | + needs: prepare-and-check |
| 39 | + if: needs.prepare-and-check.outputs.publish_to_pypi == 'true' || needs.prepare-and-check.outputs.publish_to_testpypi == 'true' |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + - name: Set up Python |
| 44 | + uses: actions/setup-python@v5 |
| 45 | + with: |
| 46 | + python-version: '3.x' |
| 47 | + |
| 48 | + - name: Install build dependencies |
| 49 | + run: | |
| 50 | + python -m pip install --upgrade pip |
| 51 | + pip install setuptools wheel twine |
33 | 52 |
|
34 |
| - # Build the package (folder exclusion is handled by MANIFEST.in) |
35 | 53 | - name: Build package
|
36 |
| - if: steps.version_check.outputs.version_exists != 'true' |
37 | 54 | run: |
|
38 | 55 | python setup.py sdist bdist_wheel
|
39 | 56 |
|
40 |
| - - name: Upload to PyPI |
41 |
| - if: steps.version_check.outputs.version_exists != 'true' |
| 57 | + - name: Publish to PyPI |
| 58 | + if: needs.prepare-and-check.outputs.publish_to_pypi == 'true' |
| 59 | + run: twine upload dist/* |
42 | 60 | env:
|
43 | 61 | TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
|
44 | 62 | TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
|
45 |
| - run: | |
46 |
| - twine upload dist/* |
| 63 | + |
| 64 | + - name: Publish to TestPyPI |
| 65 | + if: needs.prepare-and-check.outputs.publish_to_testpypi == 'true' |
| 66 | + run: twine upload --repository-url https://test.pypi.org/legacy/ dist/* |
| 67 | + env: |
| 68 | + TWINE_USERNAME: ${{ secrets.TEST_PYPI_USERNAME }} |
| 69 | + TWINE_PASSWORD: ${{ secrets.TEST_PYPI_PASSWORD }} |
0 commit comments