Skip to content
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
27 changes: 26 additions & 1 deletion internal/workflow/templates/ios-share.yml
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,10 @@ jobs:
if: steps.detect.outputs.type == 'kmp'
uses: gradle/actions/setup-gradle@v6

# The build is written to a script first and run from there, so the
# sharing step can hand the same build to mobai-ci: the MobAI app then
# rebuilds newer code on this simulator exactly as this step built it.
# The script logs to stderr and prints only the app's path on stdout.
- name: Build for the simulator
id: build
env:
Expand All @@ -546,6 +550,13 @@ jobs:
PROJECT_TYPE: ${{ steps.detect.outputs.type }}
run: |
set -e
BUILD_SCRIPT="$RUNNER_TEMP/mobai-build.sh"
{
echo 'set -e'
printf 'IOS_PATH=%q SCHEME=%q PROJECT_TYPE=%q\n' "$IOS_PATH" "$SCHEME" "$PROJECT_TYPE"
cat <<'MOBAI_BUILD'
exec 3>&1 1>&2
cd "$GITHUB_WORKSPACE"

if [ "$PROJECT_TYPE" = "flutter" ]; then
# Flutter drives xcodebuild itself and puts the bundle in a known
Expand Down Expand Up @@ -651,7 +662,13 @@ jobs:
exit 1
fi
echo "Built $APP_PATH"
case "$APP_PATH" in /*) ;; *) APP_PATH="$GITHUB_WORKSPACE/$APP_PATH" ;; esac
echo "$APP_PATH" >&3
MOBAI_BUILD
} > "$BUILD_SCRIPT"
APP_PATH=$(bash "$BUILD_SCRIPT")
echo "app_path=$APP_PATH" >> $GITHUB_OUTPUT
echo "build_script=$BUILD_SCRIPT" >> $GITHUB_OUTPUT

# Flutter builds through its own tree, so DerivedData can be absent and a
# save would fail on a path that never existed.
Expand All @@ -673,16 +690,24 @@ jobs:

# Installs the build on the simulator and publishes it to the MobAI app.
# The step (and the job) stay running until the simulator is released
# there or goes unused.
# there or goes unused. The MobAI app may rebuild newer snapshots of the
# code with the same build, and run hot reload sessions, in this
# checkout.
- name: Share the simulator
env:
MOBAI_API_KEY: ${{ secrets.MOBAI_API_KEY }}
run: |
# A mobai-ci from before rebuilds refuses flags it does not know.
REBUILD=()
if mobai-ci share -help 2>&1 | grep -q -- '-rebuild'; then
REBUILD=(--dir "$GITHUB_WORKSPACE" --rebuild "bash ${{ steps.build.outputs.build_script }}")
fi
mobai-ci share \
--device "$MOBAI_SIM_UDID" \
--app "${{ steps.build.outputs.app_path }}" \
--duration "${{ steps.params.outputs.duration }}" \
--label "${{ github.repository }} · ${{ steps.params.outputs.build_id }}" \
"${REBUILD[@]}" \
--wait-device 4m --startup-timeout 5m

# The tag exists only to start this run, so it leaves with it. Deleting
Expand Down
29 changes: 26 additions & 3 deletions internal/workflow/templates/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,13 @@ build_simulator() {
fi
sim_udid=$(mobai-ci sim boot --cache "$ci_dir/sim-cache" --device-type 'iPhone 16 Pro' --runtime latest | tail -1)
test -n "$sim_udid"
build_app
printf '%s\n' "$app_path" > "$ci_dir/app-path"
printf '%s\n' "$sim_udid" > "$ci_dir/sim-udid"
}

# Builds the app for the simulator sim_udid names and sets app_path.
build_app() {
if [ "$project_type" = flutter ]; then
cd "$BUILDER_WORKSPACE"
flutter build ios --simulator --debug
Expand All @@ -679,8 +686,6 @@ build_simulator() {
app_path=$(xcodebuild "${args[@]}" -showBuildSettings -json | jq -r 'map(.buildSettings) | map(select(.PRODUCT_TYPE == "com.apple.product-type.application" and (.TARGET_BUILD_DIR | contains("-iphonesimulator")))) | map(.TARGET_BUILD_DIR + "/" + .FULL_PRODUCT_NAME) | first // empty')
fi
test -d "$app_path"
printf '%s\n' "$app_path" > "$ci_dir/app-path"
printf '%s\n' "$sim_udid" > "$ci_dir/sim-udid"
}

case "$mode" in
Expand All @@ -693,9 +698,27 @@ case "$mode" in
;;
share)
export PATH="$ci_dir/bin:$PATH"
# The MobAI app may rebuild newer snapshots of the code with this script's
# rebuild mode. A mobai-ci from before rebuilds refuses the flags.
rebuild=()
export BUILDER_WORKSPACE="${BUILDER_WORKSPACE:-$(pwd)}"
if mobai-ci share -help 2>&1 | grep -q -- '-rebuild'; then
self="$(cd "$(dirname "$0")" && pwd)/$(basename "$0")"
rebuild=(--dir "$BUILDER_WORKSPACE" --rebuild "bash $(printf '%q' "$self") rebuild")
fi
exec mobai-ci share --device "$(cat "$ci_dir/sim-udid")" --app "$(cat "$ci_dir/app-path")" \
--duration "${DURATION:-30m}" --label "${BUILDER_REPOSITORY:-Builder} · $BUILD_ID" \
--wait-device 4m --startup-timeout 5m
"${rebuild[@]}" --wait-device 4m --startup-timeout 5m
;;
rebuild)
# Run by mobai-ci share on newer code: the build logs to stderr and the
# app's path is the one line on stdout.
exec 3>&1 1>&2
export BUILDER_WORKSPACE="${BUILDER_WORKSPACE:-$(pwd)}"
sim_udid=$(cat "$ci_dir/sim-udid")
prepare
build_app
echo "$app_path" >&3
;;
*) echo "Unknown runner mode: $mode" >&2; exit 1 ;;
esac
Loading