|
| 1 | +--- |
| 2 | +name: Publish releases |
| 3 | + |
| 4 | +# yamllint disable-line rule:truthy |
| 5 | +on: |
| 6 | + release: |
| 7 | + types: [published] |
| 8 | + workflow_dispatch: |
| 9 | + inputs: |
| 10 | + version: |
| 11 | + description: "Version for release on TestPyPI" |
| 12 | + required: true |
| 13 | +env: |
| 14 | + PYTHON_VERSION: "3.12" |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + name: Builds and publishes releases to PyPI |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + |
| 22 | + - name: Store version from inputs |
| 23 | + if: github.event_name == 'workflow_dispatch' |
| 24 | + run: echo "tag=${{ inputs.version }}" |
| 25 | + - name: Get version from tag |
| 26 | + if: github.event_name == 'release' |
| 27 | + run: echo "tag=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV |
| 28 | + - name: Validate version number |
| 29 | + if: github.event_name == 'release' |
| 30 | + run: >- |
| 31 | + if [[ "${{ github.event.release.prerelease }}" == "true" ]]; then |
| 32 | + if ! [[ "${tag}" =~ "b" ]]; then |
| 33 | + echo "Pre-release: Tag is missing beta suffix (${tag})" |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + else |
| 37 | + if [[ "${tag}" =~ "b" ]]; then |
| 38 | + echo "Release: Tag must not have a beta suffix (${tag})" |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + fi |
| 42 | + - name: Set up Python ${{ env.PYTHON_VERSION }} |
| 43 | + |
| 44 | + with: |
| 45 | + python-version: ${{ env.PYTHON_VERSION }} |
| 46 | + - name: Install build |
| 47 | + run: >- |
| 48 | + pip install build tomli tomli-w |
| 49 | + - name: Set Python project version from tag |
| 50 | + shell: python |
| 51 | + run: |- |
| 52 | + import tomli |
| 53 | + import tomli_w |
| 54 | +
|
| 55 | + with open("pyproject.toml", "rb") as f: |
| 56 | + pyproject = tomli.load(f) |
| 57 | +
|
| 58 | + pyproject["project"]["version"] = "${tag}" |
| 59 | +
|
| 60 | + with open("pyproject.toml", "wb") as f: |
| 61 | + tomli_w.dump(pyproject, f) |
| 62 | + - name: Build python package |
| 63 | + run: >- |
| 64 | + python3 -m build |
| 65 | + - name: Store the distribution packages |
| 66 | + uses: actions/upload-artifact@v4 |
| 67 | + with: |
| 68 | + name: python-package-distributions |
| 69 | + path: dist/ |
| 70 | + |
| 71 | + publish-pypi: |
| 72 | + name: Publishes releases to PyPI |
| 73 | + runs-on: ubuntu-latest |
| 74 | + if: github.event_name == 'release' |
| 75 | + needs: |
| 76 | + - build |
| 77 | + environment: |
| 78 | + name: pypi |
| 79 | + url: https://pypi.org/p/aiohasupervisor |
| 80 | + permissions: |
| 81 | + id-token: write |
| 82 | + steps: |
| 83 | + - name: Download all the dists |
| 84 | + uses: actions/download-artifact@v4 |
| 85 | + with: |
| 86 | + name: python-package-distributions |
| 87 | + path: dist/ |
| 88 | + - name: Publish distribution 📦 to PyPI |
| 89 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 90 | + |
| 91 | + publish-test-pypi: |
| 92 | + name: Publishes releases to Test-PyPI |
| 93 | + runs-on: ubuntu-latest |
| 94 | + if: github.event_name == 'workflow_dispatch' |
| 95 | + needs: |
| 96 | + - build |
| 97 | + environment: |
| 98 | + name: testpypi |
| 99 | + url: https://test.pypi.org/p/aiohasupervisor |
| 100 | + permissions: |
| 101 | + id-token: write |
| 102 | + steps: |
| 103 | + - name: Download all the dists |
| 104 | + uses: actions/download-artifact@v4 |
| 105 | + with: |
| 106 | + name: python-package-distributions |
| 107 | + path: dist/ |
| 108 | + - name: Publish distribution 📦 to TestPyPI |
| 109 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 110 | + with: |
| 111 | + repository-url: https://test.pypi.org/legacy/ |
0 commit comments