Skip to content

Commit

Permalink
[CI] Update iOS runtimes' download
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Jun 28, 2024
1 parent 82bd989 commit 28be408
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 36 deletions.
32 changes: 32 additions & 0 deletions .github/actions/setup-ios-runtime/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'Setup iOS Runtime'
description: 'Download and Install requested iOS Runtime'
runs:
using: "composite"
steps:
- name: Cache iOS Simulator Runtime
uses: actions/cache@v4
id: runtime-cache
with:
path: ./*.dmg
key: ipsw-runtime-ios-${{ inputs.version }}
restore-keys: ipsw-runtime-ios-${{ inputs.version }}
- name: Setup iOS Simulator Runtime
shell: bash
run: |
brew install blacktop/tap/ipsw
bundle exec fastlane install_runtime ios:${{ inputs.version }}
xcrun simctl list runtimes
- name: Create Custom iOS Simulator
shell: bash
run: |
ios_version_dash=$(echo "${{ inputs.version }}" | tr '.' '-') # ex: 16.4 -> 16-4
xcrun simctl create custom-test-device "${{ inputs.device }}" "com.apple.CoreSimulator.SimRuntime.iOS-$ios_version_dash"
xcrun simctl list devices ${{ inputs.version }}
inputs:
version:
description: "iOS Runtime Version"
required: true
device:
description: "iOS Simulator Model"
required: true
33 changes: 14 additions & 19 deletions .github/workflows/cron-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,14 @@ env:
jobs:
build-test-app-and-frameworks:
name: Build Test App and Frameworks
runs-on: macos-13
runs-on: macos-14
steps:
- uses: actions/[email protected]
- uses: ./.github/actions/ruby-cache
- uses: ./.github/actions/xcode-cache
- name: Build
run: bundle exec fastlane build_test_app_and_frameworks
timeout-minutes: 60
env:
XCODE_VERSION: "15.2" # Should match the minimum version in dependent jobs
- uses: actions/upload-artifact@v4
if: success()
with:
Expand All @@ -42,16 +40,16 @@ jobs:
strategy:
matrix:
include:
- ios: 17.2
xcode: 15.2
- ios: 17.4
xcode: 15.4
os: macos-14
device: "iPhone 15 Pro"
device: "iPhone 14 Pro"
setup_runtime: false
- ios: 16.4
xcode: 15.2
xcode: 15.3
os: macos-14
device: "iPhone 14 Pro Max"
setup_runtime: false
device: "iPhone 14 Pro"
setup_runtime: true
fail-fast: false
runs-on: ${{ matrix.os }}
env:
Expand All @@ -70,16 +68,13 @@ jobs:
INSTALL_ALLURE: true
INSTALL_YEETD: true
SKIP_MINT_BOOTSTRAP: true
- name: Cache iOS Simulator Runtime
uses: actions/cache@v4
id: runtime-cache
with:
path: ~/Library/Caches/XcodeInstall/
key: runtime-ios-${{ matrix.ios }}
restore-keys: runtime-ios-${{ matrix.ios }}
- name: Setup iOS ${{ matrix.ios }} Runtime
SKIP_BREW_BOOTSTRAP: true
- uses: ./.github/actions/setup-ios-runtime
if: ${{ matrix.setup_runtime }}
run: bundle exec fastlane install_sim ios:"${{ matrix.ios }}"
timeout-minutes: 60
with:
version: ${{ matrix.ios }}
device: ${{ matrix.device }}
- name: Launch Allure TestOps
run: bundle exec fastlane allure_launch cron:true
- name: Run UI Tests (Debug)
Expand Down Expand Up @@ -156,7 +151,7 @@ jobs:
steps:
- uses: actions/[email protected]
- uses: ./.github/actions/ruby-cache
- name: List Xcode versions xcversion sees
- name: List Xcode versions
run: mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'"
timeout-minutes: 25
- name: Build SwiftUI
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/smoke-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ jobs:
INSTALL_ALLURE: true
INSTALL_YEETD: true
SKIP_MINT_BOOTSTRAP: true
SKIP_BREW_BOOTSTRAP: true
- name: Run UI Tests (Debug)
run: bundle exec fastlane test_e2e_mock device:"${{ env.IOS_SIMULATOR_DEVICE }}" batch:'${{ matrix.batch }}' test_without_building:true
timeout-minutes: 100
Expand Down Expand Up @@ -207,7 +208,7 @@ jobs:
steps:
- uses: actions/[email protected]
- uses: ./.github/actions/ruby-cache
- name: List Xcode versions xcversion sees
- name: List Xcode versions
run: mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'"
timeout-minutes: 25
- name: Build SwiftUI
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# OS X
.DS_Store

# Environment Variables
.env

# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
Expand Down Expand Up @@ -67,6 +70,7 @@ Products/
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

!fastlane/.env
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
Expand All @@ -91,3 +95,4 @@ derived_data/
spm_cache/
.buildcache
buildcache
*.dmg
6 changes: 4 additions & 2 deletions Scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ ln -sf ../../hooks/pre-commit.sh .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
chmod +x ./hooks/git-format-staged

puts "Install brew dependencies"
brew bundle -d
if [ "${SKIP_BREW_BOOTSTRAP:-}" != true ]; then
puts "Install brew dependencies"
brew bundle -d
fi

if [ "${SKIP_MINT_BOOTSTRAP:-}" != true ]; then
puts "Bootstrap Mint dependencies"
Expand Down
59 changes: 59 additions & 0 deletions Scripts/install_ios_runtime.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash -e
# Copyright 2024 Namespace Labs Inc. Licensed under the MIT License.

log() { echo "👉 ${1}" >&2; }
die() { log "${1}"; exit 1; }
[ $# -eq 1 ] || die "usage: $0 path/to/runtime.dmg"

dmg=$1
mountpoint=$(mktemp -d)
staging=$(mktemp -d)

cleanup() {
if [ -d "$staging" ]; then
set +e
log "Removing $staging..."
rm -r "$staging"
log "Unmounting $mountpoint..."
hdiutil detach "$mountpoint" >&2
fi

if [ -d "$mountpoint" ]; then
log "Removing $mountpoint..."
rmdir "$mountpoint"
fi
}
trap cleanup EXIT

log "Mounting $dmg on $mountpoint..."
hdiutil attach "$dmg" -mountpoint "$mountpoint" >&2

if ! ls "$mountpoint"/*.pkg >/dev/null 2>&1; then
log "Detected a modern volume runtime; installing with simctl..."
xcrun simctl runtime add "$1"
exit 0
fi

log "Detected packaged runtime."

bundle=$(echo "$mountpoint"/*.pkg)
basename=$(basename "$bundle")
sdkname=${basename%.*}
log "Found package $bundle (sdk $sdkname)."

log "Expanding package $bundle to $staging/expanded..."
pkgutil --expand "$bundle" "$staging/expanded"

dest=/Library/Developer/CoreSimulator/Profiles/Runtimes/$sdkname.simruntime
# The package would try to install itself into volume root; this is wrong.
log "Rewriting package install location to $dest..."
sed -I '' "s|<pkg-info|<pkg-info install-location=\"$dest\"|" "$staging/expanded/PackageInfo"

log "Re-assembling the package $staging/$basename..."
pkgutil --flatten "$staging/expanded" "$staging/$basename"

log "Installing $staging/$basename..."
sudo installer -pkg "$staging/$basename" -target /

version=$(plutil -extract CFBundleName raw "$dest/Contents/Info.plist")
log "Installed $version."
7 changes: 7 additions & 0 deletions fastlane/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT=180
FASTLANE_XCODEBUILD_SETTINGS_RETRIES=10
FASTLANE_SKIP_ACTION_SUMMARY=true
FASTLANE_HIDE_PLUGINS_TABLE=true
FASTLANE_SKIP_UPDATE_CHECK=true
FASTLANE_HIDE_CHANGELOG=true
30 changes: 16 additions & 14 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ is_localhost = !is_ci
before_all do |lane|
if is_ci
setup_ci
ENV['FASTLANE_XCODEBUILD_SETTINGS_TIMEOUT'] = '180'
ENV['FASTLANE_XCODEBUILD_SETTINGS_RETRIES'] = '10'
xcversion(version: xcode_version) unless [:publish_release, :allure_launch, :allure_upload, :copyright, :pod_lint].include?(lane)
end
end
Expand Down Expand Up @@ -247,13 +245,13 @@ private_lane :parallelize_tests_on_ci do |options|
UI.success("Tests in total: #{only_testing.flatten.size}. Running #{only_testing_batch.size} of them ⌛️")
scan(options[:scan].merge(only_testing: only_testing_batch))
rescue StandardError
failed_tests = retreive_failed_e2e_tests
failed_tests = retreive_failed_tests
UI.important("Re-running #{failed_tests.size} failed tests ⌛️")
scan(options[:scan].merge(only_testing: failed_tests))
end
end

private_lane :retreive_failed_e2e_tests do
private_lane :retreive_failed_tests do
report_path = 'test_output/report.junit'
raise UI.user_error!('There is no junit report to parse') unless File.file?(report_path)

Expand Down Expand Up @@ -388,17 +386,21 @@ lane :rubocop do
sh('bundle exec rubocop')
end

lane :install_sim do |options|
xcode_install_cache_dir = File.expand_path('~/Library/Caches/XcodeInstall')
sim_dmg_path = Dir["#{xcode_install_cache_dir}/*.dmg"].first
sim_pkg_path = Dir["#{xcode_install_cache_dir}/*.pkg"].first
if is_localhost || sim_dmg_path.nil? || sim_pkg_path.nil?
sh("bundle exec xcversion simulators --install='iOS #{options[:ios]}'")
lane :install_runtime do |options|
runtimes = `xcrun simctl runtime list -j`
UI.message("👉 Runtime list:\n#{runtimes}")
simulators = JSON.parse(runtimes).select do |_, sim|
sim['platformIdentifier'].end_with?('iphonesimulator') && sim['version'] == options[:ios] && sim['state'] == 'Ready'
end

if simulators.empty?
Dir.chdir('..') do
sh("echo 'iOS #{options[:ios]} Simulator' | ipsw download xcode --sim") if Dir['*.dmg'].first.nil?
sh("./Scripts/install_ios_runtime.sh #{Dir['*.dmg'].first}")
UI.success("iOS #{options[:ios]} Runtime successfuly installed")
end
else
sh("hdiutil attach '#{sim_dmg_path}'")
sh("sudo installer -pkg '#{sim_pkg_path}' -target /")
mount_point = sh("hdiutil attach '#{sim_dmg_path}' | grep Volumes | cut -f 3").strip
sh("hdiutil detach '#{mount_point}'")
UI.important("iOS #{options[:ios]} Runtime already exists")
end
end

Expand Down

0 comments on commit 28be408

Please sign in to comment.