Skip to content

Commit

Permalink
Merge branch 'master' into feat/swift
Browse files Browse the repository at this point in the history
  • Loading branch information
brustolin authored Oct 24, 2022
2 parents 9e7c555 + 8168e86 commit 7d5e7d1
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 19 deletions.
34 changes: 19 additions & 15 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,17 @@ jobs:
fail-fast: false
matrix:
# Can't run tests on watchOS because XCTest is not available
# We can't use Xcode 10.3 because our tests contain a reference to MacCatalyst,
# which is only available since iOS 13 / Xcode 11.
# We can't use Xcode 11.7 as we use XCTestObservation. When building with Xcode 11.7
# we get the error 'XCTest/XCTest.h' not found. Setting ENABLE_TESTING_SEARCH_PATH=YES
# doesn't work.
include:
# Test on iOS 12.4
- runs-on: macos-10.15
# iOS 12.4
- runs-on: macos-11
platform: 'iOS'
xcode: '12.4'
xcode: '13.2.1'
test-destination-os: '12.4'

# Test on iOS 13.7
# iOS 13.7
- runs-on: macos-11
platform: 'iOS'
xcode: '13.2.1'
Expand Down Expand Up @@ -116,7 +114,7 @@ jobs:
xcode: '13.4.1'
test-destination-os: 'latest'

# tvOS 4
# tvOS 14
- runs-on: macos-11
platform: 'tvOS'
xcode: '12.5.1'
Expand All @@ -139,16 +137,15 @@ jobs:

- run: ./scripts/ci-select-xcode.sh ${{matrix.xcode}}

# Only Xcode 10.3 has an iOS 12.4 simulator. As we have a reference to MacCatalyst in our unit tests
# we can't run the tests with Xcode 10.3. Therefore we use a workaround with a symlink pointed out in:
# https://github.com/actions/virtual-environments/issues/551#issuecomment-637344435
- name: Prepare iOS 12.4 simulator
# GH action images don't have an iOS 12.4 simulator. Therefore we have to download and install the simulator manually.
- name: Install iOS 12.4 simulator
if: ${{ matrix.platform == 'iOS' && matrix.test-destination-os == '12.4'}}
run: |
sudo mkdir -p /Library/Developer/CoreSimulator/Profiles/Runtimes
sudo ln -s /Applications/Xcode_10.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS\ 12.4.simruntime
gem install xcode-install
xcversion simulators --install='iOS 12.4'
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-12-4"
# Workaround with a symlink pointed out in: https://github.com/actions/virtual-environments/issues/551#issuecomment-637344435
- name: Prepare iOS 13.7 simulator
if: ${{ matrix.platform == 'iOS' && matrix.test-destination-os == '13.7'}}
run: |
Expand Down Expand Up @@ -269,17 +266,24 @@ jobs:
# macos-11 doesn't have a simulator for iOS 12
ui-tests-swift-ios-12:
name: UI Tests on iOS 12 Simulator
runs-on: macos-10.15
runs-on: macos-11
strategy:
matrix:
target: ['ios_swift', 'ios_objc', 'tvos_swift']

steps:
- uses: actions/checkout@v3

# GH action images don't have an iOS 12.4 simulator. Therefore we have to download and install the simulator manually.
- name: Install iOS 12.4 simulator
run: |
gem install xcode-install
xcversion simulators --install='iOS 12.4'
xcrun simctl create custom-test-device "iPhone 8" "com.apple.CoreSimulator.SimRuntime.iOS-12-4"
# GitHub Actions sometimes fail to launch the UI tests. Therefore we retry
- name: Run Fastlane
run: for i in {1..2}; do fastlane ui_tests_${{matrix.target}} device:"$iPhone 8 (12.4)" address_sanitizer:false && break ; done
run: for i in {1..2}; do fastlane ui_tests_${{matrix.target}} device:"iPhone 8 (12.4)" address_sanitizer:false && break ; done
shell: sh

ui-tests-address-sanitizer:
Expand Down
4 changes: 4 additions & 0 deletions Samples/iOS-Swift/iOS-Swift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
637AFDB6243B02770034958B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 637AFDB4243B02770034958B /* LaunchScreen.storyboard */; };
7B3427F825876A5200056519 /* Tongariro.jpg in Resources */ = {isa = PBXBuildFile; fileRef = 7B3427F725876A5200056519 /* Tongariro.jpg */; };
7B64386B26A6C544000D0F65 /* LaunchUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B64386A26A6C544000D0F65 /* LaunchUITests.swift */; };
7B79000429028C7300A7F467 /* MetricKitManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7B79000329028C7300A7F467 /* MetricKitManager.swift */; };
7BFC8B0626D4D24B000D3504 /* LoremIpsum.txt in Resources */ = {isa = PBXBuildFile; fileRef = 7BFC8B0526D4D24B000D3504 /* LoremIpsum.txt */; };
844DA821282584C300E6B62E /* CoreDataViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D8F57BC427BBD787000D09D4 /* CoreDataViewController.swift */; };
844DA822282584F700E6B62E /* SentryData.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = D845F35927BAD4CC00A4D7A2 /* SentryData.xcdatamodeld */; };
Expand Down Expand Up @@ -240,6 +241,7 @@
7B64386826A6C544000D0F65 /* iOS-SwiftUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "iOS-SwiftUITests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
7B64386A26A6C544000D0F65 /* LaunchUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LaunchUITests.swift; sourceTree = "<group>"; };
7B64386C26A6C544000D0F65 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
7B79000329028C7300A7F467 /* MetricKitManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetricKitManager.swift; sourceTree = "<group>"; };
7BFC8B0526D4D24B000D3504 /* LoremIpsum.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = LoremIpsum.txt; sourceTree = "<group>"; };
848A2573286E3351008A8858 /* PerformanceBenchmarks.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = PerformanceBenchmarks.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
848A2578286E3490008A8858 /* PerformanceBenchmarks-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "PerformanceBenchmarks-Info.plist"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -493,6 +495,7 @@
D8DBDA74274D4E1600007380 /* Tools */ = {
isa = PBXGroup;
children = (
7B79000329028C7300A7F467 /* MetricKitManager.swift */,
84FB8125284001B800F3A94A /* SentryBenchmarking.h */,
84FB8129284001B800F3A94A /* SentryBenchmarking.mm */,
D8F3D04F274E572F00B56F8C /* DSNStorage.swift */,
Expand Down Expand Up @@ -802,6 +805,7 @@
D8F3D052274E572F00B56F8C /* DSNStorage.swift in Sources */,
D8F3D054274E572F00B56F8C /* RandomErrors.swift in Sources */,
D8D7BB4C2750095800044146 /* UIViewExtension.swift in Sources */,
7B79000429028C7300A7F467 /* MetricKitManager.swift in Sources */,
D8D7BB4A2750067900044146 /* UIAssert.swift in Sources */,
D8F3D057274E574200B56F8C /* LoremIpsumViewController.swift in Sources */,
D8DBDA78274D5FC400007380 /* SplitViewController.swift in Sources */,
Expand Down
24 changes: 24 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
options.appHangTimeoutInterval = 2
}

if #available(iOS 14.0, *) {
metricKit.receiveReports()
}

return true
}

func applicationWillTerminate(_ application: UIApplication) {
if #available(iOS 14.0, *) {
metricKit.pauseReports()
}
}

// Workaround for 'Stored properties cannot be marked potentially unavailable with '@available''
private var _metricKit: Any?
@available(iOS 14.0, *)
fileprivate var metricKit: MetricKitManager {
if _metricKit == nil {
_metricKit = MetricKitManager()
}

// We know the type so it's fine to force cast.
// swiftlint:disable force_cast
return _metricKit as! MetricKitManager
// swiftlint:enable force_cast
}
}
40 changes: 40 additions & 0 deletions Samples/iOS-Swift/iOS-Swift/Tools/MetricKitManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import Foundation
import MetricKit
import Sentry

@available(iOS 14.0, *)
class MetricKitManager: NSObject, MXMetricManagerSubscriber {
func receiveReports() {
let shared = MXMetricManager.shared
shared.add(self)
}

func pauseReports() {
let shared = MXMetricManager.shared
shared.remove(self)
}

func didReceive(_ payloads: [MXMetricPayload]) {
var attachments: [Attachment] = []
for payload in payloads {
let attachment = Attachment(data: payload.jsonRepresentation(), filename: "MXDiagnosticPayload.json")
attachments.append(attachment)
}

SentrySDK.capture(message: "MetricKit received MXMetricPayload.") { scope in
attachments.forEach { scope.add($0) }
}
}

func didReceive(_ payloads: [MXDiagnosticPayload]) {
var attachments: [Attachment] = []
for payload in payloads {
let attachment = Attachment(data: payload.jsonRepresentation(), filename: "MXDiagnosticPayload.json")
attachments.append(attachment)
}

SentrySDK.capture(message: "MetricKit received MXDiagnosticPayload.") { scope in
attachments.forEach { scope.add($0) }
}
}
}
4 changes: 2 additions & 2 deletions Samples/iOS-Swift/iOS-SwiftUITests/LaunchUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ class LaunchUITests: XCTestCase {
let app = XCUIApplication()
app.navigationBars["iOS_Swift.SecondarySplitView"].buttons["Root ViewController"].waitForExistence("SplitView not loaded.")

// This validation is currently not working on iOS 10.
if #available(iOS 11.0, *) {
// This validation is currently not working on iOS 12 and iOS 10.
if #available(iOS 13.0, *) {
assertApp()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Sentry/Public/SentryEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

NS_ASSUME_NONNULL_BEGIN

@class SentryThread, SentryException, SentryStacktrace, SentryUser, SentryDebugMeta, SentryContext,
@class SentryThread, SentryException, SentryStacktrace, SentryUser, SentryDebugMeta,
SentryBreadcrumb, SentryId, SentryMessage;

NS_SWIFT_NAME(Event)
Expand Down
17 changes: 17 additions & 0 deletions develop-docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,28 @@ Related links:

- https://github.com/getsentry/sentry-cocoa/pull/1751

### Manually installing iOS 12 simulators

Date: October 21st 2022
Contributors: @philipphofmann

GH actions will remove the macOS-10.15 image, which contains an iOS 12 simulator on 12/1/22; see https://github.com/actions/runner-images/issues/5583.
Neither the[ macOS-11](https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md#installed-sdks) nor the
[macOS-12](https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md#installed-sdks) image contains an iOS 12 simulator. GH
[concluded](https://github.com/actions/runner-images/issues/551#issuecomment-788822538) to not add more pre-installed simulators. SauceLabs doesn't
support running unit tests and adding another cloud solution as Firebase TestLab would increase the complexity of CI. Not running the unit tests on
iOS 12 opens a risk of introducing bugs, which has already happened in the past, especially with swizzling. Therefore, we give manually installing
the iOS 12 simulator a try.

Related to [GH-2218](https://github.com/getsentry/sentry-cocoa/issues/2218)

### Adding Swift code in the project

Date: October 1st 2022
Contributors: @brustolin

A Sentry SDK started to be [written in Swift once,](https://github.com/getsentry/raven-swift) but due to ABI not being stable at that time, it got dropped. Since then Swift 5.1 landed and we got ABI stability. We’ve considered adding Swift to our sentry.cocoa SDK since then, but because of some of the trade offs, we’ve postponed that decision.
This changed with our goal to better support SwiftUI. It’s growing in popularity and we need to write code in Swift in order to support it.
SwiftUI support will be available through an adicional library, but in order to support it we need to be able to demangle Swift class names in Sentry SDK, which can be done by using Swift API.
Since we support SPM, and SPM don't support multi language projects, we need to create two different targets, one with Swift and another with Objective-c code, because of that our Swift code in SPM resides in a different module, which requires a different import in projects, and for now, this is the reason we should avoid writing public API in Swift. But, everything written in Swift will be public if users import Sentry via CocoaPods or Carthage.

1 change: 0 additions & 1 deletion scripts/ci-select-xcode.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/bash

# For available Xcode versions see:
# - https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md#xcode
# - https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
# - https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md

Expand Down

0 comments on commit 7d5e7d1

Please sign in to comment.