|
| 1 | +# Publish archives to PyPI and TestPyPI using GitHub Actions |
| 2 | +name: Publish to PyPI |
| 3 | + |
| 4 | +# Only run for tagged releases and pushes to the development branch |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: |
| 8 | + - published |
| 9 | + push: |
| 10 | + branches: |
| 11 | + - development |
| 12 | + # Trigger manually at https://github.com/icesat2py/icepyx/actions/workflows/publish_to_pypi.yml |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +jobs: |
| 16 | + publish-pypi: |
| 17 | + name: Publish to PyPI |
| 18 | + runs-on: ubuntu-latest |
| 19 | + if: github.repository == 'icesat2py/icepyx' |
| 20 | + |
| 21 | + steps: |
| 22 | + - name: Checkout |
| 23 | + |
| 24 | + with: |
| 25 | + # fetch all history so that setuptools-scm works |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Set up Python |
| 29 | + |
| 30 | + with: |
| 31 | + python-version: 3.9 |
| 32 | + |
| 33 | + - name: Install dependencies |
| 34 | + run: python -m pip install setuptools wheel |
| 35 | + |
| 36 | + # This step is only necessary for testing purposes and for TestPyPI |
| 37 | + - name: Fix up version string for TestPyPI |
| 38 | + if: ${{ !startsWith(github.ref, 'refs/tags') }} |
| 39 | + run: | |
| 40 | + # Change setuptools-scm local_scheme to "no-local-version" so the |
| 41 | + # local part of the version isn't included, making the version string |
| 42 | + # compatible with PyPI. |
| 43 | + sed --in-place "s/node-and-date/no-local-version/g" setup.py |
| 44 | +
|
| 45 | + - name: Build source and wheel distributions |
| 46 | + run: | |
| 47 | + python setup.py sdist bdist_wheel |
| 48 | + echo "" |
| 49 | + echo "Generated files:" |
| 50 | + ls -lh dist/ |
| 51 | +
|
| 52 | + - name: Publish to Test PyPI |
| 53 | + |
| 54 | + with: |
| 55 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 56 | + repository_url: https://test.pypi.org/legacy/ |
| 57 | + |
| 58 | + - name: Publish to PyPI |
| 59 | + if: startsWith(github.ref, 'refs/tags') |
| 60 | + |
| 61 | + with: |
| 62 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments