|
| 1 | +name: Record Snapshots |
| 2 | + |
| 3 | +# Temporary: re-records the snapshot references touched by this branch and pushes |
| 4 | +# them back. Delete before merging. |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: write |
| 8 | + |
| 9 | +on: |
| 10 | + push: |
| 11 | + branches: |
| 12 | + - bgoncal/health-sensors-remove-labs-badge |
| 13 | + |
| 14 | +env: |
| 15 | + DEVELOPER_DIR: /Applications/Xcode_27.0.app/Contents/Developer |
| 16 | + FASTLANE_SKIP_UPDATE_CHECK: true |
| 17 | + HOMEBREW_NO_INSTALL_CLEANUP: TRUE |
| 18 | + BUNDLE_PATH: vendor/bundle |
| 19 | + |
| 20 | +concurrency: |
| 21 | + group: record-snapshots-${{ github.ref }} |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + record: |
| 26 | + runs-on: xcode-27 |
| 27 | + timeout-minutes: 90 |
| 28 | + steps: |
| 29 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 30 | + with: |
| 31 | + ref: ${{ github.ref_name }} |
| 32 | + |
| 33 | + - uses: ruby/setup-ruby@14594264cd68ce8a2345dd349bc3d138a4ef85c8 # v1.327.0 |
| 34 | + with: |
| 35 | + ruby-version: .ruby-version |
| 36 | + |
| 37 | + - uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0 |
| 38 | + name: "Restore: DerivedData" |
| 39 | + with: |
| 40 | + path: ~/Library/Developer/Xcode/DerivedData |
| 41 | + key: >- |
| 42 | + ${{ format('{0}-deriveddata-{1}-{2}', |
| 43 | + runner.os, |
| 44 | + env.DEVELOPER_DIR, |
| 45 | + hashFiles('Package.resolved')) }} |
| 46 | + restore-keys: >- |
| 47 | + ${{ format('{0}-deriveddata-{1}-', |
| 48 | + runner.os, |
| 49 | + env.DEVELOPER_DIR) }} |
| 50 | +
|
| 51 | + - name: Resolve Swift packages |
| 52 | + run: >- |
| 53 | + xcodebuild -resolvePackageDependencies |
| 54 | + -project HomeAssistant.xcodeproj |
| 55 | + -scheme Tests-Unit |
| 56 | +
|
| 57 | + # `SNAPSHOT_TESTING_RECORD` is read from the test process environment, so it has to |
| 58 | + # reach the simulator through the scheme rather than the runner's shell. |
| 59 | + - name: Record failing snapshots through the scheme |
| 60 | + run: | |
| 61 | + python3 - <<'PY' |
| 62 | + import re |
| 63 | +
|
| 64 | + path = 'HomeAssistant.xcodeproj/xcshareddata/xcschemes/Tests-Unit.xcscheme' |
| 65 | + scheme = open(path).read() |
| 66 | + scheme = scheme.replace('shouldUseLaunchSchemeArgsEnv = "YES"', 'shouldUseLaunchSchemeArgsEnv = "NO"', 1) |
| 67 | + variables = ( |
| 68 | + ' <EnvironmentVariables>\n' |
| 69 | + ' <EnvironmentVariable\n' |
| 70 | + ' key = "SNAPSHOT_TESTING_RECORD"\n' |
| 71 | + ' value = "failed"\n' |
| 72 | + ' isEnabled = "YES">\n' |
| 73 | + ' </EnvironmentVariable>\n' |
| 74 | + ' </EnvironmentVariables>\n' |
| 75 | + ) |
| 76 | + scheme = scheme.replace(' </TestAction>', variables + ' </TestAction>', 1) |
| 77 | + open(path, 'w').write(scheme) |
| 78 | + PY |
| 79 | +
|
| 80 | + - name: Run snapshot tests |
| 81 | + continue-on-error: true |
| 82 | + run: >- |
| 83 | + xcodebuild test |
| 84 | + -project HomeAssistant.xcodeproj |
| 85 | + -scheme Tests-Unit |
| 86 | + -destination 'platform=iOS Simulator,name=iPhone 17,OS=latest' |
| 87 | + -only-testing:Tests-App/SensorListViewTests |
| 88 | + COMPILER_INDEX_STORE_ENABLE=NO |
| 89 | +
|
| 90 | + - name: Push re-recorded references |
| 91 | + run: | |
| 92 | + git checkout -- HomeAssistant.xcodeproj/xcshareddata/xcschemes/Tests-Unit.xcscheme |
| 93 | + git add -- 'Tests/App/Settings/__Snapshots__/SensorListView.test' |
| 94 | + if git diff --cached --quiet; then |
| 95 | + echo "No snapshot changed" |
| 96 | + exit 0 |
| 97 | + fi |
| 98 | + git config user.name "github-actions[bot]" |
| 99 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 100 | + git commit -m "Update snapshot references" |
| 101 | + git push origin HEAD:${{ github.ref_name }} |
0 commit comments