|
1 | | -# Publishes t3api-utils to PyPI when a GitHub release is published. |
| 1 | +# Releases t3api-utils when a version tag (e.g. v2.0.0) is pushed: |
| 2 | +# 1. build: check the tag matches pyproject's version and CHANGELOG.md has |
| 3 | +# a section for it, then build the sdist and wheel; |
| 4 | +# 2. publish: upload to PyPI through trusted publishing; |
| 5 | +# 3. github-release: create the GitHub release, with the CHANGELOG.md |
| 6 | +# section as its notes and the distributions attached; |
| 7 | +# 4. docs: deploy the docs site to the gh-pages branch, so |
| 8 | +# https://classvsoftware.github.io/t3api-python-utils/ matches the |
| 9 | +# version on PyPI. |
2 | 10 | # |
3 | | -# BEFORE THIS CAN WORK, enable trusted publishing on PyPI: |
| 11 | +# PyPI needs a trusted publisher for this to upload: |
4 | 12 | # https://pypi.org/manage/project/t3api-utils/settings/publishing/ |
5 | | -# Add a GitHub publisher with owner "classvsoftware", repository |
6 | | -# "t3api-python-utils", workflow "release.yml" and environment "pypi". |
7 | | -# Also create the "pypi" environment under the repository's Settings > |
8 | | -# Environments (optionally with required reviewers). Until both exist, the |
9 | | -# publish job fails at the upload step and nothing is released. |
| 13 | +# GitHub publisher: owner "classvsoftware", repository "t3api-python-utils", |
| 14 | +# workflow "release.yml", environment "pypi". |
| 15 | +# If it's missing, the publish job fails and nothing is released; add it and |
| 16 | +# re-run the failed jobs. |
10 | 17 | # |
11 | | -# Release checklist: bump the version in pyproject.toml, update CHANGELOG.md, |
12 | | -# run scripts/update_spec.py and the sandbox smoke tests, then publish a |
13 | | -# GitHub release whose tag matches the version (e.g. v2.0.0). |
| 18 | +# Release checklist: bump the version in pyproject.toml, add a CHANGELOG.md |
| 19 | +# section headed "## X.Y.Z", run scripts/update_spec.py and the sandbox smoke |
| 20 | +# tests, wait for CI to pass, then push the tag vX.Y.Z. |
14 | 21 |
|
15 | 22 | name: Release |
16 | 23 |
|
17 | 24 | on: |
18 | | - release: |
19 | | - types: [published] |
| 25 | + push: |
| 26 | + tags: ["v*"] |
20 | 27 |
|
21 | 28 | permissions: |
22 | 29 | contents: read |
|
39 | 46 | exit 1 |
40 | 47 | fi |
41 | 48 |
|
| 49 | + - name: Extract the release notes from CHANGELOG.md |
| 50 | + run: | |
| 51 | + version="${GITHUB_REF_NAME#v}" |
| 52 | + awk -v heading="## $version" ' |
| 53 | + $0 == heading { found = 1; next } |
| 54 | + found && /^## / { exit } |
| 55 | + found { print } |
| 56 | + ' CHANGELOG.md > notes.md |
| 57 | + if ! grep -q '[^[:space:]]' notes.md; then |
| 58 | + echo "CHANGELOG.md has no '## $version' section" >&2 |
| 59 | + exit 1 |
| 60 | + fi |
| 61 | +
|
42 | 62 | - name: Build |
43 | 63 | run: uv build |
44 | 64 |
|
|
48 | 68 | path: dist/ |
49 | 69 | if-no-files-found: error |
50 | 70 |
|
| 71 | + - uses: actions/upload-artifact@v7 |
| 72 | + with: |
| 73 | + name: notes |
| 74 | + path: notes.md |
| 75 | + if-no-files-found: error |
| 76 | + |
51 | 77 | publish: |
52 | 78 | name: Publish to PyPI |
53 | 79 | needs: build |
|
64 | 90 | path: dist/ |
65 | 91 |
|
66 | 92 | - uses: pypa/gh-action-pypi-publish@release/v1 |
| 93 | + |
| 94 | + github-release: |
| 95 | + name: Create GitHub release |
| 96 | + needs: publish |
| 97 | + runs-on: ubuntu-latest |
| 98 | + permissions: |
| 99 | + contents: write |
| 100 | + steps: |
| 101 | + - uses: actions/download-artifact@v8 |
| 102 | + with: |
| 103 | + name: dist |
| 104 | + path: dist/ |
| 105 | + |
| 106 | + - uses: actions/download-artifact@v8 |
| 107 | + with: |
| 108 | + name: notes |
| 109 | + |
| 110 | + - name: Create the release |
| 111 | + env: |
| 112 | + GH_TOKEN: ${{ github.token }} |
| 113 | + run: >- |
| 114 | + gh release create "$GITHUB_REF_NAME" dist/* |
| 115 | + --repo "$GITHUB_REPOSITORY" |
| 116 | + --title "t3api-utils ${GITHUB_REF_NAME#v}" |
| 117 | + --notes-file notes.md |
| 118 | + --verify-tag |
| 119 | +
|
| 120 | + docs: |
| 121 | + name: Deploy docs |
| 122 | + needs: publish |
| 123 | + runs-on: ubuntu-latest |
| 124 | + permissions: |
| 125 | + contents: write |
| 126 | + steps: |
| 127 | + - uses: actions/checkout@v7 |
| 128 | + |
| 129 | + - uses: astral-sh/setup-uv@v7 |
| 130 | + |
| 131 | + - name: Install dependencies |
| 132 | + run: uv sync |
| 133 | + |
| 134 | + - name: Deploy to GitHub Pages |
| 135 | + env: |
| 136 | + NO_MKDOCS_2_WARNING: "1" |
| 137 | + run: | |
| 138 | + git config user.name "github-actions[bot]" |
| 139 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 140 | + git fetch origin gh-pages:gh-pages || true |
| 141 | + uv run mkdocs gh-deploy --strict |
0 commit comments