1+ #! /bin/bash
2+ # Script to build and publish API client packages to PyPI
3+
4+ set -e
5+
6+ echo " Publishing API client packages to PyPI..."
7+
8+ # Function to publish a client package
9+ publish_client () {
10+ local SERVICE=$1
11+ local CLIENT_DIR=" projects/policyengine-api-${SERVICE} /artifacts/clients/python"
12+
13+ echo " Publishing ${SERVICE} API client..."
14+
15+ # Check if client exists
16+ if [ ! -d " ${CLIENT_DIR} " ]; then
17+ echo " ❌ Client directory not found: ${CLIENT_DIR} "
18+ echo " Running client generation first..."
19+ ./scripts/generate-clients.sh
20+ fi
21+
22+ cd " ${CLIENT_DIR} "
23+
24+ # Update version based on date and commit SHA
25+ # Format: 0.YYYYMMDD.SHORT_SHA (e.g., 0.20240820.abc1234)
26+ if [ -n " ${GITHUB_SHA} " ]; then
27+ # In GitHub Actions
28+ SHORT_SHA=$( echo " ${GITHUB_SHA} " | cut -c1-7)
29+ else
30+ # Local development
31+ SHORT_SHA=$( git rev-parse --short HEAD 2> /dev/null || echo " dev" )
32+ fi
33+ DATE=$( date +%Y%m%d)
34+ NEW_VERSION=" 0.${DATE} .${SHORT_SHA} "
35+
36+ # Update version in pyproject.toml
37+ echo " Updating version to: ${NEW_VERSION} "
38+ sed -i.bak " s/^version = .*/version = \" ${NEW_VERSION} \" /" pyproject.toml
39+ rm pyproject.toml.bak
40+
41+ # Build the package
42+ echo " Building package..."
43+ uv build
44+
45+ # Publish to PyPI
46+ echo " Publishing to PyPI..."
47+ uv publish --token " ${PYPI_TOKEN} "
48+
49+ echo " ✅ Successfully published policyengine_api_${SERVICE// -/ _} _client version ${NEW_VERSION} "
50+
51+ cd ../../../../../
52+ }
53+
54+ # Check if PYPI_TOKEN is set
55+ if [ -z " ${PYPI_TOKEN} " ]; then
56+ echo " ❌ PYPI_TOKEN environment variable is not set"
57+ exit 1
58+ fi
59+
60+ # Publish both clients
61+ publish_client " full"
62+ publish_client " simulation"
63+
64+ echo " ✅ All clients published successfully!"
0 commit comments