Skip to content

Commit 8c0c3de

Browse files
committed
ci: native gh action status check
1 parent bdd50c6 commit 8c0c3de

File tree

6 files changed

+134
-4
lines changed

6 files changed

+134
-4
lines changed

.github/workflows/build-apk.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Build Android APK
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v4
13+
14+
- name: Setup node 16
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: '16'
18+
19+
- name: Set up JDK 1.8
20+
uses: actions/setup-java@v3
21+
with:
22+
distribution: 'temurin'
23+
java-version: '17'
24+
cache: 'gradle'
25+
26+
- name: Setup Android SDK
27+
uses: android-actions/setup-android@v2
28+
29+
- name: Install dependencies
30+
run: |
31+
npm install
32+
cd example
33+
npm install
34+
35+
- name: Build APK
36+
run: |
37+
npm run prepack
38+
cd example/android
39+
./gradlew assembleRelease
40+
mv app/build/outputs/apk/release/app-release.apk app-release-${{ github.sha }}.apk
41+
42+
- name: Upload APK
43+
uses: actions/upload-artifact@v3
44+
with:
45+
name: app-release-${{ github.sha }}.apk
46+
path: example/android/app-release-${{ github.sha }}.apk

.github/workflows/native-ci.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Native Build and Test
1+
name: Build and Test
22
on:
33
pull_request:
44
types: [opened, synchronize, reopened]
@@ -10,10 +10,10 @@ on:
1010
- 'assets/**'
1111
- 'package.json'
1212
- 'react-native-image-marker.podspec'
13-
1413
workflow_dispatch:
1514

1615
jobs:
16+
1717
install-dep:
1818
runs-on: macos-latest
1919
name: Install dependencies
@@ -122,6 +122,7 @@ jobs:
122122
android-test:
123123
runs-on: macos-latest
124124
needs: android-build
125+
name: Android Test
125126
strategy:
126127
matrix:
127128
api-level: [24, 25, 29, 30, 31]
@@ -178,7 +179,7 @@ jobs:
178179
cd example/android && ./gradlew connectedCheck --stacktrace
179180
180181
- name: Upload Reports
181-
uses: actions/upload-artifact@v2
182+
uses: actions/upload-artifact@v3
182183
with:
183184
name: Test-Reports
184185
path: ${{ github.workspace }}/example/android/app/build/reports
@@ -187,6 +188,7 @@ jobs:
187188
ios-build-test:
188189
runs-on: macos-latest
189190
needs: install-dep
191+
name: iOS Build and Test
190192
strategy:
191193
matrix:
192194
cocoapods: ['1.10.1', '1.11.0', '1.14.3']
@@ -240,4 +242,15 @@ jobs:
240242
- name: Test
241243
run: |
242244
cd example/ios
243-
xcodebuild -workspace ImageMarkerExample.xcworkspace -scheme ImageMarkerExample -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 12' test | xcpretty
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

android/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ dependencies {
7373
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.0"
7474
implementation "com.facebook.react:react-native:+"
7575
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
76+
testImplementation 'junit:junit:4.13.2'
77+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
78+
testImplementation "org.mockito:mockito-core:3.+"
7679
}
7780

7881
if (isNewArchitectureEnabled()) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.jimmydaddy.imagemarker.base
2+
3+
import android.graphics.RectF
4+
import com.facebook.react.bridge.ReadableMap
5+
import com.facebook.react.bridge.ReadableMapKeySetIterator
6+
import org.junit.Assert
7+
import org.junit.Test
8+
import org.mockito.Mockito
9+
10+
class CornerRadiusTest {
11+
12+
@Test
13+
fun testRadii() {
14+
// 创建一个 mock 的 ReadableMap
15+
val mockMap = Mockito.mock(ReadableMap::class.java)
16+
val mockMapTopLeft = Mockito.mock(ReadableMap::class.java)
17+
18+
val mockIterator = Mockito.mock(ReadableMapKeySetIterator::class.java)
19+
20+
// 设置 mock 对象的行为
21+
Mockito.`when`(mockMap.keySetIterator()).thenReturn(mockIterator)
22+
Mockito.`when`(mockIterator.hasNextKey()).thenReturn(true, false)
23+
Mockito.`when`(mockIterator.nextKey()).thenReturn("topLeft")
24+
Mockito.`when`(mockMap.getMap("topLeft")).thenReturn(mockMapTopLeft)
25+
26+
// 创建一个 CornerRadius 对象
27+
val cornerRadius = CornerRadius(mockMap)
28+
29+
// 测试 radii 方法
30+
val rect = RectF(0f, 0f, 100f, 100f)
31+
val radii = cornerRadius.radii(rect)
32+
33+
// 验证结果
34+
Assert.assertEquals(8, radii.size)
35+
}
36+
}
37+

example/android/app/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,9 @@ dependencies {
171171
} else {
172172
implementation jscFlavor
173173
}
174+
testImplementation 'junit:junit:4.13.2'
175+
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
176+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
174177
}
175178

176179
apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.imagemarkerexample
2+
3+
import androidx.test.espresso.Espresso.onView
4+
import androidx.test.espresso.action.ViewActions.click
5+
import androidx.test.espresso.assertion.ViewAssertions.matches
6+
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
7+
import androidx.test.espresso.matcher.ViewMatchers.withText
8+
import androidx.test.ext.junit.runners.AndroidJUnit4
9+
import androidx.test.platform.app.InstrumentationRegistry
10+
import org.junit.Assert
11+
import org.junit.Test
12+
import org.junit.runner.RunWith
13+
14+
@RunWith(AndroidJUnit4::class)
15+
class MainActivityTest {
16+
@Test
17+
fun test() {
18+
onView(withText("background image format:")).check(matches(isDisplayed()))
19+
onView(withText("topLeft")).perform(click()).check(matches(isDisplayed()))
20+
}
21+
22+
@Test
23+
fun useAppContext() {
24+
// Context of the app under test.
25+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
26+
Assert.assertEquals("com.imagemarkerexample", appContext.packageName)
27+
}
28+
}

0 commit comments

Comments
 (0)