|
| 1 | +name: Publish Python 🐍 distribution 📦 to PyPI and TestPyPI |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + build: |
| 9 | + name: Build distribution 📦 |
| 10 | + runs-on: ubuntu-latest |
| 11 | + |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + - name: Set up Python |
| 15 | + uses: actions/setup-python@v4 |
| 16 | + with: |
| 17 | + python-version: "3.10" |
| 18 | + - name: Install pypa/build |
| 19 | + run: python3 -m pip install poetry wheel --user |
| 20 | + - name: Build a binary wheel and a source tarball |
| 21 | + run: python3 -m poetry build |
| 22 | + - name: Store the distribution packages |
| 23 | + uses: actions/upload-artifact@v3 |
| 24 | + with: |
| 25 | + name: python-package-distributions |
| 26 | + path: dist/ |
| 27 | + |
| 28 | + publish-to-pypi: |
| 29 | + name: Publish Python 🐍 distribution 📦 to PyPI |
| 30 | + if: startsWith(github.ref, 'refs/tags/20') # only publish to PyPI on tag pushes |
| 31 | + needs: |
| 32 | + - build |
| 33 | + runs-on: ubuntu-latest |
| 34 | + environment: |
| 35 | + name: pypi |
| 36 | + url: https://pypi.org/p/turbinia |
| 37 | + permissions: |
| 38 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 39 | + |
| 40 | + steps: |
| 41 | + - name: Download all the dists |
| 42 | + uses: actions/download-artifact@v3 |
| 43 | + with: |
| 44 | + name: python-package-distributions |
| 45 | + path: dist/ |
| 46 | + - name: Publish distribution 📦 to PyPI |
| 47 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 48 | + |
| 49 | + github-release: |
| 50 | + name: >- |
| 51 | + Sign the Python 🐍 distribution 📦 with Sigstore |
| 52 | + and upload them to GitHub Release |
| 53 | + needs: |
| 54 | + - publish-to-pypi |
| 55 | + runs-on: ubuntu-latest |
| 56 | + |
| 57 | + permissions: |
| 58 | + contents: write # IMPORTANT: mandatory for making GitHub Releases |
| 59 | + id-token: write # IMPORTANT: mandatory for sigstore |
| 60 | + |
| 61 | + steps: |
| 62 | + - name: Download all the dists |
| 63 | + uses: actions/download-artifact@v3 |
| 64 | + with: |
| 65 | + name: python-package-distributions |
| 66 | + path: dist/ |
| 67 | + - name: Sign the dists with Sigstore |
| 68 | + |
| 69 | + with: |
| 70 | + inputs: >- |
| 71 | + ./dist/*.tar.gz |
| 72 | + ./dist/*.whl |
| 73 | + - name: Upload artifact signatures to GitHub Release |
| 74 | + # Te release must already be created or this will fail. |
| 75 | + env: |
| 76 | + GITHUB_TOKEN: ${{ github.token }} |
| 77 | + # Upload to GitHub Release using the `gh` CLI. |
| 78 | + # `dist/` contains the built packages, and the |
| 79 | + # sigstore-produced signatures and certificates. |
| 80 | + run: >- |
| 81 | + gh release upload |
| 82 | + '${{ github.ref_name }}' dist/** |
| 83 | + --repo '${{ github.repository }}' |
| 84 | +
|
| 85 | + publish-to-testpypi: |
| 86 | + name: Publish Python 🐍 distribution 📦 to TestPyPI |
| 87 | + needs: |
| 88 | + - build |
| 89 | + runs-on: ubuntu-latest |
| 90 | + |
| 91 | + environment: |
| 92 | + name: testpypi |
| 93 | + url: https://test.pypi.org/p/turbinia |
| 94 | + |
| 95 | + permissions: |
| 96 | + id-token: write # IMPORTANT: mandatory for trusted publishing |
| 97 | + |
| 98 | + steps: |
| 99 | + - name: Download all the dists |
| 100 | + uses: actions/download-artifact@v3 |
| 101 | + with: |
| 102 | + name: python-package-distributions |
| 103 | + path: dist/ |
| 104 | + - name: Publish distribution 📦 to TestPyPI |
| 105 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 106 | + with: |
| 107 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments