|
| 1 | +name: Publishing |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +jobs: |
| 8 | + # First, run the standard test suite - for this to work correctly, the workflow needs |
| 9 | + # to inherit the organisation secrets used to authenticate to CodeCov. |
| 10 | + # https://github.com/actions/runner/issues/1413 |
| 11 | + test: |
| 12 | + uses: ./.github/workflows/ci.yml |
| 13 | + secrets: inherit |
| 14 | + |
| 15 | + # Next, build the package wheel and source releases and add them to the release assets |
| 16 | + build-wheel: |
| 17 | + needs: test |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - uses: actions/checkout@v4 |
| 21 | + |
| 22 | + # Build the package - this could use `poetry build` directly but pyproject.toml |
| 23 | + # already has the build-system configured to use poetry so `pip` should pick that |
| 24 | + # up automatically. |
| 25 | + - name: Build sdist |
| 26 | + run: | |
| 27 | + python -m pip install --upgrade build |
| 28 | + python -m build |
| 29 | +
|
| 30 | + # Upload the build outputs as job artifacts - these will be two files with x.y.z |
| 31 | + # version numbers: |
| 32 | + # - virtual_ecosystem-x.y.z-py3-none-any.whl |
| 33 | + # - virtual_ecosystem-x.y.z.tar.gz |
| 34 | + - uses: actions/upload-artifact@v4 |
| 35 | + with: |
| 36 | + path: dist/virtual_ecosystem* |
| 37 | + |
| 38 | + # Add the built files to the release assets, alongside the repo archives |
| 39 | + # automatically added by GitHub. These files should then match exactly to the |
| 40 | + # published files on PyPI. |
| 41 | + - uses: softprops/action-gh-release@v1 |
| 42 | + with: |
| 43 | + files: dist/virtual_ecosystem* |
| 44 | + |
| 45 | + # Now attempt to publish the package to the TestPyPI site, where the virtual_ecosystem |
| 46 | + # project has been configured to allow trusted publishing from this repo and workflow. |
| 47 | + # |
| 48 | + # The skip-existing option allows the publication step to pass even when the release |
| 49 | + # files already exists on PyPI. That suggests something has gone wrong with the |
| 50 | + # release or the build file staging and the release should not be allowed to continue |
| 51 | + # to publish on PyPI. |
| 52 | + |
| 53 | + publish-TestPyPI: |
| 54 | + needs: build-wheel |
| 55 | + name: Publish virtual_ecosystem to TestPyPI |
| 56 | + runs-on: ubuntu-latest |
| 57 | + permissions: |
| 58 | + id-token: write |
| 59 | + |
| 60 | + steps: |
| 61 | + # Download the built package files from the job artifacts |
| 62 | + - name: Download sdist artifact |
| 63 | + uses: actions/download-artifact@v4 |
| 64 | + with: |
| 65 | + name: artifact |
| 66 | + path: dist |
| 67 | + |
| 68 | + # Information step to show the contents of the job artifacts |
| 69 | + - name: Display structure of downloaded files |
| 70 | + run: ls -R dist |
| 71 | + |
| 72 | + # Use trusted publishing to release the files downloaded into dist to TestPyPI |
| 73 | + - name: Publish package distributions to TestPyPI |
| 74 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 75 | + with: |
| 76 | + repository-url: https://test.pypi.org/legacy/ |
| 77 | + # skip-existing: true |
| 78 | + |
| 79 | + # The final job in the workflow is to publish to the real PyPI as long as the release |
| 80 | + # name does not contain the tag 'test-pypi-only' |
| 81 | + publish-PyPI: |
| 82 | + if: ${{ ! contains(github.event.release.name, 'test-pypi-only')}} |
| 83 | + needs: publish-TestPyPI |
| 84 | + name: Publish virtual_ecosystem to PyPI |
| 85 | + runs-on: ubuntu-latest |
| 86 | + permissions: |
| 87 | + id-token: write |
| 88 | + |
| 89 | + steps: |
| 90 | + # Download the built package files from the job artifacts |
| 91 | + - name: Download sdist artifact |
| 92 | + uses: actions/download-artifact@v4 |
| 93 | + with: |
| 94 | + name: artifact |
| 95 | + path: dist |
| 96 | + |
| 97 | + # Information step to show the contents of the job artifacts |
| 98 | + - name: Display structure of downloaded files |
| 99 | + run: ls -R dist |
| 100 | + |
| 101 | + # Use trusted publishing to release the files downloaded into dist to PyPI |
| 102 | + - name: Publish package distributions to PyPI |
| 103 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments