|
| 1 | +name: PyPI |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + branches: [main] |
| 5 | + push: |
| 6 | + branches: [main] |
| 7 | + release: |
| 8 | + types: [published] |
| 9 | + |
| 10 | +jobs: |
| 11 | + build: |
| 12 | + name: build source distribution |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v3 |
| 16 | + with: |
| 17 | + fetch-depth: 0 |
| 18 | + - uses: actions/setup-python@v4 |
| 19 | + with: |
| 20 | + python-version: 3.8 |
| 21 | + - name: Build the sdist and the wheel |
| 22 | + run: | |
| 23 | + pip install build |
| 24 | + python3 -m build |
| 25 | + - name: Check the sdist installs and imports |
| 26 | + run: | |
| 27 | + mkdir -p test-sdist |
| 28 | + cd test-sdist |
| 29 | + python -m venv venv-sdist |
| 30 | + venv-sdist/bin/python -m pip install ../dist/pymc-experimental*.tar.gz |
| 31 | + echo "Checking import and version number (on release)" |
| 32 | + venv-sdist/bin/python -c "import pymc_experimental as pmx; assert pmx.__version__ == '${{ github.ref_name }}' if '${{ github.ref_type }}' == 'tag' else pmx.__version__; print(pmx.__version__)" |
| 33 | + cd .. |
| 34 | + - name: Check the bdist installs and imports |
| 35 | + run: | |
| 36 | + mkdir -p test-bdist |
| 37 | + cd test-bdist |
| 38 | + python -m venv venv-bdist |
| 39 | + venv-bdist/bin/python -m pip install ../dist/pymc_experimental*.whl |
| 40 | + echo "Checking import and version number (on release)" |
| 41 | + venv-bdist/bin/python -c "import pymc_experimental as pmx; assert pmx.__version__ == '${{ github.ref_name }}' if '${{ github.ref_type }}' == 'tag' else pmx.__version__; print(pmx.__version__)" |
| 42 | + cd .. |
| 43 | + - uses: actions/upload-artifact@v3 |
| 44 | + with: |
| 45 | + name: artifact |
| 46 | + path: dist/* |
| 47 | + test: |
| 48 | + name: upload to test PyPI |
| 49 | + needs: [build] |
| 50 | + runs-on: ubuntu-latest |
| 51 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 52 | + steps: |
| 53 | + - uses: actions/download-artifact@v3 |
| 54 | + with: |
| 55 | + name: artifact |
| 56 | + path: dist |
| 57 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 58 | + with: |
| 59 | + skip_existing: true |
| 60 | + user: __token__ |
| 61 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 62 | + repository_url: https://test.pypi.org/legacy/ |
| 63 | + - uses: actions/setup-python@v4 |
| 64 | + with: |
| 65 | + python-version: 3.8 |
| 66 | + - name: Test pip install from test.pypi |
| 67 | + run: | |
| 68 | + python -m venv venv-test-pypi |
| 69 | + venv-test-pypi/bin/python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple pymc-experimental |
| 70 | + echo "Checking import and version number" |
| 71 | + venv-test-pypi/bin/python -c "import pymc_experimental; assert pymc_experimental.__version__ == '${{ github.ref_name }}'" |
| 72 | +
|
| 73 | + publish: |
| 74 | + name: upload release to PyPI |
| 75 | + needs: [build, test] |
| 76 | + runs-on: ubuntu-latest |
| 77 | + if: github.event_name == 'release' && github.event.action == 'published' |
| 78 | + steps: |
| 79 | + - uses: actions/download-artifact@v3 |
| 80 | + with: |
| 81 | + name: artifact |
| 82 | + path: dist |
| 83 | + - uses: pypa/gh-action-pypi-publish@release/v1 |
| 84 | + with: |
| 85 | + user: __token__ |
| 86 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments