Skip to content

Commit f69c53c

Browse files
Update actions
1 parent 91f3bcc commit f69c53c

6 files changed

Lines changed: 125 additions & 1 deletion

File tree

.github/workflows/deploy.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,12 @@ jobs:
3939
with:
4040
environment: prod
4141
secrets: inherit
42+
43+
publish_clients:
44+
name: Publish API clients
45+
needs: [deploy_prod]
46+
uses: ./.github/workflows/publish-clients.reusable.yml
47+
with:
48+
environment: prod
49+
secrets:
50+
PYPI_TOKEN: ${{ secrets.PYPI }}

.github/workflows/gcp-deploy.reusable.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,4 @@ jobs:
190190
simulation_integ_test_access_token: ${{ steps.get-simulation-id-token.outputs.id_token }}
191191
simulation_integ_test_base_url: ${{ needs.deploy.outputs.simulation_api_url }}
192192
workflow_integ_test_project_id: ${{ vars.PROJECT_ID }}
193-
workflow_integ_test_us_model_version: ${{ steps.versions.outputs.us_version }}
193+
workflow_integ_test_us_model_version: ${{ needs.deploy.outputs.release_metadata.models.us }}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Reusable publish clients workflow
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
required: true
8+
type: string
9+
description: 'The environment that was deployed (e.g., beta, prod)'
10+
secrets:
11+
PYPI_TOKEN:
12+
required: true
13+
description: 'PyPI API token for publishing packages'
14+
15+
jobs:
16+
publish:
17+
name: Publish API clients
18+
runs-on: ubuntu-latest
19+
environment: ${{ inputs.environment }}
20+
21+
steps:
22+
- name: Checkout repo
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: '3.13'
29+
30+
- name: Install uv
31+
uses: astral-sh/setup-uv@v3
32+
33+
- name: Generate API clients
34+
run: |
35+
./scripts/generate-clients.sh
36+
37+
- name: Publish clients to PyPI
38+
env:
39+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
40+
run: |
41+
./scripts/publish-clients.sh

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ generate-clients:
9292
@echo "Generating API clients..."
9393
@./scripts/generate-clients.sh
9494

95+
publish-clients: generate-clients
96+
@echo "Publishing API clients to PyPI..."
97+
@if [ -z "$(PYPI_TOKEN)" ]; then \
98+
echo "Please set PYPI_TOKEN environment variable"; \
99+
exit 1; \
100+
fi
101+
@PYPI_TOKEN=$(PYPI_TOKEN) ./scripts/publish-clients.sh
102+
95103
# Testing
96104
test:
97105
@echo "Running tests for all services..."

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ The repository includes automated deployment pipelines:
114114
- Deploys to beta environment
115115
- Runs integration tests
116116
- Deploys to production
117+
- Publishes API client packages to PyPI
117118

118119
Configure GitHub environments with these variables:
119120
- `PROJECT_ID`: GCP project ID
@@ -146,6 +147,7 @@ Configure GitHub environments with these variables:
146147
- `make terraform-plan` - Preview infrastructure changes
147148
- `make terraform-import` - Import existing resources
148149
- `make terraform-destroy` - Remove all infrastructure
150+
- `make publish-clients` - Publish API clients to PyPI (requires PYPI_TOKEN)
149151

150152
## Troubleshooting
151153

scripts/publish-clients.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)