Skip to content

Commit 225ad09

Browse files
authored
Merge pull request #629 from aws-amplify/fix-e2e-cb
2 parents 7397ab9 + f3d2753 commit 225ad09

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed

.codebuild/scripts/run-ios-modelgen-e2e-test.sh

100644100755
File mode changed.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: 'Test compiling Swift Modelgen output'
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
MODELS_S3_URL:
7+
description: 'S3 URL for models'
8+
required: true
9+
10+
env:
11+
MODELS_S3_URL: ${{ inputs.MODELS_S3_URL }}
12+
13+
jobs:
14+
Build-Swift-Modelgen:
15+
name: Analyze
16+
runs-on: macos-13-xl
17+
permissions:
18+
actions: read
19+
contents: read
20+
21+
strategy:
22+
fail-fast: true
23+
24+
steps:
25+
- name: Mask S3 URL
26+
run: echo "::add-mask::$MODELS_S3_URL"
27+
28+
- name: Checkout repository
29+
uses: actions/checkout@v3
30+
31+
- name: Check Xcode and Swift versions
32+
run: |
33+
xcodebuild -version
34+
swift --version
35+
36+
- name: Build Swift Models
37+
run: ./scripts/test-swift-modelgen.sh

scripts/test-swift-modelgen.sh

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
modelName=$1
29+
cd $modelName
30+
currentDirectory=$(pwd)
31+
32+
pathToSwiftPackage=$2
33+
34+
# copy with replace all files in current directory to the swift package
35+
mkdir -p $pathToSwiftPackage/Sources/models
36+
rm -rf $pathToSwiftPackage/Sources/models/*
37+
cp -r $currentDirectory/* $pathToSwiftPackage/Sources/models
38+
39+
# build and run the model
40+
cd $pathToSwiftPackage
41+
swift build && swift run
42+
43+
# clean up
44+
cd $currentDirectory
45+
}
46+
47+
function createSwiftPackage() {
48+
# create a swift package
49+
swift package init --type executable
50+
rm -rf Package.swift
51+
echo '// swift-tools-version: 5.7
52+
import PackageDescription
53+
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")]
54+
)' >> Package.swift
55+
cat Package.swift
56+
}
57+
58+
buildModels

0 commit comments

Comments
 (0)