|
| 1 | +name: Release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - "v*" |
| 7 | + |
| 8 | +jobs: |
| 9 | + publish: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + permissions: |
| 12 | + contents: write |
| 13 | + id-token: write |
| 14 | + |
| 15 | + steps: |
| 16 | + - name: Checkout |
| 17 | + uses: actions/checkout@v4 |
| 18 | + |
| 19 | + - name: Setup Python |
| 20 | + uses: actions/setup-python@v5 |
| 21 | + with: |
| 22 | + python-version: "3.12" |
| 23 | + |
| 24 | + - name: Upgrade pip |
| 25 | + run: python -m pip install --upgrade pip |
| 26 | + |
| 27 | + - name: Install release dependencies |
| 28 | + run: python -m pip install -e .[release] |
| 29 | + |
| 30 | + - name: Build package |
| 31 | + run: python -m build |
| 32 | + |
| 33 | + - name: Check package metadata |
| 34 | + run: python -m twine check dist/* |
| 35 | + |
| 36 | + - name: Validate version and release note |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + python - <<'PY' |
| 40 | + import pathlib |
| 41 | + import tomllib |
| 42 | + import sys |
| 43 | +
|
| 44 | + root = pathlib.Path(".") |
| 45 | + sys.path.insert(0, str(root / "src")) |
| 46 | + from code2skill import __version__ |
| 47 | +
|
| 48 | + tag = "${{ github.ref_name }}" |
| 49 | + version = tag.removeprefix("v") |
| 50 | + pyproject = tomllib.loads((root / "pyproject.toml").read_text(encoding="utf-8")) |
| 51 | + declared = pyproject["project"]["version"] |
| 52 | + if declared != version: |
| 53 | + raise SystemExit(f"Tag {tag} does not match pyproject version {declared}.") |
| 54 | + if __version__ != version: |
| 55 | + raise SystemExit(f"Tag {tag} does not match runtime version {__version__}.") |
| 56 | + release_note = root / "docs" / "releases" / f"v{version}.md" |
| 57 | + if not release_note.exists(): |
| 58 | + raise SystemExit(f"Missing release note file: {release_note}") |
| 59 | + PY |
| 60 | +
|
| 61 | + - name: Publish to PyPI |
| 62 | + uses: pypa/gh-action-pypi-publish@release/v1 |
| 63 | + |
| 64 | + - name: Create GitHub Release |
| 65 | + uses: softprops/action-gh-release@v2 |
| 66 | + with: |
| 67 | + body_path: docs/releases/${{ github.ref_name }}.md |
0 commit comments