|
| 1 | +# This workflow will upload a Python Package to PyPI when a release is created |
| 2 | +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries |
| 3 | + |
| 4 | +# This workflow uses actions that are not certified by GitHub. |
| 5 | +# They are provided by a third-party and are governed by |
| 6 | +# separate terms of service, privacy policy, and support |
| 7 | +# documentation. |
| 8 | + |
| 9 | +name: Upload Python Package |
| 10 | + |
| 11 | +on: |
| 12 | + release: |
| 13 | + types: [published] |
| 14 | + |
| 15 | +permissions: |
| 16 | + contents: read |
| 17 | + |
| 18 | +jobs: |
| 19 | + release-build: |
| 20 | + runs-on: ubuntu-latest |
| 21 | + |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - uses: actions/setup-python@v5 |
| 26 | + with: |
| 27 | + python-version: "3.13.2" |
| 28 | + |
| 29 | + - name: Prepare env |
| 30 | + run: | |
| 31 | + mkdir ~/.local |
| 32 | + export PATH="$PATH:~/.local/bin:/opt/hostedtoolcache/Python/3.13.2/x64/bin" |
| 33 | + python -m pip install poetry |
| 34 | + poetry self add poetry-dynamic-versioning |
| 35 | +
|
| 36 | + - name: Install deps |
| 37 | + run: | |
| 38 | + export PATH="$PATH:~/.local/bin:/opt/hostedtoolcache/Python/3.13.2/x64/bin" |
| 39 | + sudo pip install grpcio==1.72.0rc1 |
| 40 | + sudo pip install grpcio-tools==1.72.0rc1 # 解决版本问题 |
| 41 | + sudo pip install grpclib |
| 42 | + sudo pip install mypy_protobuf |
| 43 | + poetry lock |
| 44 | + poetry install --with dev |
| 45 | + echo "Install grpcio" |
| 46 | + poetry env activate |
| 47 | + pip install grpcio==1.72.0rc1 |
| 48 | + pip install grpcio-tools==1.72.0rc1 # 解决版本问题 |
| 49 | + |
| 50 | + echo -e '#!/usr/bin/python\nfrom grpclib.plugin.main import main\nimport sys\nsys.exit(main())' > /opt/hostedtoolcache/Python/3.13.2/x64/bin/protoc-gen-grpclib_python |
| 51 | + echo -e '#!/usr/bin/python\nfrom mypy_protobuf.main import main\nimport sys\nsys.exit(main())' > /opt/hostedtoolcache/Python/3.13.2/x64/bin/protoc-gen-mypy |
| 52 | + chmod +x /opt/hostedtoolcache/Python/3.13.2/x64/bin/protoc-gen-grpclib_python |
| 53 | + chmod +x /opt/hostedtoolcache/Python/3.13.2/x64/bin/protoc-gen-mypy |
| 54 | + |
| 55 | + - name: Build |
| 56 | + run: | |
| 57 | + export PATH="$PATH:~/.local/bin:/opt/hostedtoolcache/Python/3.13.2/x64/bin" |
| 58 | + ls /opt/hostedtoolcache/Python/3.13.2/x64/bin |
| 59 | + poetry env activate |
| 60 | + make proto_t |
| 61 | + poetry build |
| 62 | +
|
| 63 | + - name: Upload distributions |
| 64 | + uses: actions/upload-artifact@v4 |
| 65 | + with: |
| 66 | + name: release-dists |
| 67 | + path: dist/ |
| 68 | + |
| 69 | + pypi-publish: |
| 70 | + runs-on: ubuntu-latest |
| 71 | + needs: |
| 72 | + - release-build |
| 73 | + permissions: |
| 74 | + # IMPORTANT: this permission is mandatory for trusted publishing |
| 75 | + id-token: write |
| 76 | + |
| 77 | + # Dedicated environments with protections for publishing are strongly recommended. |
| 78 | + # For more information, see: https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment#deployment-protection-rules |
| 79 | + environment: |
| 80 | + name: pypi |
| 81 | + # OPTIONAL: uncomment and update to include your PyPI project URL in the deployment status: |
| 82 | + # url: https://pypi.org/p/YOURPROJECT |
| 83 | + # |
| 84 | + # ALTERNATIVE: if your GitHub Release name is the PyPI project version string |
| 85 | + # ALTERNATIVE: exactly, uncomment the following line instead: |
| 86 | + # url: https://pypi.org/project/YOURPROJECT/${{ github.event.release.name }} |
| 87 | + |
| 88 | + steps: |
| 89 | + - uses: actions/setup-python@v5 |
| 90 | + with: |
| 91 | + python-version: "3.13.2" |
| 92 | + |
| 93 | + - name: Retrieve release distributions |
| 94 | + uses: actions/download-artifact@v4 |
| 95 | + with: |
| 96 | + name: release-dists |
| 97 | + path: dist/ |
| 98 | + |
| 99 | + - name: Publish release distributions to PyPI |
| 100 | + run: | |
| 101 | + pip install twine |
| 102 | + twine upload -p "${{ secrets.PYPITOKEN }}" ./dist/* |
0 commit comments