|
14 | 14 |
|
15 | 15 | env: |
16 | 16 | # Common versions |
17 | | - PYTHON_VERSION: '3.12.11' # TODO: Used? |
| 17 | + PYTHON_VERSION: '3.13.7' # TODO: Used? |
| 18 | + HATCH_VERSION: '1.12.0' |
18 | 19 | DOCKER_BUILDX_VERSION: 'v0.26.1' |
19 | 20 |
|
20 | 21 | # These environment variables are important to the Crossplane CLI install.sh |
|
32 | 33 | # XPKG: xpkg.upbound.io/${{ github.repository}} |
33 | 34 | CROSSPLANE_REGORG: ghcr.io/${{ github.repository}} |
34 | 35 |
|
| 36 | + # The PyPi project version to push. The default is v0.0.0+gitdate-gitsha. |
| 37 | + PYPI_VERSION: ${{ inputs.version }} |
| 38 | + |
35 | 39 | # The package version to push. The default is 0.0.0-gitsha. |
36 | 40 | XPKG_VERSION: ${{ inputs.version }} |
37 | 41 |
|
@@ -86,11 +90,47 @@ jobs: |
86 | 90 | #remove-link-from-badge: false |
87 | 91 | #unique-id-for-comment: python3.8 |
88 | 92 |
|
| 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 | + |
89 | 129 | # We want to build most packages for the amd64 and arm64 architectures. To |
90 | 130 | # speed this up we build single-platform packages in parallel. We then upload |
91 | 131 | # those packages to GitHub as a build artifact. The push job downloads those |
92 | 132 | # artifacts and pushes them as a single multi-platform package. |
93 | | - build: |
| 133 | + build-xpkg: |
94 | 134 | runs-on: ubuntu-24.04 |
95 | 135 | strategy: |
96 | 136 | fail-fast: true |
@@ -142,16 +182,34 @@ jobs: |
142 | 182 | if-no-files-found: error |
143 | 183 | retention-days: 1 |
144 | 184 |
|
| 185 | + publish-pypi: |
| 186 | + # Don't publish unless we were run with an explicit version. |
| 187 | + if: ${{ inputs.version != '' }} |
| 188 | + needs: |
| 189 | + - build-pypi |
| 190 | + runs-on: ubuntu-24.04 |
| 191 | + steps: |
| 192 | + - name: Download Sdist and Wheel from GitHub |
| 193 | + uses: actions/download-artifact@v5 |
| 194 | + with: |
| 195 | + name: dist |
| 196 | + path: "dist" |
| 197 | + |
| 198 | + - name: Publish to PyPI |
| 199 | + uses: pypa/gh-action-pypi-publish@v1.12.4 |
| 200 | + with: |
| 201 | + password: ${{ secrets.PYPI_API_TOKEN }} |
| 202 | + |
145 | 203 | # This job downloads the single-platform packages built by the build job, and |
146 | 204 | # pushes them as a multi-platform package. We only push the package it the |
147 | 205 | # XPKG_ACCESS_ID and XPKG_TOKEN secrets were provided. |
148 | | - push: |
| 206 | + push-xpkg: |
149 | 207 | runs-on: ubuntu-24.04 |
150 | 208 | permissions: |
151 | 209 | contents: read |
152 | 210 | packages: write |
153 | 211 | needs: |
154 | | - - build |
| 212 | + - build-xpkg |
155 | 213 | steps: |
156 | 214 | - name: Checkout |
157 | 215 | uses: actions/checkout@v4 |
|
0 commit comments