-
Notifications
You must be signed in to change notification settings - Fork 24
Upload Snapshots to Sentry using SnapshotPreview and SwiftSnapshotTesting libraries #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
c2b918e
56fdd63
81230e5
676b945
4b99f38
5f81e4c
1c63516
86400e6
1a07a3c
5a524f3
4693c5c
7832aa8
7ffad21
887a063
05b0f54
bf734e6
d363a7c
22a179e
10b9207
73af48b
0e0dc8f
a7053a1
b8e01e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| name: Sentry iOS Upload (Snapshots) | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: [ios/**, .github/workflows/ios*] | ||
| pull_request: | ||
| branches: [main] | ||
| paths: [ios/**, .github/workflows/ios*] | ||
|
|
||
| jobs: | ||
| upload_sentry_snapshots: | ||
| runs-on: macos-26 | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: ./ios | ||
|
|
||
| env: | ||
| SNAPSHOT_UPLOAD_BASE_DIR: "${{ github.workspace }}/ios/snapshot-images" | ||
| DERIVED_DATA_PATH: "${{ github.workspace }}/DerivedData-snapshot-upload" | ||
| XCODE_RUNNING_FOR_PREVIEWS: 1 | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Ruby env | ||
| uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: 3.3.10 | ||
| bundler-cache: true | ||
|
|
||
| - name: Setup gems | ||
| run: exec ../.github/scripts/ios/setup.sh | ||
|
|
||
| - name: Boot iPhone simulator | ||
| run: xcrun simctl boot "iPhone 17 Pro Max" || true | ||
|
|
||
| - name: Cache Swift Package Manager | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/Library/Caches/org.swift.swiftpm | ||
| ${{ env.DERIVED_DATA_PATH }}/SourcePackages | ||
| key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} | ||
| restore-keys: ${{ runner.os }}-spm- | ||
|
|
||
| - name: Prepare snapshot export directories | ||
| run: | | ||
| mkdir -p "${SNAPSHOT_UPLOAD_BASE_DIR}/iphone" | ||
| mkdir -p "${SNAPSHOT_UPLOAD_BASE_DIR}/ipad" | ||
| mkdir -p "${DERIVED_DATA_PATH}" | ||
|
|
||
| - name: Build snapshot tests | ||
| run: | | ||
| set -o pipefail && xcodebuild build-for-testing \ | ||
| -scheme HackerNews \ | ||
| -sdk iphonesimulator \ | ||
| -destination 'platform=iOS Simulator,name=iPhone 17 Pro Max,arch=arm64' \ | ||
| -only-testing:HackerNewsTests/HackerNewsSnapshotTest \ | ||
| -resultBundlePath ../SnapshotBuildForTesting.xcresult \ | ||
| -derivedDataPath "${DERIVED_DATA_PATH}" \ | ||
| -skipPackagePluginValidation \ | ||
| ONLY_ACTIVE_ARCH=YES \ | ||
| TARGETED_DEVICE_FAMILY="1,2" \ | ||
| SUPPORTS_MACCATALYST=NO \ | ||
| CODE_SIGNING_ALLOWED=NO \ | ||
| COMPILATION_CACHING=YES \ | ||
| EAGER_LINKING=YES \ | ||
| FUSE_BUILD_SCRIPT_PHASES=YES \ | ||
| | xcpretty | ||
|
|
||
| - name: Boot iPad simulator | ||
| run: xcrun simctl boot "iPad Air 11-inch (M4)" || true | ||
|
|
||
| - name: Generate snapshot images (iPhone) | ||
| env: | ||
| TEST_RUNNER_SNAPSHOTS_EXPORT_DIR: "${{ env.SNAPSHOT_UPLOAD_BASE_DIR }}/iphone" | ||
| run: | | ||
| set -o pipefail && xcodebuild test-without-building \ | ||
| -scheme HackerNews \ | ||
| -sdk iphonesimulator \ | ||
| -destination 'platform=iOS Simulator,name=iPhone 17 Pro Max,arch=arm64' \ | ||
| -only-testing:HackerNewsTests/HackerNewsSnapshotTest \ | ||
| -resultBundlePath ../SnapshotResults-iphone.xcresult \ | ||
| -derivedDataPath "${DERIVED_DATA_PATH}" \ | ||
| | xcpretty | ||
|
|
||
| - name: Generate snapshot images (iPad) | ||
| env: | ||
| TEST_RUNNER_SNAPSHOTS_EXPORT_DIR: "${{ env.SNAPSHOT_UPLOAD_BASE_DIR }}/ipad" | ||
| run: | | ||
| set -o pipefail && xcodebuild test-without-building \ | ||
| -scheme HackerNews \ | ||
| -sdk iphonesimulator \ | ||
| -destination 'platform=iOS Simulator,name=iPad Air 11-inch (M4),arch=arm64' \ | ||
| -only-testing:HackerNewsTests/HackerNewsSnapshotTest \ | ||
| -resultBundlePath ../SnapshotResults-ipad.xcresult \ | ||
| -derivedDataPath "${DERIVED_DATA_PATH}" \ | ||
| | xcpretty | ||
|
Comment on lines
+93
to
+103
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: The iPad snapshot generation step lacks Suggested FixAdd Prompt for AI Agent |
||
|
|
||
| - name: List generated snapshot files | ||
| run: | | ||
| echo "Generated snapshot files:" | ||
| find "${SNAPSHOT_UPLOAD_BASE_DIR}" -type f | sort | ||
| echo | ||
| echo "Total PNG images: $(find "${SNAPSHOT_UPLOAD_BASE_DIR}" -type f -name '*.png' | wc -l | tr -d ' ')" | ||
|
|
||
| - name: Upload snapshots to Sentry | ||
| env: | ||
| SENTRY_SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_SENTRY_AUTH_TOKEN }} | ||
| run: bundle exec fastlane ios upload_sentry_snapshots path:"${SNAPSHOT_UPLOAD_BASE_DIR}" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| name: Sentry iOS Upload (Swift Snapshot Testing) | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| paths: [ios/**, .github/workflows/ios*] | ||
| pull_request: | ||
| branches: [main] | ||
| paths: [ios/**, .github/workflows/ios*] | ||
|
|
||
| jobs: | ||
| upload_sentry_swift_snapshots: | ||
| runs-on: macos-26 | ||
|
|
||
| defaults: | ||
| run: | ||
| working-directory: ./ios | ||
|
|
||
| env: | ||
| XCODE_RUNNING_FOR_PREVIEWS: 1 | ||
| TEST_RUNNER_SNAPSHOT_TESTING_RECORD: all | ||
|
|
||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Set up Ruby env | ||
| uses: ruby/setup-ruby@v1 | ||
| with: | ||
| ruby-version: 3.3.10 | ||
| bundler-cache: true | ||
|
|
||
| - name: Setup gems | ||
| run: exec ../.github/scripts/ios/setup.sh | ||
|
|
||
| - name: Boot iPhone simulator | ||
| run: xcrun simctl boot "iPhone 17 Pro Max" || true | ||
|
|
||
| - name: Cache Swift Package Manager | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: | | ||
| ~/Library/Caches/org.swift.swiftpm | ||
| ~/Library/Developer/Xcode/DerivedData/HackerNews-*/SourcePackages | ||
| key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} | ||
| restore-keys: ${{ runner.os }}-spm- | ||
|
|
||
| - name: Generate snapshot images | ||
| continue-on-error: true | ||
|
sentry[bot] marked this conversation as resolved.
|
||
| run: | | ||
| set -o pipefail && xcodebuild test \ | ||
| -scheme HackerNews \ | ||
| -sdk iphonesimulator \ | ||
| -destination 'platform=iOS Simulator,name=iPhone 17 Pro Max,arch=arm64' \ | ||
| -only-testing:HackerNewsTests/SwiftSnapshotTest \ | ||
| -resultBundlePath ../SnapshotResults-swift-snapshots.xcresult \ | ||
| -skipPackagePluginValidation \ | ||
| ONLY_ACTIVE_ARCH=YES \ | ||
| TARGETED_DEVICE_FAMILY=1 \ | ||
| SUPPORTS_MACCATALYST=NO \ | ||
| CODE_SIGNING_ALLOWED=NO \ | ||
| COMPILATION_CACHING=YES \ | ||
| EAGER_LINKING=YES \ | ||
| FUSE_BUILD_SCRIPT_PHASES=YES \ | ||
| | xcpretty | ||
|
|
||
| - name: List generated images | ||
| run: | | ||
| echo "Generated snapshot images:" | ||
| ls -1 HackerNewsTests/__Snapshots__/SwiftSnapshotTest/ || echo "No snapshots found" | ||
| echo "Total: $(ls -1 HackerNewsTests/__Snapshots__/SwiftSnapshotTest/ 2>/dev/null | wc -l | tr -d ' ') images" | ||
|
|
||
| - name: Upload snapshots to Sentry | ||
| env: | ||
| SENTRY_SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_SENTRY_AUTH_TOKEN }} | ||
| run: bundle exec fastlane ios upload_sentry_snapshots_swift_snapshot_testing | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,15 +14,6 @@ import Common | |
|
|
||
| final class SwiftSnapshotTest: XCTestCase { | ||
|
|
||
| override func invokeTest() { | ||
| // record: .all always records new snapshots and fails every test. | ||
| // Change to .missing to only record when no reference image exists, | ||
| // or remove this override entirely to compare against existing snapshots. | ||
| withSnapshotTesting(record: .all) { | ||
| super.invokeTest() | ||
| } | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. intentional?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @NicoHinderling Yes, because Swift Snapshot Testing does diffing locally, we would only want to enable recording on CI workflows. We use an environmental variable in the GitHub workflow example |
||
| @MainActor func testPostListScreen() { | ||
| @State var appViewModel = AppViewModel( | ||
| bookmarkStore: FakeBookmarkDataStore(), | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.