Upload Snapshots to Sentry using SnapshotPreview and SwiftSnapshotTesting libraries #18
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | |
| TEST_RUNNER_SNAPSHOTS_EXPORT_DIR: "${{ github.workspace }}/ios/snapshot-images" | |
| 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 | |
| key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} | |
| restore-keys: ${{ runner.os }}-spm- | |
| - name: Cache DerivedData | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ github.workspace }}/ios/build/DerivedData | |
| key: ${{ runner.os }}-dd-${{ github.head_ref || github.ref_name }} | |
| restore-keys: ${{ runner.os }}-dd- | |
| - name: Build for testing (iPhone) | |
| run: | | |
| set -o pipefail && xcodebuild build-for-testing \ | |
| -scheme HackerNews \ | |
| -sdk iphonesimulator \ | |
| -destination 'platform=iOS Simulator,name=iPhone 17 Pro Max' \ | |
| -derivedDataPath build/DerivedData \ | |
| -only-testing:HackerNewsTests/HackerNewsSnapshotTest \ | |
| -skipPackageUpdates \ | |
| 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: Generate snapshot images (iPhone) | |
| run: | | |
| set -o pipefail && xcodebuild test-without-building \ | |
| -scheme HackerNews \ | |
| -sdk iphonesimulator \ | |
| -destination 'platform=iOS Simulator,name=iPhone 17 Pro Max' \ | |
| -derivedDataPath build/DerivedData \ | |
| -only-testing:HackerNewsTests/HackerNewsSnapshotTest \ | |
| -resultBundlePath ../SnapshotResults-iphone.xcresult \ | |
| | xcpretty | |
| # - name: Boot iPad simulator | |
| # run: xcrun simctl boot "iPad Air 11-inch (M3)" || true | |
| # - name: Generate snapshot images (iPad) | |
| # run: | | |
| # set -o pipefail && xcodebuild test \ | |
| # -scheme HackerNews \ | |
| # -sdk iphonesimulator \ | |
| # -destination 'platform=iOS Simulator,name=iPad Air 11-inch (M3)' \ | |
| # -only-testing:HackerNewsTests/HackerNewsSnapshotTest \ | |
| # -resultBundlePath ../SnapshotResults-ipad.xcresult \ | |
| # ONLY_ACTIVE_ARCH=YES \ | |
| # TARGETED_DEVICE_FAMILY="1,2" \ | |
| # SUPPORTS_MACCATALYST=NO \ | |
| # | xcpretty | |
| - name: List generated images | |
| run: | | |
| echo "Generated snapshot images:" | |
| ls -1 snapshot-images/ | |
| echo "Total: $(ls -1 snapshot-images/ | 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_preview_snapshots |