|
9 | 9 | workflow_dispatch:
|
10 | 10 | inputs:
|
11 | 11 | version:
|
12 |
| - description: PyPI module version (e.g. v0.1.0) |
| 12 | + description: PyPI project version (e.g. 0.1.0 - no 'v') |
13 | 13 | required: false
|
14 | 14 |
|
15 | 15 | env:
|
16 | 16 | # Common versions
|
17 | 17 | PYTHON_VERSION: '3.11.5'
|
18 | 18 |
|
| 19 | + # The PyPi project version to push. The default is 0.0.0-gitdate-gitsha. |
| 20 | + PYPI_VERSION: ${{ inputs.version }} |
| 21 | + |
19 | 22 | jobs:
|
20 | 23 | lint:
|
21 | 24 | runs-on: ubuntu-22.04
|
|
66 | 69 | - name: Setup Hatch
|
67 | 70 | run: pipx install hatch==1.7.0
|
68 | 71 |
|
| 72 | + # If a version wasn't explicitly passed as a workflow_dispatch input we |
| 73 | + # default to version v0.0.0-<git-commit-date>-<git-short-sha>, for example |
| 74 | + # v0.0.0-20231101115142-1091066df799. This is a simple implementation of |
| 75 | + # Go's pseudo-versions: https://go.dev/ref/mod#pseudo-versions. |
| 76 | + - name: Set Default PyPI Project Version |
| 77 | + if: env.PYPI_VERSION == '' |
| 78 | + run: echo "PYPI_VERSION=0.0.0-$(date -d@$(git show -s --format=%ct) +%Y%m%d%H%M%S)-$(git rev-parse --short=12 HEAD)" >> $GITHUB_ENV |
| 79 | + |
| 80 | + - name: Set PyPI Project Version |
| 81 | + run: hatch version ${{ env.PYPI_VERSION }} |
| 82 | + |
69 | 83 | - name: Build Sdist and Wheel
|
70 | 84 | run: hatch build
|
71 | 85 |
|
|
76 | 90 | path: "dist/*"
|
77 | 91 | if-no-files-found: error
|
78 | 92 | retention-days: 1
|
| 93 | + |
| 94 | + |
| 95 | + publish: |
| 96 | + # Don't publish unless we were run with an explicit version. |
| 97 | + if: ${{ inputs.version != '' }} |
| 98 | + runs-on: ubuntu-22.04 |
| 99 | + steps: |
| 100 | + - name: Download Sdist and Wheel from GitHub |
| 101 | + uses: actions/download-artifact@v4 |
| 102 | + with: |
| 103 | + name: module |
| 104 | + path: "dist" |
| 105 | + |
| 106 | + - name: Publish to PyPI |
| 107 | + |
| 108 | + with: |
| 109 | + # Note that this is currently being pushed to the 'crossplane' PyPI |
| 110 | + # user (not org). See @negz if you need access - PyPI requires 2FA to |
| 111 | + # be enabled, which makes sharing the account hard. We're waiting for |
| 112 | + # a crossplane org to be approved. |
| 113 | + password: ${{ secrets.PYPI_API_TOKEN }} |
0 commit comments