diff --git a/.github/find-api-model-versions.py b/.github/find-api-model-versions.py new file mode 100644 index 000000000..0c0f53fcc --- /dev/null +++ b/.github/find-api-model-versions.py @@ -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) diff --git a/.github/install-jq.sh b/.github/install-jq.sh new file mode 100644 index 000000000..45562a138 --- /dev/null +++ b/.github/install-jq.sh @@ -0,0 +1,6 @@ +#! /usr/bin/env bash + +set -e + +apt-get update +apt-get install -y jq \ No newline at end of file diff --git a/.github/request-model-versions.sh b/.github/request-simulation-model-versions.sh similarity index 87% rename from .github/request-model-versions.sh rename to .github/request-simulation-model-versions.sh index cfd8c164c..8e563dc65 100755 --- a/.github/request-model-versions.sh +++ b/.github/request-simulation-model-versions.sh @@ -3,10 +3,10 @@ set -e # Google Cloud Workflow execution script -# Usage: ./wait_for_country_versions.sh -b -us -uk [-t timeout] [-i interval] +# Usage: ./request-simulation-model-versions.sh -b -us -uk [-t timeout] [-i interval] usage() { - echo "Usage: $0 -b -us -uk [-t timeout] [-i interval]" + echo "Usage: $0 -us -uk [-t timeout] [-i interval]" echo "" echo "Required flags:" echo " -b bucket_name - GCS bucket name" @@ -19,8 +19,8 @@ usage() { echo " -h help - Show this help message" echo "" echo "Example:" - echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4" - echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4 -t 600 -i 15" + echo " $0 -us v1.2.3 -uk v1.2.4" + echo " $0 -us v1.2.3 -uk v1.2.4 -t 600 -i 15" exit 1 } @@ -34,6 +34,9 @@ CHECK_INTERVAL="10" # Parse command line arguments while [ $# -gt 0 ]; do case "$1" in + -h|--help) + usage + ;; -b) if [ -z "$2" ]; then echo "Error: -b requires a bucket name" @@ -85,7 +88,7 @@ while [ $# -gt 0 ]; do done # Validate required arguments -if [ -z "$BUCKET_NAME" ] || [ -z "$US_VERSION" ] || [ -z "$UK_VERSION" ]; then +if [ -z "$BUCKET_NAME" ] || -z "$US_VERSION" ] || [ -z "$UK_VERSION" ]; then echo "Error: Missing required arguments" echo "bucket_name (-b), us_version (-us), and uk_version (-uk) are required" usage @@ -98,15 +101,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" @@ -134,6 +132,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") diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 4b89edcd0..e430f10f0 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -65,6 +65,14 @@ jobs: uses: actions/setup-python@v5 with: python-version: "3.11" + - name: Install dependencies (required for finding API model versions) + run: make install + - name: Install jq (required only for GitHub Actions) + run: ".github/install-jq.sh" + - 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 }}" - name: GCP authentication uses: "google-github-actions/auth@v2" with: diff --git a/changelog_entry.yaml b/changelog_entry.yaml index e69de29bb..e35b15ed4 100644 --- a/changelog_entry.yaml +++ b/changelog_entry.yaml @@ -0,0 +1,4 @@ +- bump: minor + changes: + added: + - GitHub Actions checks that full API and simulation API model versions are in sync \ No newline at end of file