|
| 1 | +name: Publish to PyPI and TestPyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +jobs: |
| 9 | + check_secrets: |
| 10 | + name: Check secrets |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + ALL: ${{ steps.pypi_api_token.outputs.is_set && steps.test_pypi_api_token.outputs.is_set }} |
| 14 | + PYPI_API_TOKEN: ${{ steps.pypi_api_token.outputs.is_set }} |
| 15 | + TEST_PYPI_API_TOKEN: ${{ steps.test_pypi_api_token.outputs.is_set }} |
| 16 | + steps: |
| 17 | + - |
| 18 | + name: Check PYPI_API_TOKEN |
| 19 | + id: pypi_api_token |
| 20 | + run: | |
| 21 | + echo "is_set: ${{ secrets.PYPI_API_TOKEN != '' }}" |
| 22 | + echo "::set-output name=is_set::${{ secrets.PYPI_API_TOKEN != '' }}" |
| 23 | + - |
| 24 | + name: Check TEST_PYPI_API_TOKEN |
| 25 | + id: test_pypi_api_token |
| 26 | + run: | |
| 27 | + echo "is_set: ${{ secrets.TEST_PYPI_API_TOKEN != '' }}" |
| 28 | + echo "::set-output name=is_set::${{ secrets.TEST_PYPI_API_TOKEN != '' }}" |
| 29 | + build_and_publish: |
| 30 | + name: Build and publish |
| 31 | + runs-on: ubuntu-latest |
| 32 | + needs: |
| 33 | + - check_secrets |
| 34 | + steps: |
| 35 | + - |
| 36 | + name: Checkout |
| 37 | + uses: actions/checkout@v2 |
| 38 | + - |
| 39 | + name: Setup Python |
| 40 | + uses: actions/setup-python@v2 |
| 41 | + with: |
| 42 | + python-version: 3.8 |
| 43 | + architecture: x64 |
| 44 | + - |
| 45 | + name: Build binary wheel and source tarball |
| 46 | + run: | |
| 47 | + python -m pip install wheel packaging |
| 48 | + python setup.py sdist bdist_wheel |
| 49 | + - |
| 50 | + if: ${{ needs.check_secrets.outputs.TEST_PYPI_API_TOKEN == 'true' && github.event.release.prerelease }} |
| 51 | + name: Publish to TestPyPI |
| 52 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 53 | + with: |
| 54 | + packages_dir: ./dist/ |
| 55 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 56 | + repository_url: https://test.pypi.org/legacy/ |
| 57 | + verbose: true |
| 58 | + - |
| 59 | + if: ${{ needs.check_secrets.outputs.PYPI_API_TOKEN == 'true' && !github.event.release.prerelease }} |
| 60 | + name: Publish to PyPI |
| 61 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 62 | + with: |
| 63 | + packages_dir: ./dist/ |
| 64 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 65 | + verbose: true |
0 commit comments