From 25f8a2f46b79432f8dacf05dc6bf754e6259f4a6 Mon Sep 17 00:00:00 2001 From: Vitor Hugo Schwaab Date: Wed, 22 May 2024 22:38:11 +0200 Subject: [PATCH] chore(ci): add android and compose lint [WPB-9287] (#3021) --- .github/workflows/code-analysis.yml | 66 + .github/workflows/codestyle.yml | 33 - .github/workflows/gradle-run-unit-tests.yml | 9 +- app/build.gradle.kts | 5 + app/lint-baseline.xml | 8155 +++++++++++++++++ app/src/main/res/values-it/strings.xml | 2 +- benchmark/lint-baseline.xml | 4 + .../gradle/KotlinAndroidConfiguration.kt | 33 +- core/ui-common/lint-baseline.xml | 345 + features/sketch/lint-baseline.xml | 26 + gradle/libs.versions.toml | 8 +- 11 files changed, 8635 insertions(+), 51 deletions(-) create mode 100644 .github/workflows/code-analysis.yml delete mode 100644 .github/workflows/codestyle.yml create mode 100644 app/lint-baseline.xml create mode 100644 benchmark/lint-baseline.xml create mode 100644 core/ui-common/lint-baseline.xml create mode 100644 features/sketch/lint-baseline.xml diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml new file mode 100644 index 00000000000..a643e7c20b8 --- /dev/null +++ b/.github/workflows/code-analysis.yml @@ -0,0 +1,66 @@ +name: "Code Analysis" + +on: [workflow_call] + +permissions: + contents: read + +jobs: + lint: + runs-on: buildjet-4vcpu-ubuntu-2204 + # Add a bit more Metaspace size as it tends to fail on GH runner when running linter, + # Reduce a bit the memory allocation pool, as the 8GB set in gradle.properties is too much for CI + # AboutLibraries seems to go crazy when running lint checks. So we explicitly don't run it. + env: + GRADLE_OPTS: '-Dorg.gradle.jvmargs="-XX:MaxMetaspaceSize=1g -Xmx2G"' + DISABLE_ABOUT_LIBRARIES: TRUE + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive # Needed in order to fetch Kalium sources for building + fetch-depth: 0 + - name: Set up JDK 17 + uses: buildjet/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@5188e9b5527a0a094cee21e2fe9a8ca44b4629af + + - name: Run Linter + run: | + ./gradlew lint + - name: Cleanup Gradle Cache + # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. + # Restoring these files from a GitHub Actions cache might cause problems for future builds. + run: | + rm -f ~/.gradle/caches/modules-2/modules-2.lock + rm -f ~/.gradle/caches/modules-2/gc.properties + + style: + runs-on: buildjet-2vcpu-ubuntu-2204 + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: recursive # Needed in order to fetch Kalium sources for building + fetch-depth: 0 + - name: Set up JDK 17 + uses: buildjet/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: gradle + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@216d1ad2b3710bf005dc39237337b9673fd8fcd5 + - name: Run Detekt + run: | + ./gradlew detektAll + - name: Cleanup Gradle Cache + # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. + # Restoring these files from a GitHub Actions cache might cause problems for future builds. + run: | + rm -f ~/.gradle/caches/modules-2/modules-2.lock + rm -f ~/.gradle/caches/modules-2/gc.properties diff --git a/.github/workflows/codestyle.yml b/.github/workflows/codestyle.yml deleted file mode 100644 index a6189bc7c77..00000000000 --- a/.github/workflows/codestyle.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: "Check Codestyle" - -on: [workflow_call] - -permissions: - contents: read - -jobs: - static-code-analysis: - runs-on: buildjet-2vcpu-ubuntu-2204 - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: recursive # Needed in order to fetch Kalium sources for building - fetch-depth: 0 - - name: Set up JDK 17 - uses: buildjet/setup-java@v4 - with: - java-version: '17' - distribution: 'temurin' - cache: gradle - - name: Validate Gradle wrapper - uses: gradle/wrapper-validation-action@216d1ad2b3710bf005dc39237337b9673fd8fcd5 - - name: Run Detekt - run: | - ./gradlew detektAll - - name: Cleanup Gradle Cache - # Remove some files from the Gradle cache, so they aren't cached by GitHub Actions. - # Restoring these files from a GitHub Actions cache might cause problems for future builds. - run: | - rm -f ~/.gradle/caches/modules-2/modules-2.lock - rm -f ~/.gradle/caches/modules-2/gc.properties diff --git a/.github/workflows/gradle-run-unit-tests.yml b/.github/workflows/gradle-run-unit-tests.yml index 935d59349b2..d3814fcc93e 100644 --- a/.github/workflows/gradle-run-unit-tests.yml +++ b/.github/workflows/gradle-run-unit-tests.yml @@ -11,10 +11,9 @@ concurrency: cancel-in-progress: true jobs: - detekt: - uses: ./.github/workflows/codestyle.yml + code-analysis: + uses: ./.github/workflows/code-analysis.yml unit-tests: - needs: [detekt] runs-on: buildjet-8vcpu-ubuntu-2204 steps: @@ -100,14 +99,14 @@ jobs: build-beta: if: ${{ github.event_name == 'pull_request' }} - needs: [unit-tests] + needs: [unit-tests, code-analysis] uses: ./.github/workflows/build-app.yml with: flavour: "beta-debug" build-dev: if: ${{ github.event_name == 'pull_request' }} - needs: [unit-tests] + needs: [unit-tests, code-analysis] uses: ./.github/workflows/build-app.yml with: flavour: "dev-debug" diff --git a/app/build.gradle.kts b/app/build.gradle.kts index e3f131194d9..0514dcb80a2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -84,6 +84,11 @@ android { } } +aboutLibraries { + val isAboutLibrariesDisabled = System.getenv("DISABLE_ABOUT_LIBRARIES")?.equals("true", true) ?: false + registerAndroidTasks = !isAboutLibrariesDisabled +} + dependencies { implementation("com.wire.kalium:kalium-logic") implementation("com.wire.kalium:kalium-util") diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml new file mode 100644 index 00000000000..a0bb5184a8a --- /dev/null +++ b/app/lint-baseline.xml @@ -0,0 +1,8155 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 87d7764b31e..4e99155cfbd 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -1304,7 +1304,7 @@ registrato. Sei pregato di riprovare. Wire necessita dell\'autorizzazione a utilizzare il tuo microfono per registrare i messaggi vocali. Consenti l\'accesso nelle impostazioni del tuo dispositivo. Impostazioni Registrazione arrestata - Le dimensioni dei file per i messaggi vocali sono limitate a %1$s MB. + Le dimensioni dei file per i messaggi vocali sono limitate a %1$d MB. Non puoi registrare un messaggio vocale durante una chiamata. Qualcosa è andato storto provando a registrare il messaggio audio. Ti preghiamo di riprovare. Non adesso diff --git a/benchmark/lint-baseline.xml b/benchmark/lint-baseline.xml new file mode 100644 index 00000000000..ddc2d3f41cc --- /dev/null +++ b/benchmark/lint-baseline.xml @@ -0,0 +1,4 @@ + + + + diff --git a/build-logic/plugins/src/main/kotlin/com/wire/android/gradle/KotlinAndroidConfiguration.kt b/build-logic/plugins/src/main/kotlin/com/wire/android/gradle/KotlinAndroidConfiguration.kt index d74c8c9ab64..a5fb410e615 100644 --- a/build-logic/plugins/src/main/kotlin/com/wire/android/gradle/KotlinAndroidConfiguration.kt +++ b/build-logic/plugins/src/main/kotlin/com/wire/android/gradle/KotlinAndroidConfiguration.kt @@ -28,6 +28,7 @@ import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import versionCatalog +import findLibrary internal fun Project.configureKotlinAndroid( commonExtension: CommonExtension<*, *, *, *, *>, // Add another `*` when upgrading AGP to 8.3 @@ -50,17 +51,7 @@ internal fun Project.configureKotlinAndroid( dependencies { add("coreLibraryDesugaring", versionCatalog.findLibrary("android.desugarJdkLibs").get()) } - - // Lint Configuration - lint { - quiet = true - abortOnError = false - ignoreWarnings = true - disable.add("InvalidPackage") // Some libraries have issues with this. - disable.add("OldTargetApi") // Lint gives this warning related to SDK Beta. - disable.add("IconDensities") // For testing purpose. This is safe to remove. - disable.add("IconMissingDensityFolder") // For testing purpose. This is safe to remove. - } + configureLint(project) } /** @@ -85,6 +76,26 @@ private fun Project.configureKotlin() { } } +private fun CommonExtension<*, *, *, *, *>.configureLint(project: Project) { + lint { + quiet = false + abortOnError = true + ignoreWarnings = true + disable.add("InvalidPackage") // Some libraries have issues with this. + disable.add("OldTargetApi") // Lint gives this warning related to SDK Beta. + disable.add("IconDensities") // For testing purpose. This is safe to remove. + disable.add("IconMissingDensityFolder") // For testing purpose. This is safe to remove. + disable.add("ComposePreviewPublic") // Needed for screenshot testing. + baseline = project.file("lint-baseline.xml") + } + + with(project) { + dependencies { + add("lintChecks", findLibrary("lint-compose")) + } + } +} + // Add another `*` when upgrading AGP to 8.3 internal fun CommonExtension<*, *, *, *, *>.configureAndroidKotlinTests() { defaultConfig { diff --git a/core/ui-common/lint-baseline.xml b/core/ui-common/lint-baseline.xml new file mode 100644 index 00000000000..1b8bad39529 --- /dev/null +++ b/core/ui-common/lint-baseline.xml @@ -0,0 +1,345 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/features/sketch/lint-baseline.xml b/features/sketch/lint-baseline.xml new file mode 100644 index 00000000000..a1e24f3a217 --- /dev/null +++ b/features/sketch/lint-baseline.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9d44af11d22..3f2dd503b88 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -70,11 +70,14 @@ rss-parser = "6.0.7" # Logging dataDog = "1.19.3" +# Lint +lint-compose = "1.3.1" + #OAuth openIdAppAuth = "0.11.1" # Other Tools -aboutLibraries = "11.1.3" +aboutLibraries = "11.1.4" leakCanary = "2.14" ksp = "1.9.23-1.0.20" @@ -216,6 +219,9 @@ coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" } # RSS Feed Loading rss-parser = { module = "com.prof18.rssparser:rssparser", version.ref = "rss-parser" } +# Lint +lint-compose = { module = "com.slack.lint.compose:compose-lint-checks", version.ref = "lint-compose" } + # Logging dataDog-core = { module = "com.datadoghq:dd-sdk-android", version.ref = "dataDog" } dataDog-compose = { module = "com.datadoghq:dd-sdk-android-compose", version.ref = "dataDog" }