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
31 changes: 31 additions & 0 deletions .github/find-api-model-versions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os
import sys
from policyengine_api.constants import COUNTRY_PACKAGE_VERSIONS


def find_api_model_versions_and_output_to_github():
"""
Find the API model versions and output them to a file for GitHub.
"""
# Try to get package versions for US and UK
us_version = COUNTRY_PACKAGE_VERSIONS.get("us")
uk_version = COUNTRY_PACKAGE_VERSIONS.get("uk")

if not us_version:
print("Error: US package version not found.", file=sys.stderr)
sys.exit(1)

if not uk_version:
print("Error: UK package version not found.", file=sys.stderr)
sys.exit(1)

# Write to GitHub Actions environment
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")


if __name__ == "__main__":
find_api_model_versions_and_output_to_github()
print("API model versions found and written to GitHub environment.")
sys.exit(0)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -e

# Google Cloud Workflow execution script
# Usage: ./wait_for_country_versions.sh -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]
# Usage: ./request-simulation-model-versions.sh -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]

usage() {
echo "Usage: $0 -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]"
Expand Down Expand Up @@ -98,15 +98,10 @@ if ! [[ "$TIMEOUT_SECONDS" =~ ^[0-9]+$ ]] || ! [[ "$CHECK_INTERVAL" =~ ^[0-9]+$
fi

# Configuration
PROJECT_ID="${GOOGLE_CLOUD_PROJECT:-$(gcloud config get-value project 2>/dev/null)}"
WORKFLOW_LOCATION="${WORKFLOW_LOCATION:-us-central1}"
PROJECT_ID="prod-api-v2-c4d5"
WORKFLOW_LOCATION="us-central1"
WORKFLOW_NAME="wait-for-country-packages"

if [ -z "$PROJECT_ID" ]; then
echo "Error: Could not determine project ID. Set GOOGLE_CLOUD_PROJECT environment variable."
exit 1
fi

echo "Starting workflow execution..."
echo "Project: $PROJECT_ID"
echo "Location: $WORKFLOW_LOCATION"
Expand Down Expand Up @@ -134,6 +129,7 @@ echo "Input: $INPUT_JSON"
# Execute workflow
echo "Executing workflow..."
EXECUTION_RESULT=$(gcloud workflows execute "$WORKFLOW_NAME" \
--project="$PROJECT_ID" \
--location="$WORKFLOW_LOCATION" \
--data="$INPUT_JSON" \
--format="json")
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,31 @@ jobs:
uses: "lgeiger/black-action@master"
with:
args: ". -l 79 --check"
ensure-model-version-aligns-with-sim-api:
name: Ensure model version aligns with simulation API
runs-on: ubuntu-latest
if: |
(github.repository == 'PolicyEngine/policyengine-api')
&& (github.event.head_commit.message == 'Update PolicyEngine API')
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: GCP authentication
uses: "google-github-actions/auth@v2"
with:
credentials_json: "${{ secrets.GCP_SA_KEY }}"
- name: Install dependencies (required for finding API model versions)
run: make install
- name: Install jq (required only for GitHub Actions)
run: sudo apt-get install -y jq
- name: Find API model versions and write to environment variable
run: python3 .github/find-api-model-versions.py
- name: Ensure full API and simulation API model versions are in sync
run: ".github/request-simulation-model-versions.sh -b prod-api-v2-c4d5-metadata -us ${{ env.US_VERSION }} -uk ${{ env.UK_VERSION }}"
versioning:
name: Update versioning
if: |
Expand Down
4 changes: 4 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- bump: patch
changes:
added:
- GitHub Actions workflow to prevent deployment if simulation API does not possess model version defined in full API
Loading