From af9059cf80ad78c5c855a1b62e9170828381076d Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Wed, 22 May 2024 14:30:06 -0700 Subject: [PATCH] fix(ci): Refactor Apple jobs (#3631) * Copy stuff from RNM and refactor * Disable ccache * gitignore ccache * fix * fix * fix * fix * fix * fix * fix --- .ado/Brewfile | 2 + .ado/azure-pipelines.yml | 86 +++++++------------ .ado/scripts/xcodebuild.sh | 77 +++++++++++++++++ .../apple-ensure-valid-cocoapods.yml | 10 --- .ado/templates/apple-tools-setup.yml | 26 ++++++ .ado/variables/vars.yml | 10 +-- .ado/xcconfig/publish_overrides.xcconfig | 23 ----- .../publish_overrides_ios_device.xcconfig | 4 - .../publish_overrides_ios_simulator.xcconfig | 4 - .ado/xcconfig/publish_staticanalysis.xcconfig | 13 --- .gitignore | 5 +- 11 files changed, 142 insertions(+), 118 deletions(-) create mode 100644 .ado/Brewfile create mode 100755 .ado/scripts/xcodebuild.sh delete mode 100644 .ado/templates/apple-ensure-valid-cocoapods.yml create mode 100644 .ado/templates/apple-tools-setup.yml delete mode 100644 .ado/xcconfig/publish_overrides.xcconfig delete mode 100644 .ado/xcconfig/publish_overrides_ios_device.xcconfig delete mode 100644 .ado/xcconfig/publish_overrides_ios_simulator.xcconfig delete mode 100644 .ado/xcconfig/publish_staticanalysis.xcconfig diff --git a/.ado/Brewfile b/.ado/Brewfile new file mode 100644 index 0000000000..bfe131072d --- /dev/null +++ b/.ado/Brewfile @@ -0,0 +1,2 @@ +brew "xcbeautify" +brew "ccache" diff --git a/.ado/azure-pipelines.yml b/.ado/azure-pipelines.yml index 7d0ee736ad..2b7c8a6f11 100644 --- a/.ado/azure-pipelines.yml +++ b/.ado/azure-pipelines.yml @@ -79,43 +79,36 @@ jobs: - template: templates/setup-repo-min-build.yml - - template: templates/apple-ensure-valid-cocoapods.yml + - template: templates/apple-tools-setup.yml - script: | + set -eox pipefail yarn bundle:macos workingDirectory: apps/fluent-tester displayName: 'yarn bundle macos' - bash: | - echo "pod install $(platform)" - pod install - workingDirectory: apps/fluent-tester/$(platform) - displayName: 'pod install $(platform)' + set -eox pipefail + pod install --verbose + workingDirectory: apps/fluent-tester/macos + displayName: 'pod install' - - bash: | - sudo xcode-select --switch '$(xcode_path)' - displayName: Switch Xcode version $(xcode_version) - failOnStderr: true - - - script: | - brew install xcbeautify - displayName: 'Install xcbeautify' - - - bash: | - echo "yarn $(platform)" - yarn $(platform) - workingDirectory: apps/fluent-tester - displayName: 'yarn $(platform)' + - task: CmdLine@2 + displayName: Build macOS + inputs: + script: | + set -eox pipefail + ./.ado/scripts/xcodebuild.sh apps/fluent-tester/macos/FluentTester.xcworkspace macosx ReactTestApp build + env: + CCACHE_DISABLE: 1 - template: templates/e2e-testing-macos.yml - job: iOSPR displayName: iOS PR pool: - vmImage: macos-13-arm64 - variables: - platform: 'ios' - timeoutInMinutes: 120 # how long to run the job before automatically cancelling + vmImage: $(VmImageApple) + timeoutInMinutes: 60 # how long to run the job before automatically cancelling cancelTimeoutInMinutes: 5 # how much time to give 'run always even if cancelled tasks' before killing them steps: @@ -124,47 +117,28 @@ jobs: - template: templates/setup-repo-min-build.yml - - template: templates/apple-ensure-valid-cocoapods.yml + - template: templates/apple-tools-setup.yml - script: | + set -eox pipefail yarn bundle:ios workingDirectory: apps/fluent-tester displayName: 'yarn bundle ios' - bash: | - echo "pod install $(platform)" - pod install - workingDirectory: apps/fluent-tester/$(platform) - displayName: 'pod install $(platform)' + set -eox pipefail + pod install --verbose + workingDirectory: apps/fluent-tester/ios + displayName: 'pod install' - - bash: | - sudo xcode-select --switch '$(xcode_path)' - displayName: Switch Xcode version $(xcode_version) - failOnStderr: true - - - script: | - brew install xcbeautify - displayName: 'Install xcbeautify' - - - script: | - xcrun simctl list - displayName: 'List Simulators' - - - script: | - xcrun --sdk iphonesimulator --show-sdk-version - displayName: 'Determine iOS SDK version' - - # - script: | - # NEW_DEVICE=$(xcrun simctl create "Test Phone" "$(ios_simulator)" iOS$(ios_version)) - # echo "🤖 Created ${NEW_DEVICE}" - # xcrun simctl boot ${NEW_DEVICE} - # displayName: 'Boot Simulator' - - - bash: | - echo "yarn $(platform)" - yarn $(platform) --simulator "$(ios_simulator)" --no-packager - workingDirectory: apps/fluent-tester - displayName: 'yarn $(platform)' + - task: CmdLine@2 + displayName: Build iOS + inputs: + script: | + set -eox pipefail + ./.ado/scripts/xcodebuild.sh apps/fluent-tester/ios/FluentTester.xcworkspace iphonesimulator ReactTestApp build + env: + CCACHE_DISABLE: 1 # Disable iOS E2E tests as they fail on macOS-13 images # - template: templates/e2e-testing-ios.yml diff --git a/.ado/scripts/xcodebuild.sh b/.ado/scripts/xcodebuild.sh new file mode 100755 index 0000000000..243cd0fd8e --- /dev/null +++ b/.ado/scripts/xcodebuild.sh @@ -0,0 +1,77 @@ +#!/bin/bash +set -eox pipefail + +workspace=$1 +sdk=$2 +scheme=$3 +action=$4 + +shift 4 + + +if [[ $sdk == iphoneos || $sdk == iphonesimulator ]]; then + if [[ $action == 'test' || $action == 'test-without-building' ]]; then + device=$(xcrun simctl list devices iPhone available) + re='iPhone [0-9]+ \(([-0-9A-Fa-f]+)\)' + [[ $device =~ $re ]] || exit 1 + shift || true + destination="-destination \"platform=iOS Simulator,id=${BASH_REMATCH[1]}\"" + else + destination='-destination "generic/platform=iOS Simulator"' + fi +elif [[ $sdk == macosx ]]; then + destination='' +elif [[ $sdk == xros || $sdk == xrsimulator ]]; then + if [[ $action == 'test' || $action == 'test-without-building' ]]; then + device=$(xcrun simctl list devices visionOS available) + re='Apple Vision Pro \(([-0-9A-Fa-f]+)\)' + [[ $device =~ $re ]] || exit 1 + shift || true + destination="-destination \"platform=visionOS Simulator,id=${BASH_REMATCH[1]}\"" + else + destination='-destination "generic/platform=visionOS Simulator"' + fi +else + echo "Cannot detect sdk: $sdk" + exit 1 +fi + +build_cmd=$( + echo xcodebuild \ + -workspace "$workspace" \ + -scheme "$scheme" \ + -sdk "$sdk" \ + "$destination" \ + -derivedDataPath $(dirname $workspace)/build \ + CODE_SIGNING_ALLOWED=NO \ + COMPILER_INDEX_STORE_ENABLE=NO \ + "$action" \ + "$@" \ + +) + +if [[ "$CCACHE_DISABLE" != "1" ]]; then + if ! command -v ccache 1> /dev/null; then + brew install ccache + fi + + CCACHE_HOME=$(dirname $(dirname $(which ccache)))/opt/ccache + + export CCACHE_DIR="$(git rev-parse --show-toplevel)/.ccache" + + export CC="${CCACHE_HOME}/libexec/clang" + export CXX="${CCACHE_HOME}/libexec/clang++" + export CMAKE_C_COMPILER_LAUNCHER=$(which ccache) + export CMAKE_CXX_COMPILER_LAUNCHER=$(which ccache) + + ccache --zero-stats 1> /dev/null +fi +if ! command -v xcbeautify 1> /dev/null; then + brew install xcbeautify +fi + +eval "$build_cmd" | xcbeautify --report junit + +if [[ "$CCACHE_DISABLE" != "1" ]]; then + ccache --show-stats --verbose +fi diff --git a/.ado/templates/apple-ensure-valid-cocoapods.yml b/.ado/templates/apple-ensure-valid-cocoapods.yml deleted file mode 100644 index ae36ecc433..0000000000 --- a/.ado/templates/apple-ensure-valid-cocoapods.yml +++ /dev/null @@ -1,10 +0,0 @@ -# Cocoapods 1.15.0 doesn't work with React Native -steps: - - task: CmdLine@2 - displayName: Install Cocoapods 1.15.2 if needed - inputs: - script: | - POD_VERSION=$(pod --version) - if [ $POD_VERSION = 1.15.0 ]; then - gem install cocoapods -v 1.15.2 - fi diff --git a/.ado/templates/apple-tools-setup.yml b/.ado/templates/apple-tools-setup.yml new file mode 100644 index 0000000000..ec7122c19a --- /dev/null +++ b/.ado/templates/apple-tools-setup.yml @@ -0,0 +1,26 @@ +steps: + - task: NodeTool@0 + inputs: + versionSpec: '18.x' + + - task: CmdLine@2 + displayName: 'brew bundle' + inputs: + script: | + brew bundle --file .ado/Brewfile + cat .ado/Brewfile.lock.json + + # Cocoapods 1.15.0 doesn't work with React Native + - task: CmdLine@2 + displayName: Install Cocoapods 1.15.2 if needed + inputs: + script: | + POD_VERSION=$(pod --version) + if [ $POD_VERSION = 1.15.0 ]; then + gem install cocoapods -v 1.15.2 + fi + + - bash: | + sudo xcode-select --switch $(xcode_version) + displayName: Use $(xcode_friendly_name) + failOnStderr: true diff --git a/.ado/variables/vars.yml b/.ado/variables/vars.yml index 2384ed8a17..77ab09cfd7 100644 --- a/.ado/variables/vars.yml +++ b/.ado/variables/vars.yml @@ -1,11 +1,7 @@ variables: - name: VmImageApple - value: macos-13 - - name: xcode_version + value: macos-latest-internal + - name: xcode_friendly_name value: 'Xcode 15.2' - - name: xcode_path + - name: xcode_version value: '/Applications/Xcode_15.2.app' - - name: ios_version - value: '17.2.0' - - name: ios_simulator - value: 'iPhone 15 (17.2.0)' diff --git a/.ado/xcconfig/publish_overrides.xcconfig b/.ado/xcconfig/publish_overrides.xcconfig deleted file mode 100644 index 606b00f2f8..0000000000 --- a/.ado/xcconfig/publish_overrides.xcconfig +++ /dev/null @@ -1,23 +0,0 @@ -#include "publish_staticanalysis.xcconfig" -// For publish builds, only provide line tables for symbolizing crashes -CLANG_DEBUG_INFORMATION_LEVEL[config=Release]=line-tables-only -// The following build setting caused build errors, so it is commented out and placed in every podspec instead -// OTHER_SWIFT_FLAGS=-gline-tables-only - -// Optimize for size in publish builds -SWIFT_OPTIMIZATION_LEVEL[config=Release]=-Osize - -// Build for all architectures, not just the active one -ONLY_ACTIVE_ARCH=NO - -// react-native/react_native_pods.rb sometimes makes our lives difficult -EXCLUDED_ARCHS = - -// Specify the exact Swift version used for reproducibility -SWIFT_VERSION = 5.0 - -// Turn off Sanitizers for Release Builds -CLANG_ADDRESS_SANITIZER = NO -CLANG_UNDEFINED_BEHAVIOR_SANITIZER = NO - - diff --git a/.ado/xcconfig/publish_overrides_ios_device.xcconfig b/.ado/xcconfig/publish_overrides_ios_device.xcconfig deleted file mode 100644 index 39d564b93e..0000000000 --- a/.ado/xcconfig/publish_overrides_ios_device.xcconfig +++ /dev/null @@ -1,4 +0,0 @@ -#include "publish_overrides.xcconfig" - -// Explicitly build arm64e for iOS device builds in case our clients need it -ARCHS = $(ARCHS_STANDARD) arm64e diff --git a/.ado/xcconfig/publish_overrides_ios_simulator.xcconfig b/.ado/xcconfig/publish_overrides_ios_simulator.xcconfig deleted file mode 100644 index 0a7a64d9e1..0000000000 --- a/.ado/xcconfig/publish_overrides_ios_simulator.xcconfig +++ /dev/null @@ -1,4 +0,0 @@ -#include "publish_overrides.xcconfig" - -// Explicitly build arm64 and x86_64 machines -ARCHS = arm64 x86_64 diff --git a/.ado/xcconfig/publish_staticanalysis.xcconfig b/.ado/xcconfig/publish_staticanalysis.xcconfig deleted file mode 100644 index c87887e025..0000000000 --- a/.ado/xcconfig/publish_staticanalysis.xcconfig +++ /dev/null @@ -1,13 +0,0 @@ -RUN_CLANG_STATIC_ANALYZER = YES -CLANG_STATIC_ANALYZER_MODE = deep - -// Required security settings for production code (do not override at target/project level, with the possible -// exception of legacy test code) -CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES -CLANG_ANALYZER_SECURITY_KEYCHAIN_API = YES -CLANG_ANALYZER_SECURITY_INSECUREAPI_UNCHECKEDRETURN = YES -CLANG_ANALYZER_SECURITY_INSECUREAPI_GETPW_GETS = YES -CLANG_ANALYZER_SECURITY_INSECUREAPI_MKSTEMP = YES -CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES -CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES -CLANG_ANALYZER_SECURITY_INSECUREAPI_VFORK = YES diff --git a/.gitignore b/.gitignore index a2f4061232..829c279731 100644 --- a/.gitignore +++ b/.gitignore @@ -112,4 +112,7 @@ apps/*/.vscode/.react/ !**/.yarn/plugins !**/.yarn/releases !**/.yarn/sdks -!**/.yarn/versions \ No newline at end of file +!**/.yarn/versions + +# Ccache +.ccache \ No newline at end of file