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,12 @@ jobs:
113155 - name : Checkout
114156 uses : actions/checkout@v4
115157
158+ - name : Download Sdist and Wheel from GitHub
159+ uses : actions/download-artifact@v5
160+ with :
161+ name : dist
162+ path : " dist"
163+
116164 # We ask Docker to use GitHub Action's native caching support to speed up
117165 # the build, per https://docs.docker.com/build/cache/backends/gha/.
118166 - name : Build Runtime
@@ -142,16 +190,34 @@ jobs:
142190 if-no-files-found : error
143191 retention-days : 1
144192
193+ publish-pypi :
194+ # Don't publish unless we were run with an explicit version.
195+ if : ${{ inputs.version != '' }}
196+ needs :
197+ - build-pypi
198+ runs-on : ubuntu-24.04
199+ steps :
200+ - name : Download Sdist and Wheel from GitHub
201+ uses : actions/download-artifact@v5
202+ with :
203+ name : dist
204+ path : " dist"
205+
206+ - name : Publish to PyPI
207+ uses : pypa/gh-action-pypi-publish@v1.12.4
208+ with :
209+ password : ${{ secrets.PYPI_API_TOKEN }}
210+
145211 # This job downloads the single-platform packages built by the build job, and
146212 # pushes them as a multi-platform package. We only push the package it the
147213 # XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided.
148- push :
214+ push-xpkg :
149215 runs-on : ubuntu-24.04
150216 permissions :
151217 contents : read
152218 packages : write
153219 needs :
154- - build
220+ - build-xpkg
155221 steps :
156222 - name : Checkout
157223 uses : actions/checkout@v4
0 commit comments