Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add scripts for ios-modelgen e2e test #629

Merged
merged 4 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified .codebuild/scripts/run-ios-modelgen-e2e-test.sh
100644 → 100755
Empty file.
37 changes: 37 additions & 0 deletions .github/workflows/build-swift-modelgen.yml
Original file line number Diff line number Diff line change
@@ -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
58 changes: 58 additions & 0 deletions scripts/test-swift-modelgen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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() {
modelName=$1
cd $modelName
currentDirectory=$(pwd)

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
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