From 7cf32ac47a8b8f700dc40b9d88dc7b6a9aa96256 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Wed, 10 Jul 2024 23:06:43 +0200 Subject: [PATCH 1/5] chore: split big sdk/build.gradle to several applied gradle sripts --- gradle/shared/html-java-gen.gradle | 31 ++++++++++++++ gradle/shared/size-check.gradle | 28 ++++++++++++ sdk/build.gradle | 68 +++--------------------------- 3 files changed, 66 insertions(+), 61 deletions(-) create mode 100644 gradle/shared/html-java-gen.gradle create mode 100644 gradle/shared/size-check.gradle diff --git a/gradle/shared/html-java-gen.gradle b/gradle/shared/html-java-gen.gradle new file mode 100644 index 0000000..e96b8ff --- /dev/null +++ b/gradle/shared/html-java-gen.gradle @@ -0,0 +1,31 @@ +android.libraryVariants.all { variant -> + def packageName = android.namespace + def variantName = variant.name.capitalize() + def outputDir = file("${project.buildDir}/generated/source/hcaptcha/${variant.name}/${packageName.replaceAll('\\.', '/')}") + def generateTask = project.task("generate${variantName}JavaClassFromStaticHtml") { + group 'Generate' + description "Generate HTML java class" + + doFirst { + def outputJavaClass = file("$outputDir/HCaptchaHtml.java") + def template = file("$projectDir/src/main/html/HCaptchaHtml.java.tml").text + def html = file("$projectDir/src/main/html/hcaptcha.html") + .readLines() + .stream() + .map({l -> "\"${l.replaceAll('"', '\\\\"')}\\n\""}) + .collect(java.util.stream.Collectors.joining("\n${' ' * 16}+ ")) + + def engine = new groovy.text.SimpleTemplateEngine() + def src = engine.createTemplate(template).make([ + "htmlContent": html, + "packageName": packageName + ]) + + outputDir.mkdirs() + outputJavaClass.write(src.toString()) + } + } + + // preBuild.dependsOn generateTask + variant.registerJavaGeneratingTask(generateTask, outputDir) +} \ No newline at end of file diff --git a/gradle/shared/size-check.gradle b/gradle/shared/size-check.gradle new file mode 100644 index 0000000..6bf0817 --- /dev/null +++ b/gradle/shared/size-check.gradle @@ -0,0 +1,28 @@ +android.libraryVariants.all { variant -> + def variantName = variant.name.capitalize() + project.task("report${variantName}AarSize") { + group 'Help' + description "Report ${variant.name} AAR size" + dependsOn variant.packageLibraryProvider + + doFirst { + var aarPath = variant.packageLibraryProvider.get().archiveFile.get().getAsFile() + long aarSizeKb = aarPath.length() / 1024 + println("File ${aarPath} is ${aarSizeKb}Kbyte") + } + } + + project.tasks.findByName("check").dependsOn(project.task("check${variantName}AarSize") { + group 'Verification' + description "Checks ${variant.name} AAR size doesn't exceed ${project.ext}Kb" + dependsOn variant.packageLibraryProvider + + doFirst { + var aarFile = variant.packageLibraryProvider.get().archiveFile.get().getAsFile() + long aarSizeKb = aarFile.length() / 1024 + if (aarSizeKb > maxAarSizeKb) { + throw new GradleException("${aarPath} size exceeded! ${aarSizeKb}Kbyte > ${MAX_AAR_SIZE_KB}Kbyte") + } + } + }) +} \ No newline at end of file diff --git a/sdk/build.gradle b/sdk/build.gradle index f78c5dd..e5c9878 100644 --- a/sdk/build.gradle +++ b/sdk/build.gradle @@ -9,6 +9,10 @@ plugins { id "org.sonarqube" version "3.4.0.2513" } +ext { + maxAarSizeKb = 200 +} + android { compileSdk 34 namespace 'com.hcaptcha.sdk' @@ -111,64 +115,6 @@ project.afterEvaluate { } } -long MAX_AAR_SIZE_KB = 200 - -android.libraryVariants.all { variant -> - def variantName = variant.name.capitalize() - project.task("report${variantName}AarSize") { - group 'Help' - description "Report ${variant.name} AAR size" - dependsOn variant.packageLibraryProvider - - doFirst { - var aarPath = variant.packageLibraryProvider.get().archiveFile.get().getAsFile() - long aarSizeKb = aarPath.length() / 1024 - println("File ${aarPath} is ${aarSizeKb}Kbyte") - } - } - - project.tasks.findByName("check").dependsOn(project.task("check${variantName}AarSize") { - group 'Verification' - description "Checks ${variant.name} AAR size doesn't exceed ${MAX_AAR_SIZE_KB}Kb" - dependsOn variant.packageLibraryProvider - - doFirst { - var aarFile = variant.packageLibraryProvider.get().archiveFile.get().getAsFile() - long aarSizeKb = aarFile.length() / 1024 - if (aarSizeKb > MAX_AAR_SIZE_KB) { - throw new GradleException("${aarPath} size exceeded! ${aarSizeKb}Kbyte > ${MAX_AAR_SIZE_KB}Kbyte") - } - } - }) - - def packageName = "com.hcaptcha.sdk" - def outputDir = file("${project.buildDir}/generated/source/hcaptcha/${variant.name}/${packageName.replaceAll('\\.', '/')}") - def generateTask = project.task("generate${variantName}JavaClassFromStaticHtml") { - group 'Generate' - description "Generate HTML java class" - - doFirst { - def outputJavaClass = file("$outputDir/HCaptchaHtml.java") - def template = file("$projectDir/src/main/html/HCaptchaHtml.java.tml").text - def html = file("$projectDir/src/main/html/hcaptcha.html") - .readLines() - .stream() - .map({l -> "\"${l.replaceAll('"', '\\\\"')}\\n\""}) - .collect(java.util.stream.Collectors.joining("\n${' ' * 16}+ ")) - - def engine = new groovy.text.SimpleTemplateEngine() - def src = engine.createTemplate(template).make([ - "htmlContent": html, - "packageName": packageName - ]) - - outputDir.mkdirs() - outputJavaClass.write(src.toString()) - } - } - - // preBuild.dependsOn generateTask - variant.registerJavaGeneratingTask(generateTask, outputDir) -} - -apply from: "$rootProject.projectDir/gradle/shared/code-quality.gradle" \ No newline at end of file +apply from: "$rootProject.projectDir/gradle/shared/code-quality.gradle" +apply from: "$rootProject.projectDir/gradle/shared/size-check.gradle" +apply from: "$rootProject.projectDir/gradle/shared/html-java-gen.gradle" \ No newline at end of file From 8518a581dc729735336aecc7c7877f5cca186ee8 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Wed, 10 Jul 2024 23:07:15 +0200 Subject: [PATCH 2/5] chore: upload all outputs and reports on benchmark failure --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 56fb777..a472cd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -157,8 +157,8 @@ jobs: with: name: androidTest-benchmark-results path: | - benchmark/build/outputs/androidTest-results - benchmark/build/reports/androidTests + benchmark/build/outputs/ + benchmark/build/reports/ - name: Diff benchmark result id: diff-benchmark uses: ./.github/actions/android-benchmark-diff From a9b4d09e9b87e8f81856ce7062a2c9f0777603b8 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Thu, 11 Jul 2024 07:30:55 +0200 Subject: [PATCH 3/5] ci: move timeout restoriction to step level and reduce it to 20 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a472cd0..1a920a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,7 +134,6 @@ jobs: # ubuntu-latest fails with JNI ERROR (app bug): weak global reference table overflow (max=51200) # macos-latest i.e. macos-14 https://github.com/ReactiveCircus/android-emulator-runner/issues/324 runs-on: macos-13 - timeout-minutes: 30 steps: - uses: actions/checkout@v4 - uses: actions/setup-java@v4 @@ -146,6 +145,7 @@ jobs: cache-read-only: false - name: Run tests uses: ./.github/actions/android-emulator-run + timeout-minutes: 20 with: api-level: 29 fresh-avd: true From 2f8d66dc0880a8b986beaf33579702863e117c93 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Thu, 11 Jul 2024 09:14:12 +0200 Subject: [PATCH 4/5] debug: enable artifact upload for success bench --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1a920a5..31978dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,7 +152,7 @@ jobs: script: | adb uninstall com.hcaptcha.sdk.bench.test || true ./gradlew benchmark:connectedReleaseAndroidTest - - if: failure() + - if: always() uses: actions/upload-artifact@v4 with: name: androidTest-benchmark-results From 9c26af715c944b5c3249d84475ee854681656439 Mon Sep 17 00:00:00 2001 From: Alexande B Date: Thu, 11 Jul 2024 13:27:54 +0200 Subject: [PATCH 5/5] fix: ignore HCaptchaWebViewHelperTest.benchmarkWebViewLoad benchmark --- .../java/com/hcaptcha/sdk/HCaptchaWebViewHelperTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/benchmark/src/androidTest/java/com/hcaptcha/sdk/HCaptchaWebViewHelperTest.java b/benchmark/src/androidTest/java/com/hcaptcha/sdk/HCaptchaWebViewHelperTest.java index af81391..feda714 100644 --- a/benchmark/src/androidTest/java/com/hcaptcha/sdk/HCaptchaWebViewHelperTest.java +++ b/benchmark/src/androidTest/java/com/hcaptcha/sdk/HCaptchaWebViewHelperTest.java @@ -10,12 +10,14 @@ import androidx.test.ext.junit.rules.ActivityScenarioRule; import androidx.test.ext.junit.runners.AndroidJUnit4; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import java.util.concurrent.CountDownLatch; +@Ignore("https://github.com/hCaptcha/hcaptcha-android-sdk/issues/101") @RunWith(AndroidJUnit4.class) public class HCaptchaWebViewHelperTest { @Rule