From 90fb62f5111693f696117597b808b6d1ac153cf8 Mon Sep 17 00:00:00 2001 From: phani-srikar Date: Thu, 13 Jul 2023 17:34:03 -0700 Subject: [PATCH 1/4] chore: make the script executable --- .codebuild/scripts/run-ios-modelgen-e2e-test.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 .codebuild/scripts/run-ios-modelgen-e2e-test.sh diff --git a/.codebuild/scripts/run-ios-modelgen-e2e-test.sh b/.codebuild/scripts/run-ios-modelgen-e2e-test.sh old mode 100644 new mode 100755 From 93b2388fdb671c19cda0a1db30eb2d1a3420ad6c Mon Sep 17 00:00:00 2001 From: phani-srikar Date: Fri, 14 Jul 2023 10:37:01 -0700 Subject: [PATCH 2/4] chore: add gh workflow --- .github/workflows/build-swift-modelgen.yml | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/build-swift-modelgen.yml diff --git a/.github/workflows/build-swift-modelgen.yml b/.github/workflows/build-swift-modelgen.yml new file mode 100644 index 000000000..0973cc6ed --- /dev/null +++ b/.github/workflows/build-swift-modelgen.yml @@ -0,0 +1,37 @@ +name: 'Test compiling Swift Modelgen output' + +on: + workflow_dispatch: + inputs: + MODELS_S3_URL: + description: 'S3 URL for models' + required: true + +env: + MODELS_S3_URL: ${{ inputs.MODELS_S3_URL }} + +jobs: + Build-Swift-Modelgen: + name: Analyze + runs-on: macos-13-xl + permissions: + actions: read + contents: read + + strategy: + fail-fast: true + + steps: + - name: Mask S3 URL + run: echo "::add-mask::$MODELS_S3_URL" + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Check Xcode and Swift versions + run: | + xcodebuild -version + swift --version + + - name: Build Swift Models + run: ./scripts/test-swift-modelgen.sh From 5c28cff726eacd0b3ee0ccb7ca6320d295a2fec4 Mon Sep 17 00:00:00 2001 From: phani-srikar Date: Fri, 14 Jul 2023 10:40:24 -0700 Subject: [PATCH 3/4] chore: add test script --- scripts/test-swift-modelgen.sh | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 scripts/test-swift-modelgen.sh diff --git a/scripts/test-swift-modelgen.sh b/scripts/test-swift-modelgen.sh new file mode 100644 index 000000000..7d52f1893 --- /dev/null +++ b/scripts/test-swift-modelgen.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# set exit on error to true +set -e + +function buildModels() { + # download and unzip the models from S3 + tempDirectory=$(mktemp -d) + cd $tempDirectory + wget -O models.zip "$MODELS_S3_URL" + tar -xvf models.zip + + # create a Swift package to test the models + pathToSwiftPackage=${tempDirectory}/swiftapp + rm -rf $pathToSwiftPackage + mkdir $pathToSwiftPackage && cd $pathToSwiftPackage + echo "Creating Swift package at $pathToSwiftPackage" + createSwiftPackage + + cd ${tempDirectory}/models + for model in */; do + echo "Building model $model" + buildAndRunModel $model $pathToSwiftPackage + done +} + +function buildAndRunModel() { + pwd && ls + modelName=$1 + ls $modelName && cd $modelName + currentDirectory=$(pwd) + pwd && ls + + pathToSwiftPackage=$2 + + # copy with replace all files in current directory to the swift package + mkdir -p $pathToSwiftPackage/Sources/models + rm -rf $pathToSwiftPackage/Sources/models/* + cp -r $currentDirectory/* $pathToSwiftPackage/Sources/models + + # build and run the model + cd $pathToSwiftPackage + ls Sources/models + swift build && swift run + + # clean up + cd $currentDirectory +} + +function createSwiftPackage() { + # create a swift package + swift package init --type executable + rm -rf Package.swift + echo '// swift-tools-version: 5.7 + import PackageDescription + let package = Package(name: "swiftapp", platforms: [.macOS(.v10_15)], dependencies: [.package(url: "https://github.com/aws-amplify/amplify-swift", from: "2.12.0") ], targets: [ .executableTarget( name: "swiftapp", dependencies: [ .product(name: "Amplify", package: "amplify-swift") ], path: "Sources")] + )' >> Package.swift + cat Package.swift +} + +buildModels From f3d2753d22aa13dd743b9620833b68123b2797d8 Mon Sep 17 00:00:00 2001 From: phani-srikar Date: Fri, 14 Jul 2023 10:57:45 -0700 Subject: [PATCH 4/4] chore: remove ls statements --- scripts/test-swift-modelgen.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/test-swift-modelgen.sh b/scripts/test-swift-modelgen.sh index 7d52f1893..5ede0d902 100644 --- a/scripts/test-swift-modelgen.sh +++ b/scripts/test-swift-modelgen.sh @@ -25,11 +25,9 @@ function buildModels() { } function buildAndRunModel() { - pwd && ls modelName=$1 - ls $modelName && cd $modelName + cd $modelName currentDirectory=$(pwd) - pwd && ls pathToSwiftPackage=$2 @@ -40,7 +38,6 @@ function buildAndRunModel() { # build and run the model cd $pathToSwiftPackage - ls Sources/models swift build && swift run # clean up