From 4a1a15ce9695461be19c663906b44f6e4c942370 Mon Sep 17 00:00:00 2001 From: JimmyDaddy Date: Tue, 28 Nov 2023 14:23:44 +0800 Subject: [PATCH] chore: ci tests --- .github/workflows/android-ci.yml | 146 ++++++++++++++++++ .github/workflows/build-apk.yml | 53 ------- .github/workflows/ci.yml | 48 ------ .github/workflows/ios-ci.yml | 111 +++++++++++++ example/android/build.gradle | 5 + ios/RCTImageMarker/ImageMarker.swift | 2 +- .../RCTConvert+ImageMarker.swift | 13 +- 7 files changed, 270 insertions(+), 108 deletions(-) create mode 100644 .github/workflows/android-ci.yml delete mode 100644 .github/workflows/build-apk.yml delete mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/ios-ci.yml diff --git a/.github/workflows/android-ci.yml b/.github/workflows/android-ci.yml new file mode 100644 index 00000000..ec1c9012 --- /dev/null +++ b/.github/workflows/android-ci.yml @@ -0,0 +1,146 @@ +name: Android Build and Test +on: + pull_request: + types: [opened, reopened] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# A workflow run is made up of one or more jobs that can run sequentially or in parallel +jobs: + android-build: + runs-on: ubuntu-latest + + steps: + - name: Checkout the code + uses: actions/checkout@v2 + + - name: Setup node 16 + uses: actions/setup-node@v3 + with: + node-version: '16' + + - name: Install dependencies + run: | + npm install + cd example + npm install + - uses: actions/cache@v2 + name: Cache node_modules + with: + path: example/node_modules + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-nodeModules- + + - uses: actions/cache@v2 + name: Cache outter node_modules + with: + path: node_modules + key: ${{ runner.os }}-outterNodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-outterNodeModules- + + - uses: actions/cache@v2 + name: Cache Gradle dependencies + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }} + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 11 + + - name: Build APK + run: | + npm run prepack + cd example/android + ./gradlew assembleRelease + mv app/build/outputs/apk/release/app-release.apk app-release-${{ github.sha }}.apk + ls + pwd + echo ${{ github.workspace }} + + - name: Upload APK + uses: actions/upload-artifact@v3 + with: + name: app-release-${{ github.sha }}.apk + path: example/android/app-release-${{ github.sha }}.apk + + android-test: + runs-on: macos-latest + needs: android-build + strategy: + matrix: + api-level: [24, 25, 29, 30, 31] + target: [default] + + steps: + - name: Checkout the code + uses: actions/checkout@v2 + + - name: Setup node 16 + uses: actions/setup-node@v3 + with: + node-version: '16' + + - uses: actions/cache@v2 + name: Cache node_modules + with: + path: example/node_modules + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-nodeModules- + - uses: actions/cache@v2 + name: Cache outter node_modules + with: + path: node_modules + key: ${{ runner.os }}-outterNodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-outterNodeModules- + + - uses: actions/cache@v2 + name: Cache Gradle dependencies + with: + path: | + ~/.gradle/caches + ~/.gradle/wrapper + key: ${{ runner.os }}-${{ hashFiles('**/*.gradle*') }}-${{ hashFiles('**/gradle/wrapper/gradle-wrapper.properties') }}-${{ hashFiles('**/buildSrc/**/*.kt') }} + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'zulu' + java-version: 11 + + - name: Run detekt + run: | + cd example/android + ./gradlew detektCheck + + - name: Run unit tests + run: | + cd example/android + ./gradlew test --stacktrace + + - name: Instrumentation Tests + uses: reactivecircus/android-emulator-runner@v2 + with: + api-level: ${{ matrix.api-level }} + target: ${{ matrix.target }} + arch: x86 + profile: Nexus 6 + script: | + cd example/android + ./gradlew connectedCheck --stacktrace + + - name: Upload Reports + uses: actions/upload-artifact@v2 + with: + name: Test-Reports + path: example/android/app/build/reports + if: always() diff --git a/.github/workflows/build-apk.yml b/.github/workflows/build-apk.yml deleted file mode 100644 index 9ece1d02..00000000 --- a/.github/workflows/build-apk.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Build Android APK - -on: - push: - branches: - - main - workflow_dispatch: - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup node 16 - uses: actions/setup-node@v3 - with: - node-version: '16' - - - name: Set up JDK 1.8 - uses: actions/setup-java@v3 - with: - distribution: 'temurin' - java-version: '17' - cache: 'gradle' - - - name: Setup Android SDK - uses: android-actions/setup-android@v2 - - - - name: Install dependencies - run: | - npm install - cd example - npm install - - - name: Build APK - run: | - npm run prepack - cd example/android - ./gradlew assembleRelease - mv app/build/outputs/apk/release/app-release.apk app-release-${{ github.sha }}.apk - ls - pwd - echo ${{ github.workspace }} - - - name: Upload APK - uses: actions/upload-artifact@v3 - with: - name: app-release-${{ github.sha }}.apk - path: example/android/app-release-${{ github.sha }}.apk diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index 9c5ee1fa..00000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,48 +0,0 @@ -name: CI -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup - uses: ./.github/actions/setup - - - name: Lint files - run: yarn lint - - - name: Typecheck files - run: yarn typecheck - - test: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup - uses: ./.github/actions/setup - - - name: Run unit tests - run: yarn test --maxWorkers=2 --coverage - - build: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Setup - uses: ./.github/actions/setup - - - name: Build package - run: yarn prepack diff --git a/.github/workflows/ios-ci.yml b/.github/workflows/ios-ci.yml new file mode 100644 index 00000000..2f8bb997 --- /dev/null +++ b/.github/workflows/ios-ci.yml @@ -0,0 +1,111 @@ +name: iOS Build and Test +on: + pull_request: + types: [opened, reopened] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + ios-install-dep: + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + bundler-cache: true + - name: Setup node 16 + uses: actions/setup-node@v3 + with: + node-version: '16' + - name: Install dependencies + run: | + npm install + cd example + npm install + - uses: actions/cache@v2 + name: Cache node_modules + with: + path: example/node_modules + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-nodeModules- + - uses: actions/cache@v2 + name: Cache outter node_modules + with: + path: node_modules + key: ${{ runner.os }}-outterNodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-outterNodeModules- + + ios-build-test: + runs-on: macos-latest + needs: ios-install-dep + strategy: + matrix: + cocoapods: ['1.10.1', '1.11.0', '1.14.3'] + steps: + - uses: actions/checkout@v2 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.7 + bundler-cache: true + - name: Install Cocoapods + run: gem install cocoapods -v ${{ matrix.cocoapods }} + - name: Setup node 16 + uses: actions/setup-node@v3 + with: + node-version: '16' + + - uses: actions/cache@v2 + name: Cache node_modules + with: + path: example/node_modules + key: ${{ runner.os }}-nodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-nodeModules- + - uses: actions/cache@v2 + name: Cache outter node_modules + with: + path: node_modules + key: ${{ runner.os }}-outterNodeModules-${{ hashFiles('package-lock.json') }}-${{ hashFiles('package.json') }} + restore-keys: | + ${{ runner.os }}-outterNodeModules- + + - name: CocoaPod Install + run: | + cd example/ios + pod install + + - name: Cache Pods + id: cache-pods + uses: actions/cache@v2 + env: + cache-name: cache-pods-${{ matrix.cocoapods }} + with: + path: example/ios/Pods + key: ${{ runner.os }}-pods-${{ env.cache-name }}-${{ hashFiles('**/Podfile.lock') }} + restore-keys: | + ${{ runner.os }}-pods-${{ env.cache-name }}- + + - name: Install Pods + if: steps.cache-pods.outputs.cache-hit != 'true' + run: | + cd example/ios + pod cache clean --all + pod install + + - name: Install xcpretty + run: gem install xcpretty + + - name: Build + run: | + cd example/ios + xcodebuild -workspace ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -configuration Release -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' | xcpretty + - name: Test + run: | + cd example/ios + xcodebuild -workspace ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' test | xcpretty \ No newline at end of file diff --git a/example/android/build.gradle b/example/android/build.gradle index a95a9994..957cf0f0 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -13,6 +13,11 @@ buildscript { repositories { google() mavenCentral() + jcenter() + maven { url 'https://dl.google.com/dl/android/maven2' } + maven { url "https://repository.jboss.org/maven2" } + maven { url 'https://maven.google.com' } + maven { url 'https://maven.fabric.io/public' } } dependencies { classpath('com.android.tools.build:gradle:7.4.2') diff --git a/ios/RCTImageMarker/ImageMarker.swift b/ios/RCTImageMarker/ImageMarker.swift index 26f152f8..2605aac4 100644 --- a/ios/RCTImageMarker/ImageMarker.swift +++ b/ios/RCTImageMarker/ImageMarker.swift @@ -25,7 +25,7 @@ public final class ImageMarker: NSObject, RCTBridgeModule { let images = try await withThrowingTaskGroup(of: (Int, UIImage).self) { group in for (index, img) in imageOptions.enumerated() { group.addTask { - try await withUnsafeThrowingContinuation { continuation in + try await withUnsafeThrowingContinuation { continuation -> Void in if Utils.isBase64(img.uri) { if let image = UIImage.transBase64(img.uri) { continuation.resume(returning: (index, image)) diff --git a/ios/RCTImageMarker/RCTConvert+ImageMarker.swift b/ios/RCTImageMarker/RCTConvert+ImageMarker.swift index 47952805..d2360c7b 100644 --- a/ios/RCTImageMarker/RCTConvert+ImageMarker.swift +++ b/ios/RCTImageMarker/RCTConvert+ImageMarker.swift @@ -9,33 +9,34 @@ import Foundation import UIKit import CoreFoundation import React +import CoreGraphics extension RCTConvert { static func CGSize(_ json: Any, offset: Int) -> CGSize { let arr = self.nsArray(json) if arr!.count < offset + 2 { NSLog("Too few elements in array (expected at least %zd): %@", 2 + offset, arr!) - return CoreFoundation.CGSize.zero + return CoreGraphics.CGSize.zero } - return CoreFoundation.CGSize(width: self.cgFloat(arr![offset]), height: self.cgFloat(arr![offset + 1])) + return CoreGraphics.CGSize(width: self.cgFloat(arr![offset]), height: self.cgFloat(arr![offset + 1])) } static func CGPoint(_ json: Any, offset: Int) -> CGPoint { let arr = self.nsArray(json) if arr!.count < offset + 2 { NSLog("Too few elements in array (expected at least %zd): %@", 2 + offset, arr!) - return CoreFoundation.CGPoint.zero + return CoreGraphics.CGPoint.zero } - return CoreFoundation.CGPoint(x: self.cgFloat(arr?[offset]), y: self.cgFloat(arr![offset + 1])) + return CoreGraphics.CGPoint(x: self.cgFloat(arr?[offset]), y: self.cgFloat(arr![offset + 1])) } static func CGRect(_ json: Any, offset: Int) -> CGRect { let arr = self.nsArray(json) if arr!.count < offset + 4 { NSLog("Too few elements in array (expected at least %zd): %@", 4 + offset, arr!) - return CoreFoundation.CGRect.zero + return CoreGraphics.CGRect.zero } - return CoreFoundation.CGRect(x: self.cgFloat(arr![offset]), y: self.cgFloat(arr![offset + 1]), width: self.cgFloat(arr![offset + 2]), height: self.cgFloat(arr![offset + 3])) + return CoreGraphics.CGRect(x: self.cgFloat(arr![offset]), y: self.cgFloat(arr![offset + 1]), width: self.cgFloat(arr![offset + 2]), height: self.cgFloat(arr![offset + 3])) } static func CGColor(_ json: Any, offset: Int) -> CGColor? {