Skip to content
Merged
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
123 changes: 118 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,125 @@ on:
- main

jobs:
build:
runs-on: macos-latest
build-and-test:
runs-on: macos-15
strategy:
fail-fast: false
matrix:
include:
- xcode: "16.2"
ios: "18"

steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Build
run: swift build
- name: Select Xcode ${{ matrix.xcode }}
run: sudo xcode-select -s /Applications/Xcode_${{ matrix.xcode }}.app/Contents/Developer

- name: Show Xcode and Swift version
run: |
xcodebuild -version
swift --version

- name: List available simulators
run: xcrun simctl list devices available

- name: List SwiftPM schemes
run: xcodebuild -workspace .swiftpm/xcode/package.xcworkspace -list

- name: Install xcpretty
run: sudo gem install xcpretty

- name: Select iOS simulator for ${{ matrix.ios }}
env:
IOS_VERSION: ${{ matrix.ios }}
run: |
set -euo pipefail
RUNTIME_JSON=$(xcrun simctl list runtimes --json 2>/dev/null || true)
if [ -z "$RUNTIME_JSON" ]; then
echo "Failed to read simctl runtimes JSON"
xcrun simctl list runtimes || true
exit 1
fi
export RUNTIME_JSON
RUNTIME_ID=$(python3 - <<'PY'
import json, os, sys
data = json.loads(os.environ["RUNTIME_JSON"])
target = os.environ["IOS_VERSION"]
runtimes = [
r for r in data.get("runtimes", [])
if r.get("platform") == "iOS"
and r.get("isAvailable")
and (
r.get("version", "") == target
or r.get("version", "").startswith(target + ".")
)
]
if not runtimes:
print(f"Missing iOS runtime for {target}", file=sys.stderr)
sys.exit(1)
print(runtimes[0]["identifier"])
PY
)
export RUNTIME_ID
DEVICE_JSON=$(xcrun simctl list devices --json 2>/dev/null || true)
if [ -z "$DEVICE_JSON" ]; then
echo "Failed to read simctl devices JSON"
xcrun simctl list devices || true
exit 1
fi
export DEVICE_JSON
DEVICE_ID=$(python3 - <<'PY'
import json, os, sys
data = json.loads(os.environ["DEVICE_JSON"])
runtime = os.environ["RUNTIME_ID"]
devices = data.get("devices", {}).get(runtime, [])
for device in devices:
if device.get("isAvailable") and "iPhone 16" in device.get("name", ""):
print(device["udid"])
sys.exit(0)
for device in devices:
if device.get("isAvailable") and "iPhone" in device.get("name", ""):
print(device["udid"])
sys.exit(0)
print("")
PY
)
if [ -z "$DEVICE_ID" ]; then
DEVICE_TYPES_JSON=$(xcrun simctl list devicetypes --json 2>/dev/null || true)
if [ -z "$DEVICE_TYPES_JSON" ]; then
echo "Failed to read simctl device types JSON"
xcrun simctl list devicetypes || true
exit 1
fi
export DEVICE_TYPES_JSON
DEVICE_TYPE=$(python3 - <<'PY'
import json, sys, os
data = json.loads(os.environ["DEVICE_TYPES_JSON"])
devicetypes = [d for d in data.get("devicetypes", []) if d.get("name", "").startswith("iPhone")]
for device in devicetypes:
if device.get("name") == "iPhone 16":
print(device["identifier"])
sys.exit(0)
if devicetypes:
print(devicetypes[0]["identifier"])
sys.exit(0)
print("", end="")
sys.exit(1)
PY
)
DEVICE_ID=$(xcrun simctl create "CI-iPhone-${IOS_VERSION}" "$DEVICE_TYPE" "$RUNTIME_ID")
fi
echo "SIMULATOR_ID=$DEVICE_ID" >> "$GITHUB_ENV"

- name: Build and Test on iOS ${{ matrix.ios }}
run: |
set -o pipefail
xcodebuild test \
-workspace .swiftpm/xcode/package.xcworkspace \
-scheme Atlantis \
-destination "id=${SIMULATOR_ID}" \
-skipPackagePluginValidation \
-skipMacroValidation \
| xcpretty --color
10 changes: 10 additions & 0 deletions .swiftpm/xcode/xcshareddata/xcschemes/Atlantis.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "AtlantisTests"
BuildableName = "AtlantisTests"
BlueprintName = "AtlantisTests"
ReferencedContainer = "container:">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
<LaunchAction
Expand Down
5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ let package = Package(
dependencies: [],
path: "Sources",
resources: [.copy("PrivacyInfo.xcprivacy")])
,
.testTarget(
name: "AtlantisTests",
dependencies: ["Atlantis"],
path: "Tests/atlantisTests")
],
swiftLanguageVersions: [.v5]
)
15 changes: 14 additions & 1 deletion Sources/Atlantis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public final class Atlantis: NSObject {
// MARK: - Components

private weak var delegate: AtlantisDelegate?
private let transporter: Transporter
private var transporter: Transporter
private var injector: Injector = NetworkInjector()
private(set) var configuration: Configuration = Configuration.default()
private var packages: [String: TrafficPackage] = [:]
Expand Down Expand Up @@ -149,6 +149,19 @@ public final class Atlantis: NSObject {
}
}

#if DEBUG
extension Atlantis {

/// Testing-only hook to inject a custom Transporter.
static func setTransporterForTesting(_ transporter: Transporter) {
retainedTestTransporters.append(Atlantis.shared.transporter)
Atlantis.shared.transporter = transporter
}
}

private var retainedTestTransporters: [Transporter] = []
#endif

// MARK: - Private

extension Atlantis {
Expand Down
Loading
Loading