Skip to content

Commit

Permalink
Add new samples (#511)
Browse files Browse the repository at this point in the history
* Add iOS and macOS samples with Tuist

* Add headers

* Close macOS app on last window closed

* Add tvOS, watchOS and visionOS

* Workaround crash on sendAllReports

* Make more clean default UI

* Fix SPM syntax

* Simplify the setup

* Use a single target for sample

* Add build rule

* Fix build action

* Fix step name

* Add Package.swift as builds trigger
  • Loading branch information
bamx23 committed Jun 25, 2024
1 parent 118810e commit 3a3b99e
Show file tree
Hide file tree
Showing 11 changed files with 444 additions and 0 deletions.
69 changes: 69 additions & 0 deletions .github/workflows/build-sample.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Build Sample

on:
pull_request:
paths:
- 'Sources/**/include/**'
- 'Package.swift'
- 'Samples/**'
- '.github/workflows/build-sample.yml'

push:
branches:
- master

schedule:
- cron: '0 0 1 * *'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
sample:
runs-on: macos-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- platform: iOS
- platform: macOS
- platform: tvOS
- platform: watchOS
- platform: visionOS
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Use Latest Stable Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable

- name: Install visionOS Platform
if: matrix.platform == 'visionOS'
shell: bash
run: |
# See https://github.com/actions/runner-images/issues/8144#issuecomment-1902072070
defaults write com.apple.dt.Xcode AllowUnsupportedVisionOSHost -bool YES
defaults write com.apple.CoreSimulator AllowUnsupportedVisionOSHost -bool YES
xcodebuild -downloadPlatform visionOS
- name: Install Tuist
run: |
brew tap tuist/tuist
brew install tuist@4.18.0
- name: Generate Project
working-directory: ./Samples
run: tuist generate --verbose --no-open

- name: Run Build
uses: bamx23/xcodebuild@os-version
timeout-minutes: 10
with:
action: build
workspace: "Samples/KSCrashSamples.xcworkspace"
scheme: "Sample"
platform: ${{ matrix.platform }}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ Carthage/Build
.build
.swiftpm/xcode/xcuserdata
.swiftpm/package.xcworkspace/xcuserdata
### Samples ###
/Samples/Common/.swiftpm
/Samples/**/Derived
/Samples/**/*.xcodeproj
/Samples/**/*.xcworkspace
49 changes: 49 additions & 0 deletions Samples/Common/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// swift-tools-version:5.3

import PackageDescription

let package = Package(
name: "KSCrashSamplesCommon",
platforms: [
.iOS(.v14),
.tvOS(.v14),
.watchOS(.v7),
.macOS(.v11),
],
products: [
.library(
name: "LibraryBridge",
targets: ["LibraryBridge"]
),
.library(
name: "CrashTriggers",
targets: ["CrashTriggers"]
),
.library(
name: "SampleUI",
targets: ["SampleUI"]
),
],
dependencies: [
.package(path: "../.."),
],
targets: [
.target(
name: "LibraryBridge",
dependencies: [
.product(name: "Recording", package: "KSCrash"),
.product(name: "Reporting", package: "KSCrash"),
]
),
.target(
name: "CrashTriggers"
),
.target(
name: "SampleUI",
dependencies: [
.target(name: "LibraryBridge"),
.target(name: "CrashTriggers"),
]
)
]
)
39 changes: 39 additions & 0 deletions Samples/Common/Sources/CrashTriggers/CrashTriggers.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// CrashTriggers.mm
//
// Created by Nikolay Volosatov on 2024-06-23.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import "CrashTriggers.h"

@implementation CrashTriggers

+ (void)nsexception
{
NSException *exc = [NSException exceptionWithName:NSGenericException
reason:@"Test"
userInfo:@{ @"a": @"b"}];
[exc raise];
}

@end
33 changes: 33 additions & 0 deletions Samples/Common/Sources/CrashTriggers/include/CrashTriggers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//
// CrashTriggers.h
//
// Created by Nikolay Volosatov on 2024-06-23.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

#import <Foundation/Foundation.h>

@interface CrashTriggers : NSObject

+ (void)nsexception;

@end
35 changes: 35 additions & 0 deletions Samples/Common/Sources/LibraryBridge/RecordingSample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// RecordingSample.swift
//
// Created by Nikolay Volosatov on 2024-06-23.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import Foundation
import KSCrashRecording

public class RecordingSample {
public static func simpleInstall() {
let config = KSCrashConfiguration()
KSCrash.shared().install(with: config)
}
}
37 changes: 37 additions & 0 deletions Samples/Common/Sources/LibraryBridge/ReportingSample.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// ReportingSample.swift
//
// Created by Nikolay Volosatov on 2024-06-23.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import Foundation
import KSCrashRecording
import KSCrashFilters
import KSCrashSinks

public class ReportingSample {
public static func logToConsole() {
KSCrash.shared().sink = CrashReportSinkConsole.filter().defaultCrashReportFilterSet()
KSCrash.shared().sendAllReports()
}
}
54 changes: 54 additions & 0 deletions Samples/Common/Sources/SampleUI/SampleView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// SampleView.swift
//
// Created by Nikolay Volosatov on 2024-06-23.
//
// Copyright (c) 2012 Karl Stenerud. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall remain in place
// in this source code.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

import SwiftUI
import LibraryBridge
import CrashTriggers

public struct SampleView: View {
public init() { }

public var body: some View {
NavigationView {
List {
Section(header: Text("Crashes")) {
Button("NSException") {
CrashTriggers.nsexception()
}
}
Section(header: Text("Reporting")) {
Button("Log To Console") {
ReportingSample.logToConsole()
}
}
}
.navigationTitle("KSCrash Sample")
}
.onAppear {
RecordingSample.simpleInstall()
}
}
}
43 changes: 43 additions & 0 deletions Samples/Project.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import ProjectDescription

let project = Project(
name: "KSCrashSamples",
packages: [
.local(path: "Common"),
],
targets: [
.target(
name: "Sample",
destinations: .allForSample,
product: .app,
bundleId: "com.github.kstenerud.KSCrash.Sample",
infoPlist: InfoPlist.extendingDefault(with: [
"UILaunchScreen": [
"UIImageName": "LaunchImage",
"UIBackgroundColor": "LaunchScreenColor",
],
"UISupportedInterfaceOrientations": ["UIInterfaceOrientationPortrait"],
"CFBundleDisplayName": "KSCrashSample",
"WKApplication": true,
"WKWatchOnly": true,
]),
sources: ["Sources/**"],
dependencies: [
.package(product: "SampleUI", type: .runtime),
]
),
]
)

extension Set where Element == ProjectDescription.Destination {
static var allForSample: Self {
let sets: [Set<Destination>] = [
.iOS,
.macOS,
.tvOS,
.watchOS,
.visionOS,
]
return sets.reduce(.init()) { $0.union($1) }
}
}
Loading

0 comments on commit 3a3b99e

Please sign in to comment.