Improving Android CI (Slack notification, coverage) (#36518)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #36052



<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Tests**
  * Automated failure notifications now include detailed error summaries
  * Added code coverage reporting and tracking for Android test suites
* Enhanced test logging and artifact collection for improved visibility
into build issues and failures

<sub>✏️ Tip: You can customize this high-level summary in your review
settings.</sub>

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Victor Lyuboslavsky 2025-12-01 16:48:32 -06:00 committed by GitHub
parent 20bac29a90
commit 1c655d4d5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 236 additions and 9 deletions

View file

@ -0,0 +1,19 @@
{
"text": "${{ env.JOB_STATUS }}\n${{ env.EVENT_URL }}",
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Android ${ANDROID_JOB_NAME}: ${{ env.JOB_STATUS }}\n${{ env.RUN_URL }}"
}
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Summary:\n```${ANDROID_FAIL_SUMMARY}```"
}
}
]
}

View file

@ -32,7 +32,7 @@ permissions:
jobs:
build:
name: Build and Test
name: Build and test
runs-on: ubuntu-latest
steps:
@ -60,20 +60,21 @@ jobs:
- name: Run formatting checks
working-directory: android
run: ./gradlew spotlessCheck --console=plain
run: ./gradlew spotlessCheck --console=plain 2>&1 | tee /tmp/gradle.log
- name: Run static analysis and build
- name: Run static analysis, build, and tests with coverage
working-directory: android
run: ./gradlew detekt build --continue --console=plain
run: ./gradlew detekt build jacocoTestReport --continue --console=plain 2>&1 | tee -a /tmp/gradle.log
- name: Upload build reports
if: failure()
if: always()
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: build-reports
path: |
android/app/build/reports/
android/app/build/test-results/
/tmp/gradle.log
- name: Upload Detekt report
if: always()
@ -95,8 +96,50 @@ jobs:
name: app-debug
path: android/app/build/outputs/apk/debug/app-debug.apk
- name: Save coverage
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: build-coverage
path: android/app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
if-no-files-found: error
- name: Generate summary of errors
if: github.event_name == 'schedule' && failure()
run: |
c1grep() { grep "$@" || test $? = 1; }
# Capture test failures (JUnit format: "ClassName > testName FAILED")
c1grep -E '.+ > .+ FAILED$' /tmp/gradle.log > /tmp/summary.txt
# Capture Kotlin compilation errors (e: file.kt: (line, col): message)
c1grep -E '^e: ' /tmp/gradle.log >> /tmp/summary.txt
# Capture task failures ("> Task :app:taskName FAILED")
c1grep -E '> Task :.+ FAILED$' /tmp/gradle.log >> /tmp/summary.txt
# Capture Spotless formatting violations
c1grep -E 'The following files had format violations:' /tmp/gradle.log >> /tmp/summary.txt
# Capture Detekt issues summary
c1grep -E 'detekt found [0-9]+ issue' /tmp/gradle.log >> /tmp/summary.txt
# Capture Gradle's "What went wrong" section
c1grep -A 3 '^\* What went wrong:' /tmp/gradle.log >> /tmp/summary.txt
ANDROID_FAIL_SUMMARY=$(head -n 5 /tmp/summary.txt | sed ':a;N;$!ba;s/\n/\\n/g')
echo "ANDROID_FAIL_SUMMARY=$ANDROID_FAIL_SUMMARY"
if [[ -z "$ANDROID_FAIL_SUMMARY" ]]; then
ANDROID_FAIL_SUMMARY="Unknown error, please check the build URL"
fi
ANDROID_JOB_NAME="build and test" ANDROID_FAIL_SUMMARY=$ANDROID_FAIL_SUMMARY envsubst < .github/workflows/config/slack_payload_android_template.json > ./payload.json
- name: Slack Notification
if: github.event_name == 'schedule' && failure()
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
with:
payload-file-path: ./payload.json
env:
JOB_STATUS: ${{ job.status }}
EVENT_URL: ${{ github.event.pull_request.html_url || github.event.head.html_url }}
RUN_URL: https://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_HELP_ENGINEERING_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
instrumented-tests:
name: Instrumented Tests
name: Instrumented tests
runs-on: ubuntu-latest
timeout-minutes: 30
@ -147,7 +190,7 @@ jobs:
target: google_apis
arch: x86_64
profile: pixel_6
script: cd android && ./gradlew connectedCheck
script: cd android && ./gradlew connectedCheck --console=plain 2>&1 | tee /tmp/gradle.log
- name: Upload instrumented test reports
if: always()
@ -157,6 +200,45 @@ jobs:
path: |
android/app/build/reports/androidTests/
android/app/build/outputs/androidTest-results/
/tmp/gradle.log
- name: Save coverage
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: instrumented-coverage
path: android/app/build/reports/coverage/androidTest/debug/connected/report.xml
if-no-files-found: error
- name: Generate summary of errors
if: github.event_name == 'schedule' && failure()
run: |
c1grep() { grep "$@" || test $? = 1; }
# Capture test failures (JUnit format: "ClassName > testName FAILED")
c1grep -E '.+ > .+ FAILED$' /tmp/gradle.log > /tmp/summary.txt
# Capture Kotlin compilation errors (e: file.kt: (line, col): message)
c1grep -E '^e: ' /tmp/gradle.log >> /tmp/summary.txt
# Capture task failures ("> Task :app:taskName FAILED")
c1grep -E '> Task :.+ FAILED$' /tmp/gradle.log >> /tmp/summary.txt
# Capture Gradle's "What went wrong" section
c1grep -A 3 '^\* What went wrong:' /tmp/gradle.log >> /tmp/summary.txt
ANDROID_FAIL_SUMMARY=$(head -n 5 /tmp/summary.txt | sed ':a;N;$!ba;s/\n/\\n/g')
echo "ANDROID_FAIL_SUMMARY=$ANDROID_FAIL_SUMMARY"
if [[ -z "$ANDROID_FAIL_SUMMARY" ]]; then
ANDROID_FAIL_SUMMARY="Unknown error, please check the build URL"
fi
ANDROID_JOB_NAME="instrumented tests" ANDROID_FAIL_SUMMARY=$ANDROID_FAIL_SUMMARY envsubst < .github/workflows/config/slack_payload_android_template.json > ./payload.json
- name: Slack Notification
if: github.event_name == 'schedule' && failure()
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
with:
payload-file-path: ./payload.json
env:
JOB_STATUS: ${{ job.status }}
EVENT_URL: ${{ github.event.pull_request.html_url || github.event.head.html_url }}
RUN_URL: https://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_HELP_ENGINEERING_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
scep-integration-test:
name: SCEP integration test
@ -217,10 +299,10 @@ jobs:
- name: Run SCEP integration tests
working-directory: android
run: |
./gradlew test -PrunIntegrationTests=true \
./gradlew test jacocoTestReport -PrunIntegrationTests=true \
-Pscep.url=http://localhost:8080/scep \
-Pscep.challenge=test-challenge-123 \
--console=plain
--console=plain 2>&1 | tee /tmp/gradle.log
- name: Upload test reports
if: always()
@ -230,3 +312,65 @@ jobs:
path: |
android/app/build/reports/tests/
android/app/build/test-results/
/tmp/gradle.log
- name: Save coverage
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: scep-coverage
path: android/app/build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml
if-no-files-found: error
- name: Generate summary of errors
if: github.event_name == 'schedule' && failure()
run: |
c1grep() { grep "$@" || test $? = 1; }
# Capture test failures (JUnit format: "ClassName > testName FAILED")
c1grep -E '.+ > .+ FAILED$' /tmp/gradle.log > /tmp/summary.txt
# Capture Kotlin compilation errors (e: file.kt: (line, col): message)
c1grep -E '^e: ' /tmp/gradle.log >> /tmp/summary.txt
# Capture task failures ("> Task :app:taskName FAILED")
c1grep -E '> Task :.+ FAILED$' /tmp/gradle.log >> /tmp/summary.txt
# Capture Gradle's "What went wrong" section
c1grep -A 3 '^\* What went wrong:' /tmp/gradle.log >> /tmp/summary.txt
ANDROID_FAIL_SUMMARY=$(head -n 5 /tmp/summary.txt | sed ':a;N;$!ba;s/\n/\\n/g')
echo "ANDROID_FAIL_SUMMARY=$ANDROID_FAIL_SUMMARY"
if [[ -z "$ANDROID_FAIL_SUMMARY" ]]; then
ANDROID_FAIL_SUMMARY="Unknown error, please check the build URL"
fi
ANDROID_JOB_NAME="SCEP integration test" ANDROID_FAIL_SUMMARY=$ANDROID_FAIL_SUMMARY envsubst < .github/workflows/config/slack_payload_android_template.json > ./payload.json
- name: Slack Notification
if: github.event_name == 'schedule' && failure()
uses: slackapi/slack-github-action@e28cf165c92ffef168d23c5c9000cffc8a25e117 # v1.24.0
with:
payload-file-path: ./payload.json
env:
JOB_STATUS: ${{ job.status }}
EVENT_URL: ${{ github.event.pull_request.html_url || github.event.head.html_url }}
RUN_URL: https://github.com/fleetdm/fleet/actions/runs/${{ github.run_id }}\n${{ github.event.pull_request.html_url || github.event.head.html_url }}
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_G_HELP_ENGINEERING_WEBHOOK_URL }}
SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK
upload-coverage:
needs: [build, instrumented-tests, scep-integration-test]
runs-on: ubuntu-latest
steps:
- name: Harden Runner
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
with:
egress-policy: audit
- name: Checkout code
uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0
- name: Download coverage artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
with:
pattern: '*-coverage'
- name: Upload to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: android

View file

@ -1,6 +1,8 @@
import java.io.FileInputStream
import java.util.Properties
// ==================== PLUGINS ====================
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
@ -8,8 +10,11 @@ plugins {
alias(libs.plugins.spotless)
alias(libs.plugins.detekt)
id("org.jetbrains.kotlin.plugin.serialization") version "2.2.20"
id("jacoco")
}
// ==================== ANDROID CONFIG ====================
android {
namespace = "com.fleetdm.agent"
compileSdk = 36
@ -84,6 +89,10 @@ android {
}
buildTypes {
debug {
enableUnitTestCoverage = true
enableAndroidTestCoverage = true
}
release {
if (keystorePropertiesFile.exists()) {
signingConfig = signingConfigs.getByName("release")
@ -128,6 +137,8 @@ android {
}
}
// ==================== KOTLIN & JAVA TOOLCHAIN ====================
kotlin {
jvmToolchain(17)
compilerOptions {
@ -141,6 +152,8 @@ java {
}
}
// ==================== CODE QUALITY ====================
detekt {
buildUponDefaultConfig = true
allRules = false
@ -152,6 +165,55 @@ tasks.named("check") {
setDependsOn(dependsOn.filterNot { it.toString().contains("detekt") })
}
// ==================== JACOCO COVERAGE ====================
jacoco {
toolVersion = "0.8.14"
}
tasks.register<JacocoReport>("jacocoTestReport") {
dependsOn("testDebugUnitTest")
reports {
xml.required.set(true)
html.required.set(true)
}
val fileFilter = listOf(
"**/R.class",
"**/R\$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*",
"android/**/*.*",
"**/compose/**/*.*",
)
val debugTree = fileTree("${layout.buildDirectory.get()}/tmp/kotlin-classes/debug") {
exclude(fileFilter)
}
val mainSrc = listOf(
"${project.projectDir}/src/main/java",
"${project.projectDir}/src/main/kotlin",
)
sourceDirectories.setFrom(files(mainSrc))
classDirectories.setFrom(files(debugTree))
executionData.setFrom(
fileTree(layout.buildDirectory) {
include(
// Unit test coverage
"outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec",
// Instrumented test coverage
"outputs/code_coverage/debugAndroidTest/connected/**/*.ec",
)
},
)
}
// ==================== SPOTLESS FORMATTING ====================
spotless {
kotlin {
target("**/*.kt")
@ -164,6 +226,8 @@ spotless {
}
}
// ==================== DEPENDENCIES ====================
dependencies {
// AndroidX and Compose
implementation(libs.androidx.core.ktx)