|
| 1 | +name: Publish Python package |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: |
| 6 | + - published |
| 7 | + |
| 8 | +concurrency: |
| 9 | + group: pypi-${{ github.event.release.tag_name }} |
| 10 | + cancel-in-progress: false |
| 11 | + |
| 12 | +jobs: |
| 13 | + build: |
| 14 | + name: Build and verify distributions |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Check out the released source |
| 21 | + uses: actions/checkout@v6 |
| 22 | + with: |
| 23 | + ref: ${{ github.event.release.tag_name }} |
| 24 | + |
| 25 | + - name: Set up Python |
| 26 | + uses: actions/setup-python@v5 |
| 27 | + with: |
| 28 | + python-version: "3.11" |
| 29 | + |
| 30 | + - name: Install build and test dependencies |
| 31 | + run: | |
| 32 | + python -m pip install --upgrade pip |
| 33 | + python -m pip install -e . |
| 34 | + python -m pip install build pytest pytest-asyncio ruff twine ty |
| 35 | +
|
| 36 | + - name: Verify tag matches the package version |
| 37 | + env: |
| 38 | + RELEASE_TAG: ${{ github.event.release.tag_name }} |
| 39 | + run: | |
| 40 | + PACKAGE_VERSION="$(python -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')" |
| 41 | + test "${RELEASE_TAG#v}" = "$PACKAGE_VERSION" || { |
| 42 | + echo "Release tag $RELEASE_TAG does not match package version $PACKAGE_VERSION" >&2 |
| 43 | + exit 1 |
| 44 | + } |
| 45 | +
|
| 46 | + - name: Check the license boundary |
| 47 | + run: | |
| 48 | + ! grep -rn "shared.api\|import wgp\|mmgp" src tests scripts |
| 49 | +
|
| 50 | + - name: Verify generated package metadata |
| 51 | + run: | |
| 52 | + nodetool-pkg scan --write |
| 53 | + git diff --exit-code -- src/nodetool/package_metadata/nodetool-wan2gp.json |
| 54 | +
|
| 55 | + - name: Run checks |
| 56 | + run: | |
| 57 | + ruff check . |
| 58 | + ty check . |
| 59 | + pytest -q |
| 60 | +
|
| 61 | + - name: Build distributions |
| 62 | + run: python -m build |
| 63 | + |
| 64 | + - name: Verify distribution metadata |
| 65 | + run: python -m twine check dist/* |
| 66 | + |
| 67 | + - name: Upload distributions |
| 68 | + uses: actions/upload-artifact@v4 |
| 69 | + with: |
| 70 | + name: python-package-distributions |
| 71 | + path: dist/ |
| 72 | + if-no-files-found: error |
| 73 | + retention-days: 1 |
| 74 | + |
| 75 | + publish: |
| 76 | + name: Publish distributions to PyPI |
| 77 | + needs: build |
| 78 | + runs-on: ubuntu-latest |
| 79 | + environment: |
| 80 | + name: pypi |
| 81 | + url: https://pypi.org/project/nodetool-wan2gp/ |
| 82 | + permissions: |
| 83 | + id-token: write |
| 84 | + |
| 85 | + steps: |
| 86 | + - name: Download distributions |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + name: python-package-distributions |
| 90 | + path: dist/ |
| 91 | + |
| 92 | + - name: Publish distributions to PyPI |
| 93 | + uses: pypa/gh-action-pypi-publish@release/v1 |
0 commit comments