Skip to content

Commit 82dd57b

Browse files
committed
Merge remote-tracking branch 'origin/master' into SonaliBedge/2237-tracer-get-method-handling-invalid-input-incorrectly
2 parents 2e318e1 + 1a10cda commit 82dd57b

34 files changed

Lines changed: 1861 additions & 736 deletions

.coveragerc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[run]
2+
source = policyengine_api
3+
4+
[report]
5+
omit =
6+
tests/*
7+
*/tests/*
8+
tests/conftest.py
9+

.github/find-api-model-versions.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import os
2+
import sys
3+
from policyengine_api.constants import COUNTRY_PACKAGE_VERSIONS
4+
5+
6+
def find_api_model_versions_and_output_to_github():
7+
"""
8+
Find the API model versions and output them to a file for GitHub.
9+
"""
10+
# Try to get package versions for US and UK
11+
us_version = COUNTRY_PACKAGE_VERSIONS.get("us")
12+
uk_version = COUNTRY_PACKAGE_VERSIONS.get("uk")
13+
14+
if not us_version:
15+
print("Error: US package version not found.", file=sys.stderr)
16+
sys.exit(1)
17+
18+
if not uk_version:
19+
print("Error: UK package version not found.", file=sys.stderr)
20+
sys.exit(1)
21+
22+
# Write to GitHub Actions environment
23+
with open(os.environ["GITHUB_ENV"], "a") as f:
24+
f.write(f"US_VERSION={us_version}\n")
25+
f.write(f"UK_VERSION={uk_version}\n")
26+
27+
28+
if __name__ == "__main__":
29+
find_api_model_versions_and_output_to_github()
30+
print("API model versions found and written to GitHub environment.")
31+
sys.exit(0)
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
5+
# Google Cloud Workflow execution script
6+
# Usage: ./request-simulation-model-versions.sh -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]
7+
8+
usage() {
9+
echo "Usage: $0 -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]"
10+
echo ""
11+
echo "Required flags:"
12+
echo " -b bucket_name - GCS bucket name"
13+
echo " -us us_version - US package version"
14+
echo " -uk uk_version - UK package version"
15+
echo ""
16+
echo "Optional flags:"
17+
echo " -t timeout_seconds - Maximum wait time in seconds (default: 300)"
18+
echo " -i check_interval - Check interval in seconds (default: 10)"
19+
echo " -h help - Show this help message"
20+
echo ""
21+
echo "Example:"
22+
echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4"
23+
echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4 -t 600 -i 15"
24+
exit 1
25+
}
26+
27+
# Initialize variables
28+
BUCKET_NAME=""
29+
US_VERSION=""
30+
UK_VERSION=""
31+
TIMEOUT_SECONDS="300"
32+
CHECK_INTERVAL="10"
33+
34+
# Parse command line arguments
35+
while [ $# -gt 0 ]; do
36+
case "$1" in
37+
-b)
38+
if [ -z "$2" ]; then
39+
echo "Error: -b requires a bucket name"
40+
exit 1
41+
fi
42+
BUCKET_NAME="$2"
43+
shift 2
44+
;;
45+
-us)
46+
if [ -z "$2" ]; then
47+
echo "Error: -us requires a US version"
48+
exit 1
49+
fi
50+
US_VERSION="$2"
51+
shift 2
52+
;;
53+
-uk)
54+
if [ -z "$2" ]; then
55+
echo "Error: -uk requires a UK version"
56+
exit 1
57+
fi
58+
UK_VERSION="$2"
59+
shift 2
60+
;;
61+
-t)
62+
if [ -z "$2" ]; then
63+
echo "Error: -t requires a timeout value"
64+
exit 1
65+
fi
66+
TIMEOUT_SECONDS="$2"
67+
shift 2
68+
;;
69+
-i)
70+
if [ -z "$2" ]; then
71+
echo "Error: -i requires an interval value"
72+
exit 1
73+
fi
74+
CHECK_INTERVAL="$2"
75+
shift 2
76+
;;
77+
-h)
78+
usage
79+
;;
80+
*)
81+
echo "Error: Unknown option $1"
82+
usage
83+
;;
84+
esac
85+
done
86+
87+
# Validate required arguments
88+
if [ -z "$BUCKET_NAME" ] || [ -z "$US_VERSION" ] || [ -z "$UK_VERSION" ]; then
89+
echo "Error: Missing required arguments"
90+
echo "bucket_name (-b), us_version (-us), and uk_version (-uk) are required"
91+
usage
92+
fi
93+
94+
# Validate numeric arguments
95+
if ! [[ "$TIMEOUT_SECONDS" =~ ^[0-9]+$ ]] || ! [[ "$CHECK_INTERVAL" =~ ^[0-9]+$ ]]; then
96+
echo "Error: timeout_seconds and check_interval must be positive integers"
97+
exit 1
98+
fi
99+
100+
# Configuration
101+
PROJECT_ID="prod-api-v2-c4d5"
102+
WORKFLOW_LOCATION="us-central1"
103+
WORKFLOW_NAME="wait-for-country-packages"
104+
105+
echo "Starting workflow execution..."
106+
echo "Project: $PROJECT_ID"
107+
echo "Location: $WORKFLOW_LOCATION"
108+
echo "Workflow: $WORKFLOW_NAME"
109+
echo "Bucket: $BUCKET_NAME"
110+
echo "US Version: $US_VERSION"
111+
echo "UK Version: $UK_VERSION"
112+
echo "Timeout: ${TIMEOUT_SECONDS}s"
113+
echo "Check Interval: ${CHECK_INTERVAL}s"
114+
115+
# Build input JSON
116+
INPUT_JSON=$(cat <<EOF
117+
{
118+
"bucket_name": "$BUCKET_NAME",
119+
"us_country_package_version": "$US_VERSION",
120+
"uk_country_package_version": "$UK_VERSION",
121+
"timeout_seconds": $TIMEOUT_SECONDS,
122+
"check_interval": $CHECK_INTERVAL
123+
}
124+
EOF
125+
)
126+
127+
echo "Input: $INPUT_JSON"
128+
129+
# Execute workflow
130+
echo "Executing workflow..."
131+
EXECUTION_RESULT=$(gcloud workflows execute "$WORKFLOW_NAME" \
132+
--project="$PROJECT_ID" \
133+
--location="$WORKFLOW_LOCATION" \
134+
--data="$INPUT_JSON" \
135+
--format="json")
136+
137+
# Extract execution name
138+
EXECUTION_NAME=$(echo "$EXECUTION_RESULT" | jq -r '.name')
139+
140+
if [ -z "$EXECUTION_NAME" ] || [ "$EXECUTION_NAME" = "null" ]; then
141+
echo "Failed to start workflow execution"
142+
echo "$EXECUTION_RESULT"
143+
exit 1
144+
fi
145+
146+
echo "Execution started: $EXECUTION_NAME"
147+
148+
# Monitor execution state
149+
START_TIME=$(date +%s)
150+
echo "Monitoring execution state..."
151+
152+
while true; do
153+
# Get current execution state
154+
EXECUTION_STATUS=$(gcloud workflows executions wait "$EXECUTION_NAME" \
155+
--location="$WORKFLOW_LOCATION" \
156+
--format="json")
157+
158+
STATE=$(echo "$EXECUTION_STATUS" | jq -r '.state')
159+
160+
echo "Current state: $STATE"
161+
162+
# Check if execution is complete
163+
if [ "$STATE" = "SUCCEEDED" ]; then
164+
echo "SUCCESS: Workflow completed successfully"
165+
RESULT=$(echo "$EXECUTION_STATUS" | jq -r '.result // empty')
166+
if [ -n "$RESULT" ] && [ "$RESULT" != "null" ]; then
167+
echo "Result: $RESULT"
168+
fi
169+
exit 0
170+
elif [ "$STATE" = "FAILED" ]; then
171+
echo "FAILED: Workflow execution failed"
172+
ERROR=$(echo "$EXECUTION_STATUS" | jq -r '.error // empty')
173+
if [ -n "$ERROR" ] && [ "$ERROR" != "null" ]; then
174+
echo "Error: $ERROR"
175+
fi
176+
exit 1
177+
elif [ "$STATE" = "CANCELLED" ]; then
178+
echo "CANCELLED: Workflow execution was cancelled"
179+
exit 1
180+
fi
181+
182+
# Check monitoring timeout
183+
CURRENT_TIME=$(date +%s)
184+
ELAPSED=$((CURRENT_TIME - START_TIME))
185+
186+
if [ $ELAPSED -ge $((TIMEOUT_SECONDS + 60)) ]; then
187+
echo "TIMEOUT: Monitoring timeout exceeded"
188+
echo "Workflow may still be running. Check Google Cloud Console for status."
189+
exit 1
190+
fi
191+
192+
# Wait before next check
193+
sleep "$CHECK_INTERVAL"
194+
done

.github/workflows/push.yml

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
env:
99
ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true
1010

11+
concurrency:
12+
group: deploy
13+
1114
jobs:
1215
Lint:
1316
runs-on: ubuntu-latest
@@ -21,6 +24,31 @@ jobs:
2124
uses: "lgeiger/black-action@master"
2225
with:
2326
args: ". -l 79 --check"
27+
ensure-model-version-aligns-with-sim-api:
28+
name: Ensure model version aligns with simulation API
29+
runs-on: ubuntu-latest
30+
if: |
31+
(github.repository == 'PolicyEngine/policyengine-api')
32+
&& (github.event.head_commit.message == 'Update PolicyEngine API')
33+
steps:
34+
- name: Checkout repo
35+
uses: actions/checkout@v4
36+
- name: Setup Python
37+
uses: actions/setup-python@v5
38+
with:
39+
python-version: "3.11"
40+
- name: GCP authentication
41+
uses: "google-github-actions/auth@v2"
42+
with:
43+
credentials_json: "${{ secrets.GCP_SA_KEY }}"
44+
- name: Install dependencies (required for finding API model versions)
45+
run: make install
46+
- name: Install jq (required only for GitHub Actions)
47+
run: sudo apt-get install -y jq
48+
- name: Find API model versions and write to environment variable
49+
run: python3 .github/find-api-model-versions.py
50+
- name: Ensure full API and simulation API model versions are in sync
51+
run: ".github/request-simulation-model-versions.sh -b prod-api-v2-c4d5-metadata -us ${{ env.US_VERSION }} -uk ${{ env.UK_VERSION }}"
2452
versioning:
2553
name: Update versioning
2654
if: |
@@ -92,4 +120,4 @@ jobs:
92120
- name: Build container
93121
run: docker build -t ghcr.io/policyengine/policyengine docker
94122
- name: Push container
95-
run: docker push ghcr.io/policyengine/policyengine
123+
run: docker push ghcr.io/policyengine/policyengine

0 commit comments

Comments
 (0)