1414
1515env :
1616 # Common versions
17- PYTHON_VERSION : ' 3.12.11' # TODO: Used?
17+ PYTHON_VERSION : ' 3.13.7' # TODO: Used?
18+ HATCH_VERSION : ' 1.12.0'
1819 DOCKER_BUILDX_VERSION : ' v0.26.1'
1920
2021 # These environment variables are important to the Crossplane CLI install.sh
3233 # XPKG: xpkg.upbound.io/${{ github.repository}}
3334 CROSSPLANE_REGORG : ghcr.io/${{ github.repository}}
3435
36+ # The PyPi project version to push. The default is v0.0.0+gitdate-gitsha.
37+ PYPI_VERSION : ${{ inputs.version }}
38+
3539 # The package version to push. The default is 0.0.0-gitsha.
3640 XPKG_VERSION : ${{ inputs.version }}
3741
@@ -86,11 +90,49 @@ jobs:
8690 # remove-link-from-badge: false
8791 # unique-id-for-comment: python3.8
8892
93+ build-pypi :
94+ runs-on : ubuntu-24.04
95+ steps :
96+ - name : Checkout
97+ uses : actions/checkout@v4
98+
99+ - name : Setup Python
100+ uses : actions/setup-python@v5
101+ with :
102+ python-version : ${{ env.PYTHON_VERSION }}
103+
104+ - name : Setup Hatch
105+ run : pipx install hatch==${{ env.HATCH_VERSION }}
106+
107+ # If a version wasn't explicitly passed as a workflow_dispatch input we
108+ # default to version v0.0.0+<git-commit-date>-<git-short-sha>, for example
109+ # v0.0.0+20231101115142-1091066df799. This is a simple implementation of
110+ # Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions.
111+ - name : Set Default PyPI Project Version
112+ if : env.PYPI_VERSION == ''
113+ run : echo "PYPI_VERSION=v0.0.0+$(date -d@$(git show -s --format=%ct) +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" >> $GITHUB_ENV
114+
115+ - name : Set PyPI Project Version
116+ run : hatch version ${{ env.PYPI_VERSION }}
117+
118+ - name : Build Sdist and Wheel
119+ run : hatch build
120+
121+ - name : Upload Sdist and Wheel to GitHub
122+ uses : actions/upload-artifact@v4
123+ with :
124+ name : dist
125+ path : " dist/*"
126+ if-no-files-found : error
127+ retention-days : 1
128+
89129 # We want to build most packages for the amd64 and arm64 architectures. To
90130 # speed this up we build single-platform packages in parallel. We then upload
91131 # those packages to GitHub as a build artifact. The push job downloads those
92132 # artifacts and pushes them as a single multi-platform package.
93- build :
133+ build-xpkg :
134+ needs :
135+ - build-pypi
94136 runs-on : ubuntu-24.04
95137 strategy :
96138 fail-fast : true
@@ -113,6 +155,13 @@ jobs:
113155 - name : Checkout
114156 uses : actions/checkout@v4
115157
158+ - name : Download Wheel from GitHub
159+ uses : actions/download-artifact@v5
160+ with :
161+ name : dist
162+ pattern : ' *.whl'
163+ path : dist
164+
116165 # We ask Docker to use GitHub Action's native caching support to speed up
117166 # the build, per https://docs.docker.com/build/cache/backends/gha/.
118167 - name : Build Runtime
@@ -142,16 +191,38 @@ jobs:
142191 if-no-files-found : error
143192 retention-days : 1
144193
194+ publish-pypi :
195+ # Don't publish unless we were run with an explicit version.
196+ if : ${{ inputs.version != '' }}
197+ needs :
198+ - build-xpkg # only publish if xpkg builds succeeds
199+ runs-on : ubuntu-24.04
200+ steps :
201+ - name : Download Sdist and Wheel from GitHub
202+ uses : actions/download-artifact@v5
203+ with :
204+ name : dist
205+ path : dist
206+
207+ - name : Setup Hatch
208+ run : pipx install hatch==${{ env.HATCH_VERSION }}
209+
210+ - name : Publish to PyPI
211+ env :
212+ HATCH_INDEX_USER : __token__
213+ HATCH_INDEX_AUTH : ${{ secrets.PYPI_API_TOKEN }}
214+ run : hatch publish --no-prompt
215+
145216 # This job downloads the single-platform packages built by the build job, and
146217 # pushes them as a multi-platform package. We only push the package it the
147218 # XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
148- push :
219+ push-xpkg :
220+ needs :
221+ - build-xpkg
149222 runs-on : ubuntu-24.04
150223 permissions :
151224 contents : read
152225 packages : write
153- needs :
154- - build
155226 steps :
156227 - name : Checkout
157228 uses : actions/checkout@v4
0 commit comments