|
| 1 | +# refer to: https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 2 | + |
| 3 | +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI |
| 4 | + |
| 5 | +# NOTE: We do not restrict branches here, |
| 6 | +# instead restrict branches in the `environment` - `pypi`. |
| 7 | +on: |
| 8 | + push: |
| 9 | + tags: |
| 10 | + - v* |
| 11 | + |
| 12 | +jobs: |
| 13 | + lint-test: |
| 14 | + name: Lint check and test 🧪 |
| 15 | + uses: ./.github/workflows/lint-test.yml |
| 16 | + secrets: inherit # IMPORTANT: sub-workflow needs secrets for uploading codecov |
| 17 | + |
| 18 | + build-dist: |
| 19 | + needs: |
| 20 | + - lint-test |
| 21 | + name: Build distribution 📦 |
| 22 | + runs-on: ubuntu-latest |
| 23 | + steps: |
| 24 | + - uses: actions/checkout@v4 |
| 25 | + - name: Set up Python |
| 26 | + uses: actions/setup-python@v4 |
| 27 | + with: |
| 28 | + python-version: "3.10" |
| 29 | + - name: Install dependencies |
| 30 | + run: | |
| 31 | + python -m pip install --upgrade pip |
| 32 | + pip install hatch |
| 33 | + - name: Build a binary wheel and a source tarball |
| 34 | + run: | |
| 35 | + hatch build |
| 36 | + - name: Store the distribution packages |
| 37 | + uses: actions/upload-artifact@v3 |
| 38 | + with: |
| 39 | + name: python-package-distributions |
| 40 | + path: dist/ |
| 41 | + if-no-files-found: error |
| 42 | + |
| 43 | + publish-to-pypi: |
| 44 | + needs: |
| 45 | + - build-dist |
| 46 | + name: Publish Python 🐍 distribution 📦 to PyPI |
| 47 | + runs-on: ubuntu-latest |
| 48 | + environment: |
| 49 | + name: pypi |
| 50 | + url: https://pypi.org/p/fastapi-proxy-lib |
| 51 | + permissions: |
| 52 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 53 | + steps: |
| 54 | + - name: Download all the dists |
| 55 | + uses: actions/download-artifact@v3 |
| 56 | + with: |
| 57 | + name: python-package-distributions |
| 58 | + path: dist/ |
| 59 | + - name: Publish distribution 📦 to PyPI |
| 60 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 61 | + |
| 62 | + github-release: |
| 63 | + needs: |
| 64 | + - publish-to-pypi |
| 65 | + name: Create GitHub release 🏷️ |
| 66 | + runs-on: ubuntu-latest |
| 67 | + permissions: |
| 68 | + contents: write # IMPORTANT: mandatory for creating release |
| 69 | + steps: |
| 70 | + - name: Download all the dists |
| 71 | + uses: actions/download-artifact@v3 |
| 72 | + with: |
| 73 | + name: python-package-distributions |
| 74 | + path: dist/ |
| 75 | + - name: Create release |
| 76 | + uses: ncipollo/release-action@v1 |
| 77 | + with: |
| 78 | + draft: true |
| 79 | + body: ${{ github.event.head_commit.message }} |
| 80 | + artifacts: dist/*.whl,dist/*.tar.gz |
0 commit comments