|
| 1 | +name: release |
| 2 | + |
| 3 | +"on": |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + name: Build distributions |
| 12 | + runs-on: ubuntu-latest |
| 13 | + permissions: |
| 14 | + contents: read |
| 15 | + steps: |
| 16 | + - uses: actions/checkout@v4 |
| 17 | + with: |
| 18 | + persist-credentials: false |
| 19 | + |
| 20 | + - name: Set up Python |
| 21 | + uses: actions/setup-python@v5 |
| 22 | + with: |
| 23 | + python-version: "3.12" |
| 24 | + |
| 25 | + - name: Verify tag matches package version |
| 26 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 27 | + env: |
| 28 | + TAG_NAME: ${{ github.ref_name }} |
| 29 | + run: | |
| 30 | + package_version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/rs_embed/_version.py) |
| 31 | + tag_version="${TAG_NAME#v}" |
| 32 | +
|
| 33 | + if [ -z "$package_version" ]; then |
| 34 | + echo "Unable to determine package version from src/rs_embed/_version.py" >&2 |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | +
|
| 38 | + if [ "$package_version" != "$tag_version" ]; then |
| 39 | + echo "Tag version ${tag_version} does not match package version ${package_version}" >&2 |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + - name: Extract release notes from CHANGELOG.md |
| 44 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 45 | + env: |
| 46 | + TAG_NAME: ${{ github.ref_name }} |
| 47 | + run: | |
| 48 | + version="${TAG_NAME#v}" |
| 49 | + awk -v version="$version" ' |
| 50 | + $0 ~ "^## \\[" version "\\]" { capture = 1; next } |
| 51 | + capture && $0 ~ "^## \\[" { exit } |
| 52 | + capture { print } |
| 53 | + ' CHANGELOG.md > RELEASE_NOTES.md |
| 54 | +
|
| 55 | + if ! grep -q '[^[:space:]]' RELEASE_NOTES.md; then |
| 56 | + echo "No changelog entry found for ${version} in CHANGELOG.md" >&2 |
| 57 | + exit 1 |
| 58 | + fi |
| 59 | +
|
| 60 | + - name: Install build tooling |
| 61 | + run: python -m pip install --upgrade build twine |
| 62 | + |
| 63 | + - name: Build wheel and sdist |
| 64 | + run: python -m build |
| 65 | + |
| 66 | + - name: Check distribution metadata |
| 67 | + run: python -m twine check --strict dist/* |
| 68 | + |
| 69 | + - name: Store distribution packages |
| 70 | + uses: actions/upload-artifact@v4 |
| 71 | + with: |
| 72 | + name: python-package-distributions |
| 73 | + path: dist/ |
| 74 | + |
| 75 | + - name: Store release notes |
| 76 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 77 | + uses: actions/upload-artifact@v4 |
| 78 | + with: |
| 79 | + name: github-release-notes |
| 80 | + path: RELEASE_NOTES.md |
| 81 | + |
| 82 | + publish-to-testpypi: |
| 83 | + name: Publish package to TestPyPI |
| 84 | + if: github.event_name == 'workflow_dispatch' |
| 85 | + needs: build |
| 86 | + runs-on: ubuntu-latest |
| 87 | + environment: |
| 88 | + name: testpypi |
| 89 | + url: https://test.pypi.org/p/rs-embed |
| 90 | + permissions: |
| 91 | + id-token: write |
| 92 | + steps: |
| 93 | + - name: Download distributions |
| 94 | + uses: actions/download-artifact@v4 |
| 95 | + with: |
| 96 | + name: python-package-distributions |
| 97 | + path: dist/ |
| 98 | + |
| 99 | + - name: Publish distribution to TestPyPI |
| 100 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 101 | + with: |
| 102 | + repository-url: https://test.pypi.org/legacy/ |
| 103 | + |
| 104 | + smoke-test-testpypi: |
| 105 | + name: Install package from TestPyPI |
| 106 | + if: github.event_name == 'workflow_dispatch' |
| 107 | + needs: publish-to-testpypi |
| 108 | + runs-on: ubuntu-latest |
| 109 | + permissions: |
| 110 | + contents: read |
| 111 | + steps: |
| 112 | + - uses: actions/checkout@v4 |
| 113 | + |
| 114 | + - name: Set up Python |
| 115 | + uses: actions/setup-python@v5 |
| 116 | + with: |
| 117 | + python-version: "3.12" |
| 118 | + |
| 119 | + - name: Upgrade pip |
| 120 | + run: python -m pip install --upgrade pip |
| 121 | + |
| 122 | + - name: Install published package from TestPyPI |
| 123 | + run: | |
| 124 | + version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/rs_embed/_version.py) |
| 125 | +
|
| 126 | + if [ -z "$version" ]; then |
| 127 | + echo "Unable to determine package version from src/rs_embed/_version.py" >&2 |
| 128 | + exit 1 |
| 129 | + fi |
| 130 | +
|
| 131 | + for attempt in 1 2 3 4 5; do |
| 132 | + if python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "rs-embed==${version}"; then |
| 133 | + exit 0 |
| 134 | + fi |
| 135 | +
|
| 136 | + if [ "$attempt" -eq 5 ]; then |
| 137 | + echo "TestPyPI install failed for rs-embed==${version}" >&2 |
| 138 | + exit 1 |
| 139 | + fi |
| 140 | +
|
| 141 | + sleep 30 |
| 142 | + done |
| 143 | +
|
| 144 | + - name: Verify installed version |
| 145 | + run: | |
| 146 | + version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/rs_embed/_version.py) |
| 147 | + installed=$(python -c "import importlib.metadata as md; print(md.version('rs-embed'))") |
| 148 | +
|
| 149 | + if [ "$installed" != "$version" ]; then |
| 150 | + echo "Installed version ${installed} does not match expected ${version}" >&2 |
| 151 | + exit 1 |
| 152 | + fi |
| 153 | +
|
| 154 | + - name: Verify package import |
| 155 | + run: | |
| 156 | + python -c "import rs_embed; print(rs_embed.__version__)" |
| 157 | +
|
| 158 | + - name: Verify CLI entry point |
| 159 | + run: | |
| 160 | + rs-embed --help |
| 161 | +
|
| 162 | + publish-to-pypi: |
| 163 | + name: Publish package to PyPI |
| 164 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 165 | + needs: build |
| 166 | + runs-on: ubuntu-latest |
| 167 | + environment: |
| 168 | + name: pypi |
| 169 | + url: https://pypi.org/p/rs-embed |
| 170 | + permissions: |
| 171 | + id-token: write |
| 172 | + steps: |
| 173 | + - name: Download distributions |
| 174 | + uses: actions/download-artifact@v4 |
| 175 | + with: |
| 176 | + name: python-package-distributions |
| 177 | + path: dist/ |
| 178 | + |
| 179 | + - name: Publish distribution to PyPI |
| 180 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 181 | + |
| 182 | + github-release: |
| 183 | + name: Publish GitHub Release |
| 184 | + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') |
| 185 | + needs: publish-to-pypi |
| 186 | + runs-on: ubuntu-latest |
| 187 | + permissions: |
| 188 | + contents: write |
| 189 | + steps: |
| 190 | + - name: Download release notes |
| 191 | + uses: actions/download-artifact@v4 |
| 192 | + with: |
| 193 | + name: github-release-notes |
| 194 | + path: . |
| 195 | + |
| 196 | + - name: Publish GitHub Release |
| 197 | + uses: softprops/action-gh-release@v2 |
| 198 | + with: |
| 199 | + body_path: RELEASE_NOTES.md |
| 200 | + generate_release_notes: false |
0 commit comments