Skip to content

Commit

Permalink
ci: native gh action status check
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyDaddy committed Nov 29, 2023
1 parent bdd50c6 commit 8c0c3de
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 4 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/build-apk.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build Android APK

on:
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
- name: Upload APK
uses: actions/upload-artifact@v3
with:
name: app-release-${{ github.sha }}.apk
path: example/android/app-release-${{ github.sha }}.apk
21 changes: 17 additions & 4 deletions .github/workflows/native-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Native Build and Test
name: Build and Test
on:
pull_request:
types: [opened, synchronize, reopened]
Expand All @@ -10,10 +10,10 @@ on:
- 'assets/**'
- 'package.json'
- 'react-native-image-marker.podspec'

workflow_dispatch:

jobs:

install-dep:
runs-on: macos-latest
name: Install dependencies
Expand Down Expand Up @@ -122,6 +122,7 @@ jobs:
android-test:
runs-on: macos-latest
needs: android-build
name: Android Test
strategy:
matrix:
api-level: [24, 25, 29, 30, 31]
Expand Down Expand Up @@ -178,7 +179,7 @@ jobs:
cd example/android && ./gradlew connectedCheck --stacktrace
- name: Upload Reports
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v3
with:
name: Test-Reports
path: ${{ github.workspace }}/example/android/app/build/reports
Expand All @@ -187,6 +188,7 @@ jobs:
ios-build-test:
runs-on: macos-latest
needs: install-dep
name: iOS Build and Test
strategy:
matrix:
cocoapods: ['1.10.1', '1.11.0', '1.14.3']
Expand Down Expand Up @@ -240,4 +242,15 @@ jobs:
- name: Test
run: |
cd example/ios
xcodebuild -workspace ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' test | xcpretty
xcodebuild -workspace ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' test | xcpretty
native-ci-complete:
name: Complete CI
needs: [android-build, android-test, ios-build-test]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Check all job status
if: >-
${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') || contains(needs.*.result, 'skipped') }}
run: exit 1
3 changes: 3 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0"
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
testImplementation "org.mockito:mockito-core:3.+"
}

if (isNewArchitectureEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.jimmydaddy.imagemarker.base

import android.graphics.RectF
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.ReadableMapKeySetIterator
import org.junit.Assert
import org.junit.Test
import org.mockito.Mockito

class CornerRadiusTest {

@Test
fun testRadii() {
// 创建一个 mock 的 ReadableMap
val mockMap = Mockito.mock(ReadableMap::class.java)
val mockMapTopLeft = Mockito.mock(ReadableMap::class.java)

val mockIterator = Mockito.mock(ReadableMapKeySetIterator::class.java)

// 设置 mock 对象的行为
Mockito.`when`(mockMap.keySetIterator()).thenReturn(mockIterator)
Mockito.`when`(mockIterator.hasNextKey()).thenReturn(true, false)
Mockito.`when`(mockIterator.nextKey()).thenReturn("topLeft")
Mockito.`when`(mockMap.getMap("topLeft")).thenReturn(mockMapTopLeft)

// 创建一个 CornerRadius 对象
val cornerRadius = CornerRadius(mockMap)

// 测试 radii 方法
val rect = RectF(0f, 0f, 100f, 100f)
val radii = cornerRadius.radii(rect)

// 验证结果
Assert.assertEquals(8, radii.size)
}
}

3 changes: 3 additions & 0 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ dependencies {
} else {
implementation jscFlavor
}
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.imagemarkerexample

import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import org.junit.Assert
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class MainActivityTest {
@Test
fun test() {
onView(withText("background image format:")).check(matches(isDisplayed()))
onView(withText("topLeft")).perform(click()).check(matches(isDisplayed()))
}

@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
Assert.assertEquals("com.imagemarkerexample", appContext.packageName)
}
}

0 comments on commit 8c0c3de

Please sign in to comment.