Skip to content

Commit

Permalink
fix: iOS status check loop
Browse files Browse the repository at this point in the history
  • Loading branch information
phani-srikar committed Jul 16, 2023
1 parent db97995 commit d8fce90
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
26 changes: 19 additions & 7 deletions .codebuild/scripts/run-ios-modelgen-e2e-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ get_latest_run_id() {
echo "$latest_run_id"
}

# Function to get the status of a workflow run
# Function to get the status of a workflow run - can be queued or in_progress or completed
get_run_status() {
run_id="$1"
run_status=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
Expand All @@ -24,6 +24,17 @@ get_run_status() {
echo "$run_status"
}

# Function to get the status of a test run - can be success or failure
get_test_status() {
run_id="$1"
test_status=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/actions/runs/$run_id" | \
jq -r '.conclusion')
echo "$test_status"
}

# Function to trigger a workflow dispatch event to run the e2e test
trigger_workflow() {
curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
Expand All @@ -40,24 +51,25 @@ main() {
# Get the latest run ID and initial status
latest_run_id=$(get_latest_run_id)
echo "Latest run ID: $latest_run_id"
latest_status=$(get_run_status "$latest_run_id")
run_status=$(get_run_status "$latest_run_id")
timeout=$((SECONDS + 600)) # 600 seconds = 10 minutes

# Continuously check for status until completion
while [[ "$latest_status" != "completed" && "$SECONDS" -lt "$timeout" ]]; do
while [[ "$run_status" != "completed" && "$SECONDS" -lt "$timeout" ]]; do
echo "Test run status: $latest_status"
sleep 10 # Wait before checking again
latest_status=$(get_run_status "$latest_run_id")
run_status=$(get_run_status "$latest_run_id")
done

# Check if the run completed within the specified duration
if [[ "$latest_status" != "completed" ]]; then
if [[ "$run_status" != "completed" ]]; then
echo "The test run did not complete within the specified duration."
exit 1
fi

# Check if the run failed and throw an error if it did
if [[ "$latest_status" == "failure" ]]; then
test_status=$(get_test_status "$latest_run_id")
# Check if the test failed and throw an error if it did
if [[ "$test_status" != "success" ]]; then
echo "The test run failed."
exit 1
else
Expand Down
11 changes: 3 additions & 8 deletions scripts/test-swift-modelgen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,17 @@ function buildModels() {

function buildAndRunModel() {
modelName=$1
cd $modelName
currentDirectory=$(pwd)

pathToSwiftPackage=$2

# copy with replace all files in current directory to the swift package
# copy with replace all model files to the swift package
mkdir -p $pathToSwiftPackage/Sources/models
rm -rf $pathToSwiftPackage/Sources/models/*
cp -r $currentDirectory/* $pathToSwiftPackage/Sources/models
cp -r $modelName/* $pathToSwiftPackage/Sources/models
ls $pathToSwiftPackage/Sources/models

# build and run the model
cd $pathToSwiftPackage
swift build && swift run

# clean up
cd $currentDirectory
}

function createSwiftPackage() {
Expand Down

0 comments on commit d8fce90

Please sign in to comment.