|
| 1 | +name: Publish to PyPI |
| 2 | + |
| 3 | +# Publishes `palace-util` and `palace-opds` when a GitHub Release is |
| 4 | +# published. Each package is built and uploaded independently via PyPI's |
| 5 | +# Trusted Publishing (OIDC) flow. https://docs.pypi.org/trusted-publishers/ |
| 6 | +# |
| 7 | +# No action is needed on new releases beyond publishing a GitHub Release with |
| 8 | +# a tag that dunamai can parse as semver (e.g. `v1.0.0` or `1.0.0`). |
| 9 | + |
| 10 | +on: |
| 11 | + release: |
| 12 | + types: [published] |
| 13 | + |
| 14 | +env: |
| 15 | + PYTHON_VERSION: "3.12" |
| 16 | + |
| 17 | +jobs: |
| 18 | + publish: |
| 19 | + name: Publish ${{ matrix.package }} to PyPI |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + strategy: |
| 22 | + fail-fast: false |
| 23 | + matrix: |
| 24 | + include: |
| 25 | + - package: palace-util |
| 26 | + source_dir: packages/palace-util/src/palace/util |
| 27 | + - package: palace-opds |
| 28 | + source_dir: packages/palace-opds/src/palace/opds |
| 29 | + permissions: |
| 30 | + # Required for PyPI Trusted Publishing (OIDC). |
| 31 | + id-token: write |
| 32 | + contents: read |
| 33 | + |
| 34 | + steps: |
| 35 | + - uses: actions/checkout@v6 |
| 36 | + with: |
| 37 | + persist-credentials: false |
| 38 | + # dunamai needs the full tag history. |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: Install uv |
| 42 | + uses: astral-sh/setup-uv@v8.0.0 |
| 43 | + with: |
| 44 | + enable-cache: true |
| 45 | + cache-dependency-glob: uv.lock |
| 46 | + python-version: ${{ env.PYTHON_VERSION }} |
| 47 | + activate-environment: true |
| 48 | + |
| 49 | + - name: Install Dunamai |
| 50 | + run: uv sync --frozen --only-group ci |
| 51 | + |
| 52 | + - name: Compute version metadata |
| 53 | + id: version |
| 54 | + run: | |
| 55 | + echo "version=$(dunamai from git --style semver)" >> "$GITHUB_OUTPUT" |
| 56 | + echo "commit=$(dunamai from git --format '{commit}' --full-commit)" >> "$GITHUB_OUTPUT" |
| 57 | +
|
| 58 | + - name: Write _version.py |
| 59 | + # hatch reads __version__ from this file via [tool.hatch.version] |
| 60 | + # regex source; overwriting it here is how the release version lands |
| 61 | + # in the wheel metadata. |
| 62 | + run: | |
| 63 | + cat > ${{ matrix.source_dir }}/_version.py <<EOF |
| 64 | + __version__ = "${{ steps.version.outputs.version }}" |
| 65 | + __commit__: str | None = "${{ steps.version.outputs.commit }}" |
| 66 | + EOF |
| 67 | +
|
| 68 | + - name: Pin intra-workspace dependency |
| 69 | + # uv build preserves workspace deps as bare names in Requires-Dist |
| 70 | + # (e.g. `palace-util` with no version). For PyPI we need an exact pin |
| 71 | + # so a consumer installing palace-opds resolves the matching |
| 72 | + # palace-util version. |
| 73 | + if: matrix.package == 'palace-opds' |
| 74 | + run: uv add --package palace-opds "palace-util==${{ steps.version.outputs.version }}" |
| 75 | + |
| 76 | + - name: Build ${{ matrix.package }} |
| 77 | + run: uv build --package ${{ matrix.package }} |
| 78 | + |
| 79 | + - name: Publish to PyPI |
| 80 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 81 | + with: |
| 82 | + packages-dir: dist |
| 83 | + print-hash: true |
0 commit comments