|
| 1 | +name: Build and Test |
| 2 | +on: |
| 3 | + pull_request: |
| 4 | + types: [opened, synchronize, reopened] |
| 5 | + paths: |
| 6 | + - 'example/**' |
| 7 | + - 'android/**' |
| 8 | + - 'ios/**' |
| 9 | + - 'src/**' |
| 10 | + - 'assets/**' |
| 11 | + - 'package.json' |
| 12 | + - 'react-native-image-marker.podspec' |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +jobs: |
| 16 | + |
| 17 | + install-dep: |
| 18 | + runs-on: macos-latest |
| 19 | + name: Install dependencies |
| 20 | + steps: |
| 21 | + - name: Checkout the code |
| 22 | + uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - uses: actions/cache@v3 |
| 25 | + name: Cache node_modules |
| 26 | + id: cache-node-modules |
| 27 | + with: |
| 28 | + path: | |
| 29 | + node_modules |
| 30 | + example/node_modules |
| 31 | + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package.json') }}-${{ hashFiles('example/package.json') }} |
| 32 | + |
| 33 | + - name: Set up Ruby |
| 34 | + uses: ruby/setup-ruby@v1 |
| 35 | + with: |
| 36 | + ruby-version: 2.7 |
| 37 | + bundler-cache: true |
| 38 | + - name: Setup node 16 |
| 39 | + uses: actions/setup-node@v3 |
| 40 | + with: |
| 41 | + node-version: '16' |
| 42 | + |
| 43 | + - name: Install npm dependencies |
| 44 | + if: steps.cache-node-modules.outputs.cache-hit != 'true' |
| 45 | + run: | |
| 46 | + ls |
| 47 | + pwd |
| 48 | + npm install |
| 49 | + cd example |
| 50 | + ls |
| 51 | + pwd |
| 52 | + npm install |
| 53 | +
|
| 54 | + android-build: |
| 55 | + runs-on: macos-latest |
| 56 | + name: Android Build |
| 57 | + needs: install-dep |
| 58 | + steps: |
| 59 | + - name: Checkout the code |
| 60 | + uses: actions/checkout@v4 |
| 61 | + |
| 62 | + - uses: actions/cache@v3 |
| 63 | + name: Cache node_modules |
| 64 | + id: cache-node-modules |
| 65 | + with: |
| 66 | + path: | |
| 67 | + node_modules |
| 68 | + example/node_modules |
| 69 | + fail-on-cache-miss: true |
| 70 | + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package.json') }}-${{ hashFiles('example/package.json') }} |
| 71 | + |
| 72 | + - uses: actions/cache@v3 |
| 73 | + id: cache-gradle |
| 74 | + name: Cache Gradle dependencies |
| 75 | + with: |
| 76 | + path: | |
| 77 | + ~/.gradle/caches |
| 78 | + ~/.gradle/wrapper |
| 79 | + key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('android/src/**/*.kt') }} |
| 80 | + |
| 81 | + - name: Set up Ruby |
| 82 | + uses: ruby/setup-ruby@v1 |
| 83 | + with: |
| 84 | + ruby-version: 2.7 |
| 85 | + bundler-cache: true |
| 86 | + |
| 87 | + - name: Setup node 16 |
| 88 | + uses: actions/setup-node@v3 |
| 89 | + with: |
| 90 | + node-version: '16' |
| 91 | + |
| 92 | + - name: Set up JDK |
| 93 | + uses: actions/setup-java@v3 |
| 94 | + with: |
| 95 | + distribution: 'zulu' |
| 96 | + java-version: 11 |
| 97 | + |
| 98 | + - name: Install Gradle dependencies |
| 99 | + if: steps.cache-gradle.outputs.cache-hit != 'true' |
| 100 | + run: | |
| 101 | + cd example/android |
| 102 | + ./gradlew build --stacktrace |
| 103 | +
|
| 104 | + - name: Run unit tests |
| 105 | + run: | |
| 106 | + cd example/android |
| 107 | + ./gradlew test --stacktrace |
| 108 | +
|
| 109 | + - name: Build APK |
| 110 | + run: | |
| 111 | + npm run prepack |
| 112 | + cd example/android |
| 113 | + ./gradlew assembleRelease |
| 114 | + mv app/build/outputs/apk/release/app-release.apk app-release-${{ github.sha }}.apk |
| 115 | +
|
| 116 | + - name: Upload APK |
| 117 | + uses: actions/upload-artifact@v3 |
| 118 | + with: |
| 119 | + name: app-release-${{ github.sha }}.apk |
| 120 | + path: ${{ github.workspace }}/example/android/app-release-${{ github.sha }}.apk |
| 121 | + |
| 122 | + android-test: |
| 123 | + runs-on: macos-latest |
| 124 | + needs: android-build |
| 125 | + name: Android Test |
| 126 | + strategy: |
| 127 | + matrix: |
| 128 | + api-level: [24, 25, 29, 30, 31] |
| 129 | + target: [default] |
| 130 | + steps: |
| 131 | + - name: Checkout the code |
| 132 | + uses: actions/checkout@v4 |
| 133 | + |
| 134 | + - uses: actions/cache@v3 |
| 135 | + name: Cache node_modules |
| 136 | + id: cache-node-modules |
| 137 | + with: |
| 138 | + path: | |
| 139 | + node_modules |
| 140 | + example/node_modules |
| 141 | + fail-on-cache-miss: true |
| 142 | + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package.json') }}-${{ hashFiles('example/package.json') }} |
| 143 | + |
| 144 | + - uses: actions/cache@v3 |
| 145 | + name: Cache Gradle dependencies |
| 146 | + id: cache-gradle |
| 147 | + with: |
| 148 | + path: | |
| 149 | + ~/.gradle/caches |
| 150 | + ~/.gradle/wrapper |
| 151 | + fail-on-cache-miss: true |
| 152 | + key: ${{ runner.os }}-gradle-${{ hashFiles('example/android/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('android/src/**/*.kt') }} |
| 153 | + |
| 154 | + - name: Set up Ruby |
| 155 | + uses: ruby/setup-ruby@v1 |
| 156 | + with: |
| 157 | + ruby-version: 2.7 |
| 158 | + bundler-cache: true |
| 159 | + |
| 160 | + - name: Setup node 16 |
| 161 | + uses: actions/setup-node@v3 |
| 162 | + with: |
| 163 | + node-version: '16' |
| 164 | + |
| 165 | + - name: Set up JDK |
| 166 | + uses: actions/setup-java@v3 |
| 167 | + with: |
| 168 | + distribution: 'zulu' |
| 169 | + java-version: 11 |
| 170 | + |
| 171 | + - name: Instrumentation Tests |
| 172 | + uses: reactivecircus/android-emulator-runner@v2 |
| 173 | + with: |
| 174 | + api-level: ${{ matrix.api-level }} |
| 175 | + target: ${{ matrix.target }} |
| 176 | + arch: x86_64 |
| 177 | + profile: Nexus 6 |
| 178 | + script: | |
| 179 | + cd example/android && ./gradlew connectedCheck --stacktrace |
| 180 | +
|
| 181 | + - name: Upload Reports |
| 182 | + uses: actions/upload-artifact@v3 |
| 183 | + with: |
| 184 | + name: Test-Reports |
| 185 | + path: ${{ github.workspace }}/example/android/app/build/reports |
| 186 | + if: always() |
| 187 | + |
| 188 | + ios-build-test: |
| 189 | + runs-on: macos-latest |
| 190 | + needs: install-dep |
| 191 | + name: iOS Build and Test |
| 192 | + strategy: |
| 193 | + matrix: |
| 194 | + cocoapods: ['1.10.1', '1.11.0', '1.14.3'] |
| 195 | + steps: |
| 196 | + - name: Checkout the code |
| 197 | + uses: actions/checkout@v4 |
| 198 | + |
| 199 | + - uses: actions/cache@v3 |
| 200 | + name: Cache node_modules |
| 201 | + id: cache-node-modules |
| 202 | + with: |
| 203 | + path: | |
| 204 | + node_modules |
| 205 | + example/node_modules |
| 206 | + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package.json') }}-${{ hashFiles('example/package.json') }} |
| 207 | + fail-on-cache-miss: true |
| 208 | + |
| 209 | + - name: Cache Pods |
| 210 | + id: cache-pods |
| 211 | + uses: actions/cache@v3 |
| 212 | + with: |
| 213 | + path: example/ios/Pods |
| 214 | + key: ${{ runner.os }}-pods-${{ matrix.cocoapods }}-${{ hashFiles('**/Podfile.lock') }} |
| 215 | + |
| 216 | + - name: Set up Ruby |
| 217 | + uses: ruby/setup-ruby@v1 |
| 218 | + with: |
| 219 | + ruby-version: 2.7 |
| 220 | + bundler-cache: true |
| 221 | + - name: Install Cocoapods |
| 222 | + run: gem install cocoapods -v ${{ matrix.cocoapods }} |
| 223 | + - name: Setup node 16 |
| 224 | + uses: actions/setup-node@v3 |
| 225 | + with: |
| 226 | + node-version: '16' |
| 227 | + |
| 228 | + - name: Install Pods |
| 229 | + if: steps.cache-pods.outputs.cache-hit != 'true' |
| 230 | + run: | |
| 231 | + cd example/ios |
| 232 | + pod cache clean --all |
| 233 | + pod install |
| 234 | +
|
| 235 | + - name: Install xcpretty |
| 236 | + run: gem install xcpretty |
| 237 | + |
| 238 | + - name: Build |
| 239 | + run: | |
| 240 | + cd example/ios |
| 241 | + xcodebuild -workspace ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' | xcpretty |
| 242 | + - name: Test |
| 243 | + run: | |
| 244 | + cd example/ios |
| 245 | + xcodebuild -workspace ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' test | xcpretty |
| 246 | +
|
| 247 | + native-ci-complete: |
| 248 | + name: Complete CI |
| 249 | + needs: [android-build, android-test, ios-build-test] |
| 250 | + if: ${{ always() }} |
| 251 | + runs-on: ubuntu-latest |
| 252 | + steps: |
| 253 | + - name: Check all job status |
| 254 | + if: >- |
| 255 | + ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }} |
| 256 | + run: exit 1 |
0 commit comments