Skip to content

Commit 83ed92e

Browse files
authored
feat: Add script to request model versions (#2531)
1 parent 1253976 commit 83ed92e

2 files changed

Lines changed: 202 additions & 0 deletions

File tree

.github/request-model-versions.sh

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
#! /usr/bin/env bash
2+
3+
set -e
4+
5+
# 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]
7+
8+
usage() {
9+
echo "Usage: $0 -b <bucket_name> -us <us_version> -uk <uk_version> [-t timeout] [-i interval]"
10+
echo ""
11+
echo "Required flags:"
12+
echo " -b bucket_name - GCS bucket name"
13+
echo " -us us_version - US package version"
14+
echo " -uk uk_version - UK package version"
15+
echo ""
16+
echo "Optional flags:"
17+
echo " -t timeout_seconds - Maximum wait time in seconds (default: 300)"
18+
echo " -i check_interval - Check interval in seconds (default: 10)"
19+
echo " -h help - Show this help message"
20+
echo ""
21+
echo "Example:"
22+
echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4"
23+
echo " $0 -b my-bucket -us v1.2.3 -uk v1.2.4 -t 600 -i 15"
24+
exit 1
25+
}
26+
27+
# Initialize variables
28+
BUCKET_NAME=""
29+
US_VERSION=""
30+
UK_VERSION=""
31+
TIMEOUT_SECONDS="300"
32+
CHECK_INTERVAL="10"
33+
34+
# Parse command line arguments
35+
while [ $# -gt 0 ]; do
36+
case "$1" in
37+
-b)
38+
if [ -z "$2" ]; then
39+
echo "Error: -b requires a bucket name"
40+
exit 1
41+
fi
42+
BUCKET_NAME="$2"
43+
shift 2
44+
;;
45+
-us)
46+
if [ -z "$2" ]; then
47+
echo "Error: -us requires a US version"
48+
exit 1
49+
fi
50+
US_VERSION="$2"
51+
shift 2
52+
;;
53+
-uk)
54+
if [ -z "$2" ]; then
55+
echo "Error: -uk requires a UK version"
56+
exit 1
57+
fi
58+
UK_VERSION="$2"
59+
shift 2
60+
;;
61+
-t)
62+
if [ -z "$2" ]; then
63+
echo "Error: -t requires a timeout value"
64+
exit 1
65+
fi
66+
TIMEOUT_SECONDS="$2"
67+
shift 2
68+
;;
69+
-i)
70+
if [ -z "$2" ]; then
71+
echo "Error: -i requires an interval value"
72+
exit 1
73+
fi
74+
CHECK_INTERVAL="$2"
75+
shift 2
76+
;;
77+
-h)
78+
usage
79+
;;
80+
*)
81+
echo "Error: Unknown option $1"
82+
usage
83+
;;
84+
esac
85+
done
86+
87+
# Validate required arguments
88+
if [ -z "$BUCKET_NAME" ] || [ -z "$US_VERSION" ] || [ -z "$UK_VERSION" ]; then
89+
echo "Error: Missing required arguments"
90+
echo "bucket_name (-b), us_version (-us), and uk_version (-uk) are required"
91+
usage
92+
fi
93+
94+
# Validate numeric arguments
95+
if ! [[ "$TIMEOUT_SECONDS" =~ ^[0-9]+$ ]] || ! [[ "$CHECK_INTERVAL" =~ ^[0-9]+$ ]]; then
96+
echo "Error: timeout_seconds and check_interval must be positive integers"
97+
exit 1
98+
fi
99+
100+
# Configuration
101+
PROJECT_ID="${GOOGLE_CLOUD_PROJECT:-$(gcloud config get-value project 2>/dev/null)}"
102+
WORKFLOW_LOCATION="${WORKFLOW_LOCATION:-us-central1}"
103+
WORKFLOW_NAME="wait-for-country-packages"
104+
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+
110+
echo "Starting workflow execution..."
111+
echo "Project: $PROJECT_ID"
112+
echo "Location: $WORKFLOW_LOCATION"
113+
echo "Workflow: $WORKFLOW_NAME"
114+
echo "Bucket: $BUCKET_NAME"
115+
echo "US Version: $US_VERSION"
116+
echo "UK Version: $UK_VERSION"
117+
echo "Timeout: ${TIMEOUT_SECONDS}s"
118+
echo "Check Interval: ${CHECK_INTERVAL}s"
119+
120+
# Build input JSON
121+
INPUT_JSON=$(cat <<EOF
122+
{
123+
"bucket_name": "$BUCKET_NAME",
124+
"us_country_package_version": "$US_VERSION",
125+
"uk_country_package_version": "$UK_VERSION",
126+
"timeout_seconds": $TIMEOUT_SECONDS,
127+
"check_interval": $CHECK_INTERVAL
128+
}
129+
EOF
130+
)
131+
132+
echo "Input: $INPUT_JSON"
133+
134+
# Execute workflow
135+
echo "Executing workflow..."
136+
EXECUTION_RESULT=$(gcloud workflows execute "$WORKFLOW_NAME" \
137+
--location="$WORKFLOW_LOCATION" \
138+
--data="$INPUT_JSON" \
139+
--format="json")
140+
141+
# Extract execution name
142+
EXECUTION_NAME=$(echo "$EXECUTION_RESULT" | jq -r '.name')
143+
144+
if [ -z "$EXECUTION_NAME" ] || [ "$EXECUTION_NAME" = "null" ]; then
145+
echo "Failed to start workflow execution"
146+
echo "$EXECUTION_RESULT"
147+
exit 1
148+
fi
149+
150+
echo "Execution started: $EXECUTION_NAME"
151+
152+
# Monitor execution state
153+
START_TIME=$(date +%s)
154+
echo "Monitoring execution state..."
155+
156+
while true; do
157+
# Get current execution state
158+
EXECUTION_STATUS=$(gcloud workflows executions wait "$EXECUTION_NAME" \
159+
--location="$WORKFLOW_LOCATION" \
160+
--format="json")
161+
162+
STATE=$(echo "$EXECUTION_STATUS" | jq -r '.state')
163+
164+
echo "Current state: $STATE"
165+
166+
# Check if execution is complete
167+
if [ "$STATE" = "SUCCEEDED" ]; then
168+
echo "SUCCESS: Workflow completed successfully"
169+
RESULT=$(echo "$EXECUTION_STATUS" | jq -r '.result // empty')
170+
if [ -n "$RESULT" ] && [ "$RESULT" != "null" ]; then
171+
echo "Result: $RESULT"
172+
fi
173+
exit 0
174+
elif [ "$STATE" = "FAILED" ]; then
175+
echo "FAILED: Workflow execution failed"
176+
ERROR=$(echo "$EXECUTION_STATUS" | jq -r '.error // empty')
177+
if [ -n "$ERROR" ] && [ "$ERROR" != "null" ]; then
178+
echo "Error: $ERROR"
179+
fi
180+
exit 1
181+
elif [ "$STATE" = "CANCELLED" ]; then
182+
echo "CANCELLED: Workflow execution was cancelled"
183+
exit 1
184+
fi
185+
186+
# Check monitoring timeout
187+
CURRENT_TIME=$(date +%s)
188+
ELAPSED=$((CURRENT_TIME - START_TIME))
189+
190+
if [ $ELAPSED -ge $((TIMEOUT_SECONDS + 60)) ]; then
191+
echo "TIMEOUT: Monitoring timeout exceeded"
192+
echo "Workflow may still be running. Check Google Cloud Console for status."
193+
exit 1
194+
fi
195+
196+
# Wait before next check
197+
sleep "$CHECK_INTERVAL"
198+
done

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+
- Bash script to check for model versions within simulation API; not yet integrated into GitHub Actions.

0 commit comments

Comments
 (0)