|
| 1 | +name: Release |
| 2 | + |
| 3 | +# Trigger the workflow on a release event. |
| 4 | +# This will trigger the workflow when a release is published - so draft releases will not trigger the workflow. |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + |
| 9 | +jobs: |
| 10 | + publish: |
| 11 | + # Name of the job for the workflow. |
| 12 | + name: Publish Package to PyPI |
| 13 | + runs-on: ubuntu-latest |
| 14 | + |
| 15 | + # Get the oidc token with write permissions to upload the package to PyPI. |
| 16 | + # We have configured the trusted OIDC token in the pypi project settings. |
| 17 | + # See here: https://docs.pypi.org/trusted-publishers/using-a-publisher/ |
| 18 | + permissions: |
| 19 | + id-token: write |
| 20 | + attestations: write |
| 21 | + |
| 22 | + # Use the Github Actions Environment to isolate the workflow from the rest of the repository. |
| 23 | + # See here: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment |
| 24 | + environment: |
| 25 | + name: pypi |
| 26 | + url: https://pypi.org/p/nodestream-plugin-dotenv/ |
| 27 | + |
| 28 | + steps: |
| 29 | + # Checkout the repository subject to the release. |
| 30 | + - uses: actions/checkout@v4 |
| 31 | + |
| 32 | + # Install poetry to build the package. |
| 33 | + - name: Install poetry |
| 34 | + run: pipx install poetry |
| 35 | + |
| 36 | + # Set up Python 3.12 to build the package. |
| 37 | + # Python version here does not really matter as long as it works with |
| 38 | + # poetry because its simply building the package. We've confirmed functionality |
| 39 | + # with CI testing before this step. |
| 40 | + - name: Set up Python 3.12 |
| 41 | + uses: actions/setup-python@v5 |
| 42 | + with: |
| 43 | + python-version: 3.12 |
| 44 | + cache: 'poetry' |
| 45 | + |
| 46 | + # Build the package using poetry. This will create a dist directory with the package. |
| 47 | + # Poetry isn't _special_ in the sense that it builds packages in some unique way. |
| 48 | + # Therefore, we can use poetry built packaes with PyPA's action for publishing packages below. |
| 49 | + # See: https://python-poetry.org/docs/cli/#build |
| 50 | + - name: Build Package |
| 51 | + run: poetry build |
| 52 | + |
| 53 | + # Publish the package to PyPI using the OIDC token and PyPA's action for publishing packages. |
| 54 | + # By default, this action will publish to the PyPI server and pull artifacts from the dist directory. |
| 55 | + # Dist directory is where poetry builds the package in the previous step. |
| 56 | + # See: |
| 57 | + # - https://github.com/marketplace/actions/pypi-publish |
| 58 | + # - https://packaging.python.org/en/latest/guides/publishing-package-distribution-releases-using-github-actions-ci-cd-workflows/ |
| 59 | + - name: Publish package distributions to PyPI |
| 60 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 61 | + |
| 62 | + # We are then going to store the built package as an artifact. |
| 63 | + # This is so we can sign the package and upload it to the GitHub release. |
| 64 | + # this is being done as a seperate job so that we can minimize the permissions needed for the publish job. |
| 65 | + - name: Store the Built Package |
| 66 | + uses: actions/upload-artifact@v3 |
| 67 | + with: |
| 68 | + name: python-package-distribution |
| 69 | + path: dist/ |
| 70 | + |
| 71 | + # We are then going to sign the package using Github's Attest Build Provenance action. |
| 72 | + # This action will sign the package and upload the signature to the GitHub release. |
| 73 | + # This is to ensure that the package is verified and trusted by the user. |
| 74 | + - uses: actions/attest-build-provenance@v1 |
| 75 | + with: |
| 76 | + subject-path: 'dist/*' |
0 commit comments