Merge pull request #43 from CSSFrancis/release/v0.4.2 #8
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 | |
| # Fires when a version tag is pushed (manually, after the Prepare Release PR | |
| # is merged and reviewed). | |
| # | |
| # Jobs: | |
| # build - build wheel + sdist with uv | |
| # publish - upload to PyPI via OIDC trusted publishing (no API token needed) | |
| # release - create a GitHub Release with the dist files and changelog notes | |
| on: | |
| push: | |
| tags: ["v*.*.*"] | |
| permissions: | |
| contents: write # create GitHub Releases and upload assets | |
| id-token: write # OIDC token for PyPI trusted publishing | |
| jobs: | |
| # -------------------------------------------------------------------------- | |
| build: | |
| name: Build distribution | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set up uv | |
| uses: astral-sh/setup-uv@v5 | |
| with: | |
| python-version: "3.13" | |
| enable-cache: true | |
| - name: Build wheel and sdist | |
| run: uv build | |
| - name: Upload dist artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| if-no-files-found: error | |
| retention-days: 7 | |
| # -------------------------------------------------------------------------- | |
| publish: | |
| name: Publish to PyPI | |
| needs: build | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: pypi | |
| url: https://pypi.org/p/anyplotlib | |
| steps: | |
| - name: Download dist artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| # Trusted publishing - no API token required. | |
| # One-time setup on pypi.org: add a pending publisher for | |
| # Owner: CSSFrancis Repo: anyplotlib Workflow: release.yml | |
| - name: Publish to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| # -------------------------------------------------------------------------- | |
| release: | |
| name: Create GitHub Release | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Download dist artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: dist | |
| path: dist/ | |
| - name: Prepare release notes | |
| env: | |
| TAG: ${{ github.ref_name }} | |
| shell: python | |
| run: | | |
| import re, pathlib, os | |
| tag = os.environ["TAG"] | |
| # Prefer the curated RELEASE_NOTES.md; fall back to the matching | |
| # CHANGELOG.rst section, then to a generic stub. | |
| curated = pathlib.Path("RELEASE_NOTES.md") | |
| if curated.exists(): | |
| notes = curated.read_text() | |
| else: | |
| text = pathlib.Path("CHANGELOG.rst").read_text() | |
| parts = re.split(r"(?m)(?=^\S[^\n]*\n=+\n)", text) | |
| section = next((p.strip() for p in parts if p.strip().startswith(tag)), None) | |
| notes = section or ("Release " + tag + "\n\nSee CHANGELOG.rst.") | |
| pathlib.Path("release_notes.md").write_text(notes) | |
| - name: Create GitHub Release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| TAG: ${{ github.ref_name }} | |
| run: | | |
| PRERELEASE_FLAG="" | |
| if [[ "$TAG" == *b* ]]; then PRERELEASE_FLAG="--prerelease"; fi | |
| gh release create "$TAG" \ | |
| --title "$TAG" \ | |
| --notes-file release_notes.md \ | |
| $PRERELEASE_FLAG \ | |
| dist/* |