|
| 1 | +# Ensures certain packages work on simulators |
| 2 | +name: Test Simulators/Emulators |
| 3 | +on: |
| 4 | + pull_request: # triggered for any PR updates (including new pushes to PR branch) |
| 5 | + |
| 6 | +jobs: |
| 7 | + check-changes: |
| 8 | + name: Check for relevant changes |
| 9 | + runs-on: ubuntu-latest |
| 10 | + outputs: |
| 11 | + should_run: ${{ steps.check.outputs.should_run }} |
| 12 | + steps: |
| 13 | + - uses: actions/checkout@v4 |
| 14 | + with: |
| 15 | + fetch-depth: 0 |
| 16 | + - name: Check for changes |
| 17 | + id: check |
| 18 | + run: | |
| 19 | + git fetch origin ${{ github.base_ref }} |
| 20 | + if git diff --quiet origin/${{ github.base_ref }} -- packages/common packages/powersync-op-sqlite; then |
| 21 | + echo "should_run=false" >> $GITHUB_OUTPUT |
| 22 | + else |
| 23 | + echo "should_run=true" >> $GITHUB_OUTPUT |
| 24 | + fi |
| 25 | +
|
| 26 | + test-android: |
| 27 | + name: Test Android |
| 28 | + needs: check-changes |
| 29 | + if: ${{ needs.check-changes.outputs.should_run == 'true' }} |
| 30 | + runs-on: ubuntu-xl |
| 31 | + env: |
| 32 | + AVD_NAME: ubuntu-avd-x86_64-31 |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + persist-credentials: false |
| 37 | + |
| 38 | + - name: Enable KVM group perms |
| 39 | + run: | |
| 40 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 41 | + sudo udevadm control --reload-rules |
| 42 | + sudo udevadm trigger --name-match=kvm |
| 43 | +
|
| 44 | + - name: Setup Gradle |
| 45 | + uses: gradle/actions/setup-gradle@v4 |
| 46 | + |
| 47 | + - name: AVD Cache |
| 48 | + uses: actions/cache@v3 |
| 49 | + id: avd-cache |
| 50 | + with: |
| 51 | + path: | |
| 52 | + ~/.android/avd/* |
| 53 | + ~/.android/adb* |
| 54 | + key: avd-31 |
| 55 | + |
| 56 | + - name: Set up JDK 17 |
| 57 | + uses: actions/setup-java@v3 |
| 58 | + with: |
| 59 | + java-version: 17 |
| 60 | + distribution: 'adopt' |
| 61 | + cache: 'gradle' |
| 62 | + |
| 63 | + - name: Setup NodeJS |
| 64 | + uses: actions/setup-node@v4 |
| 65 | + with: |
| 66 | + node-version-file: '.nvmrc' |
| 67 | + |
| 68 | + - uses: pnpm/action-setup@v2 |
| 69 | + name: Install pnpm |
| 70 | + with: |
| 71 | + version: 9 |
| 72 | + run_install: false |
| 73 | + |
| 74 | + - name: Get pnpm store directory |
| 75 | + shell: bash |
| 76 | + run: | |
| 77 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 78 | +
|
| 79 | + - uses: actions/cache@v3 |
| 80 | + name: Setup pnpm cache |
| 81 | + with: |
| 82 | + path: ${{ env.STORE_PATH }} |
| 83 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }} |
| 84 | + restore-keys: | |
| 85 | + ${{ runner.os }}-pnpm-store- |
| 86 | +
|
| 87 | + - name: Install dependencies |
| 88 | + run: pnpm install |
| 89 | + |
| 90 | + - name: Build |
| 91 | + run: pnpm build:packages |
| 92 | + |
| 93 | + - name: Setup Detox build framework cache |
| 94 | + working-directory: ./tools/powersynctests |
| 95 | + run: | |
| 96 | + pnpx detox clean-framework-cache && pnpx detox build-framework-cache |
| 97 | +
|
| 98 | + - name: Initialize Android Folder |
| 99 | + run: mkdir -p ~/.android/avd |
| 100 | + |
| 101 | + - name: create AVD and generate snapshot for caching |
| 102 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 103 | + uses: reactivecircus/[email protected] |
| 104 | + with: |
| 105 | + api-level: 31 |
| 106 | + force-avd-creation: false |
| 107 | + target: google_apis |
| 108 | + arch: x86_64 |
| 109 | + disable-animations: false |
| 110 | + avd-name: $AVD_NAME |
| 111 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 112 | + script: echo "Generated AVD snapshot for caching." |
| 113 | + |
| 114 | + - name: Android Emulator Build |
| 115 | + working-directory: ./tools/powersynctests |
| 116 | + run: pnpx detox build --configuration android.emu.release |
| 117 | + |
| 118 | + - name: Run connected Android tests |
| 119 | + uses: ReactiveCircus/[email protected] |
| 120 | + with: |
| 121 | + api-level: 31 |
| 122 | + target: google_apis |
| 123 | + arch: x86_64 |
| 124 | + avd-name: $AVD_NAME |
| 125 | + script: cd tools/powersynctests && pnpx detox test --configuration android.emu.release --headless |
| 126 | + force-avd-creation: false |
| 127 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 128 | + disable-animations: true |
| 129 | + |
| 130 | + test-ios: |
| 131 | + name: Test iOS |
| 132 | + needs: check-changes |
| 133 | + if: ${{ needs.check-changes.outputs.should_run == 'true' }} |
| 134 | + runs-on: macOS-15 |
| 135 | + |
| 136 | + steps: |
| 137 | + - uses: actions/checkout@v4 |
| 138 | + with: |
| 139 | + persist-credentials: false |
| 140 | + |
| 141 | + - name: CocoaPods Cache |
| 142 | + uses: actions/cache@v3 |
| 143 | + id: cocoapods-cache |
| 144 | + with: |
| 145 | + path: | |
| 146 | + tools/powersynctests/ios/Pods/* |
| 147 | + key: ${{ runner.os }}-${{ hashFiles('tools/powersynctests/ios/Podfile.lock') }} |
| 148 | + |
| 149 | + - name: Cache Xcode Derived Data |
| 150 | + uses: actions/cache@v3 |
| 151 | + with: |
| 152 | + path: | |
| 153 | + tools/powersynctests/ios/build/* |
| 154 | + key: xcode-derived-${{ runner.os }}-${{ hashFiles('tools/powersynctests/ios/Podfile.lock') }} |
| 155 | + restore-keys: | |
| 156 | + xcode-derived-${{ runner.os }}- |
| 157 | +
|
| 158 | + - name: Setup NodeJS |
| 159 | + uses: actions/setup-node@v4 |
| 160 | + with: |
| 161 | + node-version-file: '.nvmrc' |
| 162 | + |
| 163 | + - uses: pnpm/action-setup@v2 |
| 164 | + name: Install pnpm |
| 165 | + with: |
| 166 | + version: 9 |
| 167 | + run_install: false |
| 168 | + |
| 169 | + - name: Get pnpm store directory |
| 170 | + shell: bash |
| 171 | + run: | |
| 172 | + echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV |
| 173 | +
|
| 174 | + - uses: actions/cache@v3 |
| 175 | + name: Setup pnpm cache |
| 176 | + with: |
| 177 | + path: ${{ env.STORE_PATH }} |
| 178 | + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('pnpm-lock.yaml') }} |
| 179 | + restore-keys: | |
| 180 | + ${{ runner.os }}-pnpm-store- |
| 181 | +
|
| 182 | + - name: Install dependencies |
| 183 | + run: pnpm install |
| 184 | + |
| 185 | + - name: Build |
| 186 | + run: pnpm build:packages |
| 187 | + |
| 188 | + - name: Install Detox dependencies |
| 189 | + run: | |
| 190 | + brew tap wix/brew |
| 191 | + brew install applesimutils |
| 192 | + npm install -g detox-cli |
| 193 | + detox clean-framework-cache && detox build-framework-cache |
| 194 | +
|
| 195 | + - name: Install CocoaPods dependencies |
| 196 | + working-directory: tools/powersynctests/ios |
| 197 | + run: pod install |
| 198 | + |
| 199 | + - name: iOS Simulator Build |
| 200 | + working-directory: ./tools/powersynctests |
| 201 | + run: pnpx detox build --configuration ios.sim.release |
| 202 | + |
| 203 | + - name: iOS Simulator Test |
| 204 | + working-directory: ./tools/powersynctests |
| 205 | + run: pnpx detox test --configuration ios.sim.release --cleanup |
0 commit comments