File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 )
Original file line number Diff line number Diff line change 33set -e
44
55# Google Cloud Workflow execution script
6- # Usage: ./wait_for_country_versions .sh -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]
6+ # Usage: ./request-simulation-model-versions .sh -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]
77
88usage () {
99 echo " Usage: $0 -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]"
@@ -98,15 +98,10 @@ if ! [[ "$TIMEOUT_SECONDS" =~ ^[0-9]+$ ]] || ! [[ "$CHECK_INTERVAL" =~ ^[0-9]+$
9898fi
9999
100100# Configuration
101- PROJECT_ID=" ${GOOGLE_CLOUD_PROJECT :- $(gcloud config get-value project 2> / dev / null)} "
102- WORKFLOW_LOCATION=" ${WORKFLOW_LOCATION :- us-central1} "
101+ PROJECT_ID=" prod-api-v2-c4d5 "
102+ WORKFLOW_LOCATION=" us-central1"
103103WORKFLOW_NAME=" wait-for-country-packages"
104104
105- if [ -z " $PROJECT_ID " ]; then
106- echo " Error: Could not determine project ID. Set GOOGLE_CLOUD_PROJECT environment variable."
107- exit 1
108- fi
109-
110105echo " Starting workflow execution..."
111106echo " Project: $PROJECT_ID "
112107echo " Location: $WORKFLOW_LOCATION "
@@ -134,6 +129,7 @@ echo "Input: $INPUT_JSON"
134129# Execute workflow
135130echo " Executing workflow..."
136131EXECUTION_RESULT=$( gcloud workflows execute " $WORKFLOW_NAME " \
132+ --project=" $PROJECT_ID " \
137133 --location=" $WORKFLOW_LOCATION " \
138134 --data=" $INPUT_JSON " \
139135 --format=" json" )
Original file line number Diff line number Diff line change 2424 uses : " lgeiger/black-action@master"
2525 with :
2626 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 }}"
2752 versioning :
2853 name : Update versioning
2954 if : |
Original file line number Diff line number Diff line change 1+ - bump : patch
2+ changes :
3+ added :
4+ - GitHub Actions workflow to prevent deployment if simulation API does not possess model version defined in full API
You can’t perform that action at this time.
0 commit comments