|
| 1 | +--- |
| 2 | +name: Publish releases |
| 3 | + |
| 4 | +# yamllint disable-line rule:truthy |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | +env: |
| 9 | + PYTHON_VERSION: "3.12" |
| 10 | + |
| 11 | +jobs: |
| 12 | + build-and-publish-pypi: |
| 13 | + name: Builds and publishes releases to PyPI |
| 14 | + runs-on: ubuntu-latest |
| 15 | + steps: |
| 16 | + |
| 17 | + - name: Get tag |
| 18 | + id: vars |
| 19 | + run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV |
| 20 | + - name: Validate version number |
| 21 | + run: >- |
| 22 | + if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then |
| 23 | + if ! [[ "${tag}" =~ "b" ]]; then |
| 24 | + echo "Pre-release: Tag is missing beta suffix (${tag})" |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + else |
| 28 | + if [[ "${tag}" =~ "b" ]]; then |
| 29 | + echo "Release: Tag must not have a beta suffix (${tag})" |
| 30 | + exit 1 |
| 31 | + fi |
| 32 | + fi |
| 33 | + - name: Set up Python ${{ env.PYTHON_VERSION }} |
| 34 | + |
| 35 | + with: |
| 36 | + python-version: ${{ env.PYTHON_VERSION }} |
| 37 | + - name: Install build |
| 38 | + run: >- |
| 39 | + pip install build tomli tomli-w |
| 40 | + - name: Set Python project version from tag |
| 41 | + shell: python |
| 42 | + run: |- |
| 43 | + import tomli |
| 44 | + import tomli_w |
| 45 | +
|
| 46 | + with open("pyproject.toml", "rb") as f: |
| 47 | + pyproject = tomli.load(f) |
| 48 | +
|
| 49 | + pyproject["project"]["version"] = "${tag}" |
| 50 | +
|
| 51 | + with open("pyproject.toml", "wb") as f: |
| 52 | + tomli_w.dump(pyproject, f) |
| 53 | + - name: Build python package |
| 54 | + run: >- |
| 55 | + python3 -m build |
| 56 | + - name: Publish release to PyPI |
| 57 | + |
| 58 | + with: |
| 59 | + user: __token__ |
| 60 | + password: ${{ secrets.PYPI_TOKEN }} |
| 61 | + - name: Wait for PyPI |
| 62 | + run: sleep 300 |
0 commit comments