Skip to content

[CI] Dynamically pick latest simulator device#15993

Draft
andrewheard wants to merge 6 commits intomainfrom
ah/dynamic-simulator-selection
Draft

[CI] Dynamically pick latest simulator device#15993
andrewheard wants to merge 6 commits intomainfrom
ah/dynamic-simulator-selection

Conversation

@andrewheard
Copy link
Copy Markdown
Contributor

@andrewheard andrewheard commented Mar 26, 2026

Updated build.sh to dynamically select an available simulator for the latest version of the specified OS. For example, get_latest_simulator "iOS" "iPhone" returns iPhone 17 Pro. This may reduce CI failures due to missing devices, requiring fixes like #15992.

Added an install_simulators.sh script that skips downloading when a platform is available already. xcodebuild -downloadPlatform was downloading iOS 26.3.1 runtimes when iOS 26.2 or iOS 26.3 was already available. This added minutes to the CI runs and gigabytes upon gigabytes of bandwidth usage.

#no-changelog

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@andrewheard
Copy link
Copy Markdown
Contributor Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces dynamic simulator selection in scripts/build.sh and adds a new utility script, scripts/install_simulators.sh, to manage simulator runtime installations. The review feedback highlights the need for explicit error handling when using command substitutions and suggests a more robust jq query to handle potential null values when fetching simulator names.

if [[ "$xcode_major" -gt 16 ]]; then
iphone_simulator_name="iPhone 17"
fi
iphone_simulator_name=$(get_latest_simulator "iOS" "iPhone")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When get_latest_simulator fails, it returns a non-zero exit code, but the script doesn't exit because of how set -e handles command substitutions. This can lead to iphone_simulator_name being empty and causing issues later. To ensure the script fails immediately on error, you should explicitly check the exit code.

Suggested change
iphone_simulator_name=$(get_latest_simulator "iOS" "iPhone")
iphone_simulator_name=$(get_latest_simulator "iOS" "iPhone") || exit 1

-destination "platform=iOS Simulator,name=${iphone_simulator_name}"
-destination "platform=iOS Simulator,OS=latest,name=${iphone_simulator_name}"
)
watchos_simulator_name=$(get_latest_simulator "watchOS" "Apple Watch")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When get_latest_simulator fails, it returns a non-zero exit code, but the script doesn't exit because of how set -e handles command substitutions. This can lead to watchos_simulator_name being empty and causing issues later. To ensure the script fails immediately on error, you should explicitly check the exit code.

Suggested change
watchos_simulator_name=$(get_latest_simulator "watchOS" "Apple Watch")
watchos_simulator_name=$(get_latest_simulator "watchOS" "Apple Watch") || exit 1

macos_flags=(
-destination 'platform=OS X,arch=x86_64'
)
tvos_simulator_name=$(get_latest_simulator "tvOS" "Apple TV")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

When get_latest_simulator fails, it returns a non-zero exit code, but the script doesn't exit because of how set -e handles command substitutions. This can lead to tvos_simulator_name being empty and causing issues later. To ensure the script fails immediately on error, you should explicitly check the exit code.

Suggested change
tvos_simulator_name=$(get_latest_simulator "tvOS" "Apple TV")
tvos_simulator_name=$(get_latest_simulator "tvOS" "Apple TV") || exit 1

Comment on lines +192 to +193
first |
.name
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

If map(select(.name | contains($dev))) returns an empty array, first will evaluate to null. Attempting to access .name on null will cause jq to error. Using the optional operator ? (.name?) will prevent this error by gracefully returning null instead, making the query more robust.

Suggested change
first |
.name
first | .name?

@ncooke3 ncooke3 self-assigned this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants