|
| 1 | +name: "Publish Python Package" |
| 2 | +# Uses: |
| 3 | +# https://github.com/actions/setup-python : a26af69be951a213d495a4c3e4e4022e16d87065 |
| 4 | +# https://github.com/actions/checkout : 11bd71901bbe5b1630ceea73d27597364c9af683 |
| 5 | +# https://github.com/actions/download-artifact : d3f86a106a0bac45b974a628896c90dbdf5c8093 |
| 6 | +# https://github.com/actions/upload-artifact : ea165f8d65b6e75b540449e92b4886f43607fa02 |
| 7 | +# https://github.com/actions/pypa/gh-action-pypi-publish : 76f52bc884231f62b9a034ebfe128415bbaabdfc |
| 8 | + |
| 9 | +on: |
| 10 | + workflow_call: |
| 11 | + inputs: |
| 12 | + runs-on: |
| 13 | + description: "The base runner to use." |
| 14 | + default: "ubuntu-latest" |
| 15 | + required: false |
| 16 | + type: "string" |
| 17 | + python-version: |
| 18 | + description: "Python version to use for all actions." |
| 19 | + default: "3.12" |
| 20 | + required: false |
| 21 | + type: "string" |
| 22 | + build-command: |
| 23 | + description: "Command line to trigger package build." |
| 24 | + default: "python -m pip install build; python -m build" |
| 25 | + required: false |
| 26 | + type: "string" |
| 27 | + build-directory: |
| 28 | + description: "Directory where build artifacts are located." |
| 29 | + default: "./dist" |
| 30 | + required: false |
| 31 | + type: "string" |
| 32 | + index-environment: |
| 33 | + description: "Environment of the packaging index." |
| 34 | + default: "" |
| 35 | + required: true |
| 36 | + type: "string" |
| 37 | + index-package-url: |
| 38 | + description: "URL of the package on the packaging index." |
| 39 | + default: "" |
| 40 | + required: true |
| 41 | + type: "string" |
| 42 | + index-publish-url: |
| 43 | + description: "URL of the packaging index publishing url." |
| 44 | + default: "" |
| 45 | + required: true |
| 46 | + type: "string" |
| 47 | + |
| 48 | +jobs: |
| 49 | + build: |
| 50 | + name: "Build package" |
| 51 | + runs-on: "${{ inputs.runs-on }}" |
| 52 | + outputs: |
| 53 | + artifact-id: "${{ steps.upload-artifact.outputs.artifact-id }}" |
| 54 | + |
| 55 | + steps: |
| 56 | + - uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" |
| 57 | + with: |
| 58 | + persist-credentials: false |
| 59 | + |
| 60 | + - name: "Set up Python" |
| 61 | + uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065" |
| 62 | + with: |
| 63 | + python-version: "${{ inputs.python-version }}" |
| 64 | + |
| 65 | + - name: "Build the package" |
| 66 | + run: "${{ inputs.build-command }}" |
| 67 | + |
| 68 | + - name: "Store the distribution packages" |
| 69 | + id: "upload-artifact" |
| 70 | + uses: "actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02" |
| 71 | + with: |
| 72 | + path: "${{ inputs.build-directory }}" |
| 73 | + |
| 74 | + publish-to-pypi: |
| 75 | + name: "Publish Python Distribution to PyPI" |
| 76 | + needs: ["build"] |
| 77 | + runs-on: "${{ inputs.runs-on }}" |
| 78 | + environment: |
| 79 | + name: "${{ inputs.index-environment }}" |
| 80 | + url: "${{ inputs.index-package-url }}" |
| 81 | + permissions: |
| 82 | + id-token: "write" |
| 83 | + |
| 84 | + steps: |
| 85 | + - name: "Download all the dists" |
| 86 | + uses: "actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093" |
| 87 | + with: |
| 88 | + artifact-ids: "${{ needs.build.outputs.artifact-id }}" |
| 89 | + path: "${{ inputs.build-directory }}" |
| 90 | + merge-multiple: true |
| 91 | + |
| 92 | + - name: "Publish distribution to PyPI" |
| 93 | + uses: "pypa/gh-action-pypi-publish@76f52bc884231f62b9a034ebfe128415bbaabdfc" |
| 94 | + with: |
| 95 | + repository-url: "${{ inputs.index-publish-url }}" |
0 commit comments