Skip to content

Commit 6f74f64

Browse files
authored
Merge pull request #2547 from PolicyEngine/fix/properly-install-jq
Ensure that when API v1 attempts deploy, API v2 runs with required model version
2 parents 173b9fb + d79b3f2 commit 6f74f64

4 files changed

Lines changed: 64 additions & 8 deletions

File tree

.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)

.github/request-model-versions.sh renamed to .github/request-simulation-model-versions.sh

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
set -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

88
usage() {
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]+$
9898
fi
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"
103103
WORKFLOW_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-
110105
echo "Starting workflow execution..."
111106
echo "Project: $PROJECT_ID"
112107
echo "Location: $WORKFLOW_LOCATION"
@@ -134,6 +129,7 @@ echo "Input: $INPUT_JSON"
134129
# Execute workflow
135130
echo "Executing workflow..."
136131
EXECUTION_RESULT=$(gcloud workflows execute "$WORKFLOW_NAME" \
132+
--project="$PROJECT_ID" \
137133
--location="$WORKFLOW_LOCATION" \
138134
--data="$INPUT_JSON" \
139135
--format="json")

.github/workflows/push.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,31 @@ jobs:
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: |

changelog_entry.yaml

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

0 commit comments

Comments
 (0)