From a56760008aa51176c84da18e444bd79b10e2140f Mon Sep 17 00:00:00 2001 From: Alexey Alter-Pesotskiy Date: Mon, 24 Jun 2024 10:52:21 +0100 Subject: [PATCH] [CI] Update iOS runtimes' download --- .github/actions/setup-ios-runtime/action.yml | 32 +++++++++ .github/workflows/cron-checks.yml | 69 ++++++------------- .github/workflows/smoke-checks.yml | 4 +- .gitignore | 8 ++- Scripts/bootstrap.sh | 7 +- Scripts/install_ios_runtime.sh | 59 ++++++++++++++++ .../ChannelController_Tests.swift | 5 ++ fastlane/.env | 7 ++ fastlane/Fastfile | 37 ++++++---- 9 files changed, 160 insertions(+), 68 deletions(-) create mode 100644 .github/actions/setup-ios-runtime/action.yml create mode 100755 Scripts/install_ios_runtime.sh create mode 100644 fastlane/.env diff --git a/.github/actions/setup-ios-runtime/action.yml b/.github/actions/setup-ios-runtime/action.yml new file mode 100644 index 00000000000..57dd16ed5f3 --- /dev/null +++ b/.github/actions/setup-ios-runtime/action.yml @@ -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_sim 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 diff --git a/.github/workflows/cron-checks.yml b/.github/workflows/cron-checks.yml index cf463b4d8ec..a25fd149a05 100644 --- a/.github/workflows/cron-checks.yml +++ b/.github/workflows/cron-checks.yml @@ -43,27 +43,17 @@ jobs: - 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.3 os: macos-14 - device: "iPhone 14 Pro Max" + device: "iPhone 14 Pro" setup_runtime: true - ios: 15.5 xcode: 15.3 os: macos-14 - device: "iPhone 13" - setup_runtime: true - - ios: 14.5 - xcode: 15.3 - os: macos-14 - device: "iPhone SE (2nd generation)" - setup_runtime: true - - ios: 13.7 - xcode: 15.3 - os: macos-14 - device: "iPad Air (3rd generation)" + device: "iPhone 13 Pro" setup_runtime: true fail-fast: false runs-on: ${{ matrix.os }} @@ -85,20 +75,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: ~/Downloads/*.dmg - key: xcodes-runtime-ios-${{ matrix.ios }} - restore-keys: xcodes-runtime-ios-${{ matrix.ios }} - - name: Setup iOS ${{ matrix.ios }} Runtime + SKIP_BREW_BOOTSTRAP: true + - uses: ./.github/actions/setup-ios-runtime if: ${{ matrix.setup_runtime }} timeout-minutes: 60 - run: | - brew install xcodesorg/made/xcodes - xcodes runtimes - sudo xcodes runtimes install 'iOS ${{ matrix.ios }}' --keep-archive + with: + version: ${{ matrix.ios }} + device: ${{ matrix.device }} - name: Launch Allure TestOps run: bundle exec fastlane allure_launch cron:true - name: Run UI Tests (Debug) @@ -143,27 +126,27 @@ jobs: - ios: 17.4 xcode: 15.4 os: macos-14 - device: "iPhone 14 Pro Max" + device: "iPhone 14 Pro" setup_runtime: false - ios: 16.4 xcode: 15.3 os: macos-14 - device: "iPhone 14 Pro Max" + device: "iPhone 14 Pro" setup_runtime: true - ios: 15.5 xcode: 15.3 os: macos-14 - device: "iPhone 13" + device: "iPhone 13 Pro" setup_runtime: true - ios: 14.5 - xcode: 15.3 - os: macos-14 - device: "iPhone SE (2nd generation)" + xcode: 14.2 + os: macos-12 + device: "iPhone 12 Pro" setup_runtime: true - ios: 13.7 - xcode: 15.3 - os: macos-14 - device: "iPad Air (3rd generation)" + xcode: 14.2 + os: macos-12 + device: "iPhone 11 Pro" setup_runtime: true fail-fast: false runs-on: ${{ matrix.os }} @@ -175,20 +158,12 @@ jobs: - uses: ./.github/actions/bootstrap env: INSTALL_YEETD: true - - name: Cache iOS Simulator Runtime - uses: actions/cache@v4 - id: runtime-cache - with: - path: ~/Downloads/*.dmg - key: xcodes-runtime-ios-${{ matrix.ios }} - restore-keys: xcodes-runtime-ios-${{ matrix.ios }} - - name: Setup iOS ${{ matrix.ios }} Runtime + - uses: ./.github/actions/setup-ios-runtime if: ${{ matrix.setup_runtime }} timeout-minutes: 60 - run: | - brew install xcodesorg/made/xcodes - xcodes runtimes - sudo xcodes runtimes install 'iOS ${{ matrix.ios }}' --keep-archive + with: + version: ${{ matrix.ios }} + device: ${{ matrix.device }} - name: Run LLC Tests (Debug) run: bundle exec fastlane test device:"${{ matrix.device }} (${{ matrix.ios }})" cron:true timeout-minutes: 100 @@ -224,7 +199,7 @@ jobs: steps: - uses: actions/checkout@v4.1.1 - uses: ./.github/actions/ruby-cache - - name: List Xcode versions xcversion sees + - name: List Xcode versions run: mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'" - name: Build LLC run: bundle exec fastlane test device:"iPhone 8" build_for_testing:true diff --git a/.github/workflows/smoke-checks.yml b/.github/workflows/smoke-checks.yml index 1f3b1125497..984608cf8a4 100644 --- a/.github/workflows/smoke-checks.yml +++ b/.github/workflows/smoke-checks.yml @@ -115,6 +115,7 @@ jobs: env: INSTALL_YEETD: true SKIP_MINT_BOOTSTRAP: true + SKIP_BREW_BOOTSTRAP: true - name: Run UI Tests (Debug) run: bundle exec fastlane test_ui device:"${{ env.IOS_SIMULATOR_DEVICE }}" skip_build:true record:${{ github.event.inputs.snapshots }} timeout-minutes: 60 @@ -158,6 +159,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 @@ -224,7 +226,7 @@ jobs: steps: - uses: actions/checkout@v4.1.1 - uses: ./.github/actions/ruby-cache - - name: List Xcode versions xcversion sees + - name: List Xcode versions run: mdfind "kMDItemCFBundleIdentifier = 'com.apple.dt.Xcode'" - name: Build LLC run: bundle exec fastlane test device:"iPhone 13" build_for_testing:true diff --git a/.gitignore b/.gitignore index 0bdbec20c28..972569a5fcc 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -64,6 +67,7 @@ Carthage/ # For more information about the recommended setup visit: # https://docs.fastlane.tools/best-practices/source-control/#source-control +!fastlane/.env fastlane/fastlane.log fastlane/report.xml fastlane/Preview.html @@ -92,6 +96,7 @@ spm_cache/ buildcache App Thinning Size Report.txt app-thinning.plist +*.dmg # gcloud google-cloud-sdk @@ -104,8 +109,5 @@ Products/ # Ignore Dependencies folder Dependencies/ -# Environment Variables -.env - # Ignore internal scheme StreamChat.xcodeproj/xcshareddata/xcschemes/DemoApp-StreamDevelopers.xcscheme diff --git a/Scripts/bootstrap.sh b/Scripts/bootstrap.sh index e933ed5b04e..3402e6970fd 100755 --- a/Scripts/bootstrap.sh +++ b/Scripts/bootstrap.sh @@ -37,8 +37,11 @@ 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" diff --git a/Scripts/install_ios_runtime.sh b/Scripts/install_ios_runtime.sh new file mode 100755 index 00000000000..1f7c7cd362f --- /dev/null +++ b/Scripts/install_ios_runtime.sh @@ -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| e + UI.user_error!(e) unless options[:cron] + + failed_tests = retreive_failed_tests + UI.important("Re-running #{failed_tests.size} failed tests ⌛️") + scan(scan_options.merge(only_testing: failed_tests)) + end end desc 'Starts Sinatra web server' @@ -549,13 +557,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) @@ -757,16 +765,15 @@ lane :rubocop do 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]}'") + runtime_list = sh("xcrun simctl runtime list | grep 'iOS #{options[:ios]}' || true") + if runtime_list.include?('Ready') + UI.important("iOS #{options[:ios]} Runtime already exists") 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}'") + 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 end end