release:prepare 0.1.2 #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release | |
| "on": | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: Build distributions | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Verify tag matches package version | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
| env: | |
| TAG_NAME: ${{ github.ref_name }} | |
| run: | | |
| package_version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/rs_embed/_version.py) | |
| tag_version="${TAG_NAME#v}" | |
| if [ -z "$package_version" ]; then | |
| echo "Unable to determine package version from src/rs_embed/_version.py" >&2 | |
| exit 1 | |
| fi | |
| if [ "$package_version" != "$tag_version" ]; then | |
| echo "Tag version ${tag_version} does not match package version ${package_version}" >&2 | |
| exit 1 | |
| fi | |
| - name: Extract release notes from CHANGELOG.md | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
| env: | |
| TAG_NAME: ${{ github.ref_name }} | |
| run: | | |
| version="${TAG_NAME#v}" | |
| awk -v version="$version" ' | |
| $0 ~ "^## \\[" version "\\]" { capture = 1; next } | |
| capture && $0 ~ "^## \\[" { exit } | |
| capture { print } | |
| ' CHANGELOG.md > RELEASE_NOTES.md | |
| if ! grep -q '[^[:space:]]' RELEASE_NOTES.md; then | |
| echo "No changelog entry found for ${version} in CHANGELOG.md" >&2 | |
| exit 1 | |
| fi | |
| - name: Install build tooling | |
| run: python -m pip install --upgrade build twine | |
| - name: Build wheel and sdist | |
| run: python -m build | |
| - name: Check distribution metadata | |
| run: python -m twine check --strict dist/* | |
| - name: Store distribution packages | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Store release notes | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: github-release-notes | |
| path: RELEASE_NOTES.md | |
| publish-to-testpypi: | |
| name: Publish package to TestPyPI | |
| if: github.event_name == 'workflow_dispatch' | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: testpypi | |
| url: https://test.pypi.org/p/rs-embed | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download distributions | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Publish distribution to TestPyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| repository-url: https://test.pypi.org/legacy/ | |
| smoke-test-testpypi: | |
| name: Install package from TestPyPI | |
| if: github.event_name == 'workflow_dispatch' | |
| needs: publish-to-testpypi | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Upgrade pip | |
| run: python -m pip install --upgrade pip | |
| - name: Install published package from TestPyPI | |
| run: | | |
| version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/rs_embed/_version.py) | |
| if [ -z "$version" ]; then | |
| echo "Unable to determine package version from src/rs_embed/_version.py" >&2 | |
| exit 1 | |
| fi | |
| for attempt in 1 2 3 4 5; do | |
| if python -m pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "rs-embed==${version}"; then | |
| exit 0 | |
| fi | |
| if [ "$attempt" -eq 5 ]; then | |
| echo "TestPyPI install failed for rs-embed==${version}" >&2 | |
| exit 1 | |
| fi | |
| sleep 30 | |
| done | |
| - name: Verify installed version | |
| run: | | |
| version=$(sed -n 's/^__version__ = "\(.*\)"$/\1/p' src/rs_embed/_version.py) | |
| installed=$(python -c "import importlib.metadata as md; print(md.version('rs-embed'))") | |
| if [ "$installed" != "$version" ]; then | |
| echo "Installed version ${installed} does not match expected ${version}" >&2 | |
| exit 1 | |
| fi | |
| - name: Verify package import | |
| run: | | |
| python -c "import rs_embed; print(rs_embed.__version__)" | |
| - name: Verify CLI entry point | |
| run: | | |
| rs-embed --help | |
| publish-to-pypi: | |
| name: Publish package to PyPI | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/rs-embed | |
| permissions: | |
| id-token: write | |
| steps: | |
| - name: Download distributions | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: python-package-distributions | |
| path: dist/ | |
| - name: Publish distribution to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| github-release: | |
| name: Publish GitHub Release | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
| needs: publish-to-pypi | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download release notes | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: github-release-notes | |
| path: . | |
| - name: Publish GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| body_path: RELEASE_NOTES.md | |
| generate_release_notes: false |