Skip to content

Commit 5c28cff

Browse files
committed
chore: add test script
1 parent 93b2388 commit 5c28cff

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

scripts/test-swift-modelgen.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# set exit on error to true
4+
set -e
5+
6+
function buildModels() {
7+
# download and unzip the models from S3
8+
tempDirectory=$(mktemp -d)
9+
cd $tempDirectory
10+
wget -O models.zip "$MODELS_S3_URL"
11+
tar -xvf models.zip
12+
13+
# create a Swift package to test the models
14+
pathToSwiftPackage=${tempDirectory}/swiftapp
15+
rm -rf $pathToSwiftPackage
16+
mkdir $pathToSwiftPackage && cd $pathToSwiftPackage
17+
echo "Creating Swift package at $pathToSwiftPackage"
18+
createSwiftPackage
19+
20+
cd ${tempDirectory}/models
21+
for model in */; do
22+
echo "Building model $model"
23+
buildAndRunModel $model $pathToSwiftPackage
24+
done
25+
}
26+
27+
function buildAndRunModel() {
28+
pwd && ls
29+
modelName=$1
30+
ls $modelName && cd $modelName
31+
currentDirectory=$(pwd)
32+
pwd && ls
33+
34+
pathToSwiftPackage=$2
35+
36+
# copy with replace all files in current directory to the swift package
37+
mkdir -p $pathToSwiftPackage/Sources/models
38+
rm -rf $pathToSwiftPackage/Sources/models/*
39+
cp -r $currentDirectory/* $pathToSwiftPackage/Sources/models
40+
41+
# build and run the model
42+
cd $pathToSwiftPackage
43+
ls Sources/models
44+
swift build && swift run
45+
46+
# clean up
47+
cd $currentDirectory
48+
}
49+
50+
function createSwiftPackage() {
51+
# create a swift package
52+
swift package init --type executable
53+
rm -rf Package.swift
54+
echo '// swift-tools-version: 5.7
55+
import PackageDescription
56+
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")]
57+
)' >> Package.swift
58+
cat Package.swift
59+
}
60+
61+
buildModels

0 commit comments

Comments
 (0)