|
| 1 | +name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ '**' ] |
| 6 | + tags-ignore: [ '**' ] |
| 7 | + pull_request: |
| 8 | + release: |
| 9 | + types: |
| 10 | + - published |
| 11 | +jobs: |
| 12 | + |
| 13 | + build_wheels: |
| 14 | + name: Build wheels [${{ matrix.os }}] |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + fail-fast: false |
| 18 | + matrix: |
| 19 | + python-version: |
| 20 | + - 3.8 |
| 21 | + os: |
| 22 | + - ubuntu-20.04 |
| 23 | + # - macos-latest |
| 24 | + # - windows-latest |
| 25 | + |
| 26 | + steps: |
| 27 | + |
| 28 | + - uses: actions/checkout@master |
| 29 | + - run: git fetch --prune --unshallow |
| 30 | + |
| 31 | + - name: Set up Python |
| 32 | + uses: actions/setup-python@v2 |
| 33 | + with: |
| 34 | + python-version: ${{ matrix.python-version }} |
| 35 | + |
| 36 | + - name: Install pypa/build |
| 37 | + run: pip install build |
| 38 | + |
| 39 | + - name: Build wheel and a source tarball |
| 40 | + run: python -m build --sdist --wheel --outdir dist/ . |
| 41 | + |
| 42 | + - name: Archive artifacts |
| 43 | + uses: actions/upload-artifact@v2 |
| 44 | + with: |
| 45 | + name: dist |
| 46 | + path: dist |
| 47 | + |
| 48 | + |
| 49 | + deploy_test_PyPI: |
| 50 | + name: 📦 Deploy to TestPyPI |
| 51 | + runs-on: ubuntu-20.04 |
| 52 | + needs: [build_wheels] |
| 53 | + if: github.ref == 'refs/heads/main' |
| 54 | + steps: |
| 55 | + |
| 56 | + - name: Download artifacts |
| 57 | + uses: actions/download-artifact@v2 |
| 58 | + with: |
| 59 | + name: dist |
| 60 | + path: dist |
| 61 | + |
| 62 | + - name: Publish distribution 📦 to Test PyPI |
| 63 | + uses: pypa/gh-action-pypi-publish@master |
| 64 | + with: |
| 65 | + password: ${{ secrets.TEST_PYPI_API_TOKEN }} |
| 66 | + repository_url: https://test.pypi.org/legacy/ |
| 67 | + |
| 68 | + |
| 69 | + deploy_PyPI: |
| 70 | + name: 📦 Deploy to PyPI |
| 71 | + runs-on: ubuntu-20.04 |
| 72 | + needs: [build_wheels] |
| 73 | + if: startsWith(github.ref, 'refs/tags') |
| 74 | + steps: |
| 75 | + |
| 76 | + - name: Download artifacts |
| 77 | + uses: actions/download-artifact@v2 |
| 78 | + with: |
| 79 | + name: dist |
| 80 | + path: dist |
| 81 | + |
| 82 | + - name: Publish distribution 📦 to PyPI |
| 83 | + uses: pypa/gh-action-pypi-publish@master |
| 84 | + with: |
| 85 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments