Skip to content

fix(ci): publish Python wheel to GitHub Releases #10

fix(ci): publish Python wheel to GitHub Releases

fix(ci): publish Python wheel to GitHub Releases #10

Workflow file for this run

name: Python Client CI
on:
push:
branches: [main]
paths:
- 'clients/python/**'
- 'spec/**'
- '.github/workflows/python-ci.yml'
pull_request:
branches: [main]
paths:
- 'clients/python/**'
- 'spec/**'
- '.github/workflows/python-ci.yml'
jobs:
build-and-test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: clients/python
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install pipx
run: pip install pipx
- name: Generate client from spec
working-directory: .
run: ./scripts/generate.sh
- name: Set up generated symlink
run: ln -sf ../../generated src/ros2_medkit_client/_generated
- name: Install package with dev deps
run: pip install -e '.[dev]'
- name: Test
run: python -m pytest -v
- name: Lint
run: ruff check src/ tests/
- name: Format check
run: ruff format --check src/ tests/
publish:
needs: build-and-test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: write
defaults:
run:
working-directory: clients/python
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install build tools
run: pip install pipx build
- name: Generate client from spec
working-directory: .
run: ./scripts/generate.sh
- name: Set up generated symlink
run: ln -sf ../../generated src/ros2_medkit_client/_generated
- name: Build wheel
run: python -m build
- name: Read version
id: version
run: |
VERSION=$(python3 -c "import re, pathlib; text = pathlib.Path('pyproject.toml').read_text(); m = re.search(r'^version\s*=\s*\"([^\"]+)\"', text, re.MULTILINE); print(m.group(1))")
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
- name: Publish wheel to GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="py-v${{ steps.version.outputs.version }}"
# Delete existing release if same version (overwrite)
gh release delete "$TAG" --yes 2>/dev/null || true
# Create release and upload wheel
gh release create "$TAG" \
--title "Python client v${{ steps.version.outputs.version }}" \
--notes "Install: \`pip install https://github.com/selfpatch/ros2_medkit_clients/releases/download/${TAG}/$(ls dist/*.whl | head -1 | xargs basename)\`" \
dist/*.whl