Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 42 additions & 9 deletions .github/find-api-model-versions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import argparse
import os
import sys
from policyengine_api.constants import COUNTRY_PACKAGE_VERSIONS

from policyengine_api.constants import (
COUNTRY_PACKAGE_VERSIONS,
POLICYENGINE_CORE_VERSION,
POLICYENGINE_VERSION,
)

def find_api_model_versions_and_output_to_github():

def find_api_model_versions() -> dict[str, str]:
"""
Find the API model versions and output them to a file for GitHub.
Find the API model versions from the installed PolicyEngine bundle.
"""
# Try to get package versions for US and UK
us_version = COUNTRY_PACKAGE_VERSIONS.get("us")
uk_version = COUNTRY_PACKAGE_VERSIONS.get("uk")

Expand All @@ -19,13 +24,41 @@ def find_api_model_versions_and_output_to_github():
print("Error: UK package version not found.", file=sys.stderr)
sys.exit(1)

# Write to GitHub Actions environment
if not POLICYENGINE_VERSION:
print("Error: PolicyEngine package version not found.", file=sys.stderr)
sys.exit(1)

return {
"POLICYENGINE_VERSION": POLICYENGINE_VERSION,
"POLICYENGINE_CORE_VERSION": POLICYENGINE_CORE_VERSION,
"US_VERSION": us_version,
"UK_VERSION": uk_version,
}


def find_api_model_versions_and_output_to_github():
"""
Find the API model versions and output them to a file for GitHub.
"""
versions = find_api_model_versions()
with open(os.environ["GITHUB_ENV"], "a") as f:
f.write(f"US_VERSION={us_version}\n")
f.write(f"UK_VERSION={uk_version}\n")
for key, value in versions.items():
f.write(f"{key}={value}\n")


if __name__ == "__main__":
find_api_model_versions_and_output_to_github()
print("API model versions found and written to GitHub environment.")
parser = argparse.ArgumentParser()
parser.add_argument(
"--shell",
action="store_true",
help="Print shell-compatible KEY=VALUE lines instead of writing GITHUB_ENV.",
)
args = parser.parse_args()

if args.shell:
for key, value in find_api_model_versions().items():
print(f"{key}={value}")
else:
find_api_model_versions_and_output_to_github()
print("API model versions found and written to GitHub environment.")
sys.exit(0)
92 changes: 64 additions & 28 deletions .github/request-simulation-model-versions.sh
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
#!/usr/bin/env bash

set -e

# Modal Gateway version check script
# Verifies that the US package version used by API v1 is deployed
# in the Modal simulation API before allowing API v1 deployment to proceed.
#
# NOTE: We explicitly do NOT check for UK versions here. The UK package
# (policyengine-uk) does not support the older Python versions that API v1
# runs on, so the UK version deployed to Modal may not match the version
# pinned in API v1's requirements.
#
# Usage: ./request-simulation-model-versions.sh -us <us_version>
set -euo pipefail

# Modal gateway version check script.
# Verifies that the PolicyEngine .py bundle used by API v1 is deployed in the
# simulation gateway before allowing API v1 deployment to proceed. US/UK
# versions are optional compatibility checks that should resolve to the same
# gateway app as the .py bundle route.

GATEWAY_URL="${SIMULATION_API_URL:-https://policyengine--policyengine-simulation-gateway-web-app.modal.run}"

usage() {
echo "Usage: $0 -us <us_version>"
echo "Usage: $0 -py <policyengine_version> [-us <us_version>] [-uk <uk_version>]"
echo ""
echo "Required flags:"
echo " -us us_version - US package version (e.g., 1.459.0)"
echo " -py, --policyengine policyengine_version PolicyEngine .py bundle version"
echo ""
echo "Optional compatibility checks:"
echo " -us us_version Expected bundled policyengine-us version"
echo " -uk uk_version Expected bundled policyengine-uk version"
exit 1
}

POLICYENGINE_VERSION=""
US_VERSION=""
UK_VERSION=""

while [ $# -gt 0 ]; do
case "$1" in
-py|--policyengine)
POLICYENGINE_VERSION="$2"
shift 2
;;
-us)
US_VERSION="$2"
shift 2
;;
-uk)
# Accept but ignore UK version flag for backwards compatibility
echo "Note: UK version check is disabled (see script comments)"
UK_VERSION="$2"
shift 2
;;
-h|--help)
Expand All @@ -46,34 +50,66 @@ while [ $# -gt 0 ]; do
esac
done

if [ -z "$US_VERSION" ]; then
echo "Error: -us version is required"
if [ -z "$POLICYENGINE_VERSION" ]; then
echo "Error: -py/--policyengine version is required"
usage
fi

echo "Checking Modal simulation API versions..."
echo " Gateway: $GATEWAY_URL"
echo " Expected US version: $US_VERSION"
echo " Expected PolicyEngine .py bundle: $POLICYENGINE_VERSION"
if [ -n "$US_VERSION" ]; then
echo " Expected policyengine-us: $US_VERSION"
fi
if [ -n "$UK_VERSION" ]; then
echo " Expected policyengine-uk: $UK_VERSION"
fi
echo ""

# Query the gateway for deployed versions
VERSIONS_RESPONSE=$(curl -s "${GATEWAY_URL}/versions")

if [ -z "$VERSIONS_RESPONSE" ]; then
echo "ERROR: Failed to fetch versions from gateway"
exit 1
fi

# Check if US version is deployed
US_DEPLOYED=$(echo "$VERSIONS_RESPONSE" | jq -r --arg v "$US_VERSION" '.us[$v] // empty')
if [ -z "$US_DEPLOYED" ]; then
echo "ERROR: US version $US_VERSION is NOT deployed in Modal simulation API"
echo "Available US versions:"
echo "$VERSIONS_RESPONSE" | jq -r '.us | keys[]'
BUNDLE_APP=$(echo "$VERSIONS_RESPONSE" | jq -r --arg v "$POLICYENGINE_VERSION" '.policyengine[$v] // empty')
if [ -z "$BUNDLE_APP" ]; then
echo "ERROR: PolicyEngine .py bundle $POLICYENGINE_VERSION is NOT deployed in the simulation API"
echo "Available PolicyEngine versions:"
echo "$VERSIONS_RESPONSE" | jq -r '.policyengine | keys[]'
exit 1
fi
echo "US version $US_VERSION is deployed (app: $US_DEPLOYED)"
echo "PolicyEngine .py bundle $POLICYENGINE_VERSION is deployed (app: $BUNDLE_APP)"

check_country_route() {
local country="$1"
local version="$2"
local app

if [ -z "$version" ]; then
return
fi

app=$(echo "$VERSIONS_RESPONSE" | jq -r --arg country "$country" --arg v "$version" '.[$country][$v] // empty')
if [ -z "$app" ]; then
echo "ERROR: ${country} version ${version} is NOT deployed in the simulation API"
echo "Available ${country} versions:"
echo "$VERSIONS_RESPONSE" | jq -r --arg country "$country" '.[$country] | keys[]'
exit 1
fi

if [ "$app" != "$BUNDLE_APP" ]; then
echo "ERROR: ${country} version ${version} resolves to ${app}, not bundle app ${BUNDLE_APP}"
exit 1
fi

echo "${country} version ${version} resolves to the same app"
}

check_country_route "us" "$US_VERSION"
check_country_route "uk" "$UK_VERSION"

echo ""
echo "SUCCESS: US version is deployed and ready"
echo "SUCCESS: PolicyEngine bundle route is deployed and ready"
exit 0
122 changes: 0 additions & 122 deletions .github/scripts/update-package.sh

This file was deleted.

Loading
Loading