From d8fce90e9c4c67982513dbba11b7025c7a447dfc Mon Sep 17 00:00:00 2001 From: phani-srikar Date: Sun, 16 Jul 2023 12:39:59 -0700 Subject: [PATCH] fix: iOS status check loop --- .../scripts/run-ios-modelgen-e2e-test.sh | 26 ++++++++++++++----- scripts/test-swift-modelgen.sh | 11 +++----- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/.codebuild/scripts/run-ios-modelgen-e2e-test.sh b/.codebuild/scripts/run-ios-modelgen-e2e-test.sh index fc0a4da0..def3b027 100755 --- a/.codebuild/scripts/run-ios-modelgen-e2e-test.sh +++ b/.codebuild/scripts/run-ios-modelgen-e2e-test.sh @@ -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" \ @@ -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" \ @@ -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 diff --git a/scripts/test-swift-modelgen.sh b/scripts/test-swift-modelgen.sh index 5ede0d90..75611918 100755 --- a/scripts/test-swift-modelgen.sh +++ b/scripts/test-swift-modelgen.sh @@ -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() {