release: 0.21.0 (declarative device trees + configurable Homie domain… #35
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: Publish to PyPI | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| # The publish gate: a hang here must fail, not stall the release. | |
| timeout-minutes: 5 | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: "3.12" | |
| - run: pip install -e ".[dev]" | |
| - run: pytest tests/ -v | |
| publish: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| environment: pypi | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: "3.12" | |
| # Refuse to publish an artifact whose version disagrees with the tag. | |
| - name: Verify tag matches package version | |
| run: | | |
| pkg="v$(python -c 'import re,pathlib; print(re.search(r"__version__ = \"([^\"]+)\"", pathlib.Path("src/ebus_sdk/__init__.py").read_text()).group(1))')" | |
| echo "tag=${GITHUB_REF_NAME} package=${pkg}" | |
| test "${pkg}" = "${GITHUB_REF_NAME}" | |
| - run: pip install build | |
| - run: python -m build | |
| - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 | |
| with: | |
| print-hash: true | |
| # After a successful PyPI publish, mirror the release to GitHub Releases, | |
| # using the tag's CHANGELOG section as the notes. Idempotent (create or edit). | |
| github-release: | |
| needs: publish | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3 | |
| - name: Create GitHub Release from the CHANGELOG section | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| version="${GITHUB_REF_NAME#v}" | |
| python3 - "$version" > notes.md <<'PY' | |
| import re, sys, pathlib | |
| v = re.escape(sys.argv[1]) | |
| text = pathlib.Path("CHANGELOG.md").read_text() | |
| m = re.search(rf"^## \[{v}\][^\n]*\n(.*?)(?=^## \[|\Z)", text, re.S | re.M) | |
| body = (m.group(1).strip() if m else "") or "See CHANGELOG.md." | |
| sys.stdout.write(body + "\n") | |
| PY | |
| gh release create "${GITHUB_REF_NAME}" --title "${GITHUB_REF_NAME}" \ | |
| --notes-file notes.md --verify-tag \ | |
| || gh release edit "${GITHUB_REF_NAME}" --notes-file notes.md |