Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade gradle 8 and run tests against optimized sdk #125

Merged
merged 18 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 75 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
paths-ignore:
- '**.md'

env:
JAVA_VERSION: '17'

jobs:
test:
name: 'Test Unit'
Expand All @@ -21,7 +24,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
Expand All @@ -44,6 +47,9 @@ jobs:
fail-fast: false
matrix:
include:
- compile: 34
target: 34
appcompat: 1.6.1
- compile: 33
target: 33
appcompat: 1.5.1
Expand All @@ -60,7 +66,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
Expand All @@ -82,7 +88,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
Expand Down Expand Up @@ -119,14 +125,72 @@ jobs:
profile: Nexus 6
script: |
brew install parallel
parallel --retries 3 ::: "./gradlew sdk:connectedCheck"
parallel --retries 3 ::: "./gradlew test:connectedCheck"
- if: failure()
uses: actions/upload-artifact@v3
with:
name: androidTest-results
path: |
sdk/build/outputs/androidTest-results
sdk/build/reports/androidTests
test/build/outputs/androidTest-results
test/build/reports/androidTests

test-minified:
name: 'Test UI Minified'
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
api-level: [29]
target: [default]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
cache-read-only: false
- name: 'Cache AVD'
uses: actions/cache@v3
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-api-${{ matrix.api-level }}-target-${{ matrix.target }}
- name: 'Create AVD'
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: false
arch: x86_64
profile: Nexus 6
script: echo "Generated AVD snapshot for caching."
- name: 'Tests'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
target: ${{ matrix.target }}
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
force-avd-creation: false
disable-animations: true
arch: x86_64
profile: Nexus 6
script: |
brew install parallel
parallel --retries 3 ::: "./gradlew test:connectedCheck -P testingMinimizedBuild=true -P android.enableR8.fullMode=false"
- if: failure()
uses: actions/upload-artifact@v3
with:
name: androidTest-minified-results
path: |
test/build/outputs/androidTest-results
test/build/reports/androidTests

test-benchmark:
name: 'Test Benchmark'
Expand All @@ -140,7 +204,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
Expand Down Expand Up @@ -174,13 +238,13 @@ jobs:
disable-animations: true
arch: x86_64
profile: Nexus 6
script: ./gradlew bench:connectedReleaseAndroidTest
script: ./gradlew benchmark:connectedReleaseAndroidTest
- name: Diff benchmark result
id: diff-benchmark
uses: ./.github/actions/android-benchmark-diff
with:
reference: benchmark/data/ci-benchmarkData.json
compare-with: benchmark/build/outputs/connected_android_test_additional_output/releaseAndroidTest/connected/test(AVD) - 10/com.hcaptcha.sdk.bench.test-benchmarkData.json
compare-with: benchmark/build/outputs/connected_android_test_additional_output/releaseAndroidTest/connected/test(AVD) - 10/com_hcaptcha_sdk_bench_test-benchmarkData.json
- name: Log diff benchmark reuslts
run: echo "${{ steps.diff-benchmark.outputs.markdown-table }}"
- uses: peter-evans/find-comment@v2
Expand Down Expand Up @@ -215,7 +279,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
Expand All @@ -241,7 +305,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
java-version: '11'
java-version: ${{ env.JAVA_VERSION }}
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
Expand Down
18 changes: 16 additions & 2 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,22 @@
There is automated testing for every `push` command through github actions (see `.github/workflows/ci.yml`).

You can manually test before pushing by running both unit tests and instrumented tests:
* ```gradlew test```
* ```gradlew connectedDebugAndroidTest```
* `./gradlew sdk:test`
* `./gradlew test:connectedAndroidTest`
* `./gradlew test:connectedAndroidTest -P testingMinimizedBuild=true -P android.enableR8.fullMode=false`

## Manual testing

+ {normal,invisible,compact} -> verify -> success -> mark used
+ {normal,invisible,compact} -> verify -> success -> token timeout

+ {normal,invisible,compact} -> verify -> touch outside -> challenge closed
+ {normal,invisible,compact} -> verify -> back button -> challenge closed

+ {normal,invisible,compact} -> verify -> rotate device (recreate activity) -> hcaptcha gone, no callbacks fired
+ {normal,invisible,compact} -> verify -> send app to background -> open app from history again -> hcaptcha is displayed

+ {hide dialog} -> verify -> token obtained -> mark used

# Publishing

Expand Down
29 changes: 22 additions & 7 deletions benchmark/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

android {
compileSdkVersion 33
compileSdk 34
namespace 'com.hcaptcha.sdk.bench'

compileOptions {
Expand All @@ -14,7 +14,7 @@ android {

defaultConfig {
minSdkVersion 16
targetSdkVersion 33
targetSdkVersion 34

testInstrumentationRunner 'androidx.benchmark.junit4.AndroidBenchmarkRunner'
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "DEBUGGABLE,EMULATOR,LOW-BATTERY,UNLOCKED"
Expand All @@ -36,14 +36,29 @@ android {
}

dependencies {
androidTestImplementation 'androidx.test:runner:1.5.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.4'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.benchmark:benchmark-junit4:1.1.1'
androidTestImplementation 'androidx.benchmark:benchmark-junit4:1.2.0'

implementation project(path: ':sdk')
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat:1.6.1'
}

// Workaround for: java.lang.ClassNotFoundException: com.android.tools.lint.client.api.Vendor
lint.enabled = false
lint.enabled = false

tasks.register('pullBenchmarkData', Exec) {
def packageName = android.namespace + ".test"

commandLine java.nio.file.Paths.get(android.sdkDirectory.absolutePath, "platform-tools", "adb"),
"pull",
"/storage/emulated/0/Android/media/" \
+ "${packageName}/additional_test_output/" \
+ "${packageName.replace('.', '_')}-benchmarkData.json",
"${projectDir}/build/outputs/"

doFirst {
println "pullBenchmarkData: ${commandLine.join(' ')}"
}
}
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ buildscript {
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:7.2.2'
classpath 'androidx.benchmark:benchmark-gradle-plugin:1.1.1'
classpath 'com.android.tools.build:gradle:8.1.3'
classpath 'androidx.benchmark:benchmark-gradle-plugin:1.2.0'
classpath 'com.slack.keeper:keeper:0.15.0'
}
}

Expand Down
6 changes: 2 additions & 4 deletions example-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ def prop(name, fallback) {
}

android {
compileSdkVersion intProp("exampleCompileSdkVersion", 32)
buildToolsVersion "30.0.3"
compileSdk intProp("exampleCompileSdkVersion", 34)
namespace 'com.hcaptcha.example'

defaultConfig {
applicationId "com.hcaptcha.example"
minSdkVersion 16
targetSdkVersion intProp("exampleTargetSdkVersion", 32)
targetSdkVersion intProp("exampleTargetSdkVersion", 34)
versionCode 1
versionName "0.0.1"

Expand Down
2 changes: 1 addition & 1 deletion example-app/src/main/java/com/hcaptcha/example/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class App extends Application {
public void onCreate() {
super.onCreate();

if (BuildConfig.DEBUG) {
if (com.hcaptcha.sdk.BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
new StrictMode.ThreadPolicy.Builder()
.detectAll()
Expand Down
2 changes: 0 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,5 @@ org.gradle.jvmargs=-Xmx2048m
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0
android.disableAutomaticComponentCreation=true
# To test more aggressive optimizations
android.enableR8.fullMode=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading