Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/ios-client.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Builds and tests the iOS SDK (clients/ios) when it changes: the unit tests on macOS and on an iOS
# simulator, two checks that keep the SDK safe to embed, and the sample app, whose Objective-C file
# compile-checks the SDK's generated header.
name: iOS client

on:
pull_request:
paths:
- 'clients/ios/**'
- '.github/workflows/ios-client.yml'
push:
branches: [main, sudoquery-monorepo-impl]
paths:
- 'clients/ios/**'
- '.github/workflows/ios-client.yml'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: ios-client-${{ github.ref }}
cancel-in-progress: true

jobs:
check:
runs-on: macos-15
timeout-minutes: 45
defaults:
run:
working-directory: clients/ios
steps:
- uses: actions/checkout@v4

- name: Toolchain
run: xcodebuild -version && swift --version

- name: Test on macOS
run: swift test -Xswiftc -warnings-as-errors

- name: The SDK never traps
run: |
if grep -rnE '(^|[^[:alnum:]_])(try!|as!|fatalError\(|precondition(Failure)?\()' Sources; then
echo "::error::SDK code must not trap inside the app; handle the failure instead"
exit 1
fi

# iOS 13 and 14 apps (Objective-C-only ones in particular) may not ship the Swift
# Concurrency back-deployment library, so the SDK uses GCD and locks only.
- name: The SDK needs no Swift Concurrency runtime
shell: bash
run: |
symbols=$(find .build/debug/SudoQuery.build -name '*.o' -exec nm -u {} +)
if ! grep -q '_swift_retain' <<<"$symbols"; then
echo "::error::no SudoQuery object files were read"
exit 1
fi
if grep -E '_swift_task_|_swift_continuation_|_swift_job_' <<<"$symbols"; then
echo "::error::SudoQuery references the Swift Concurrency runtime"
exit 1
fi

- name: Create a throwaway iPhone simulator
id: sim
run: |
runtimes=$(xcrun simctl list runtimes --json)
runtime=$(jq -r '[.runtimes[] | select(.platform == "iOS" and .isAvailable)] | sort_by(.version | split(".") | map(tonumber)) | last | .identifier' <<<"$runtimes")
device=$(jq -r --arg runtime "$runtime" '.runtimes[] | select(.identifier == $runtime) | [.supportedDeviceTypes[] | select(.productFamily == "iPhone")] | first | .identifier' <<<"$runtimes")
echo "Using $device on $runtime"
echo "udid=$(xcrun simctl create sudoquery-ci "$device" "$runtime")" >> "$GITHUB_OUTPUT"

- name: Test on the iOS simulator
run: |
xcodebuild test -scheme SudoQuery -destination "id=${{ steps.sim.outputs.udid }}" \
-derivedDataPath .build/xcode -resultBundlePath .build/xcode/ios-tests.xcresult \
SWIFT_TREAT_WARNINGS_AS_ERRORS=YES
total=$(xcrun xcresulttool get test-results summary --path .build/xcode/ios-tests.xcresult --compact | jq .totalTestCount)
echo "iOS tests run: $total"
[ "$total" -gt 0 ]

- name: Build the sample app (Swift and Objective-C)
run: |
xcodebuild build -project Sample/SudoQuerySample.xcodeproj -scheme SudoQuerySample \
-destination 'generic/platform=iOS Simulator' -derivedDataPath .build/sample \
CODE_SIGNING_ALLOWED=NO

- name: Delete the simulator
if: always() && steps.sim.outputs.udid != ''
run: xcrun simctl delete "${{ steps.sim.outputs.udid }}"
6 changes: 6 additions & 0 deletions clients/ios/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.build/
.swiftpm/
xcuserdata/
DerivedData/
*.xcresult
Package.resolved
24 changes: 24 additions & 0 deletions clients/ios/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// swift-tools-version: 6.0
// The SudoQuery iOS SDK: stores events on disk, batches them and delivers them to the
// collector's /v1/events/batch route.
import PackageDescription

let package = Package(
name: "SudoQuery",
// The SDK is for iOS apps. macOS is listed only so `swift test` runs on a Mac.
platforms: [.iOS(.v13), .macOS(.v10_15)],
products: [
.library(name: "SudoQuery", targets: ["SudoQuery"]),
],
targets: [
.target(
name: "SudoQuery",
resources: [.copy("Resources/PrivacyInfo.xcprivacy")]
),
.testTarget(
name: "SudoQueryTests",
dependencies: ["SudoQuery"],
resources: [.copy("Resources/golden")]
),
]
)
294 changes: 294 additions & 0 deletions clients/ios/README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions clients/ios/Sample/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SudoQueryEndpoint</key>
<string>$(SUDOQUERY_ENDPOINT)</string>
<key>SudoQueryOrgId</key>
<string>$(SUDOQUERY_ORG_ID)</string>
<key>SudoQueryWorkspaceId</key>
<string>$(SUDOQUERY_WORKSPACE_ID)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsLocalNetworking</key>
<true/>
</dict>
</dict>
</plist>
Loading
Loading