From d9a65af9f6ec1c1533bdbaa5776b170c5373ecd6 Mon Sep 17 00:00:00 2001 From: Ronaldo Pace Date: Tue, 5 Nov 2024 12:40:46 +0100 Subject: [PATCH] Add github action --- .github/workflows/on_pull_request.yml | 32 +++++++ .gitignore | 4 +- build.gradle.kts | 116 ++++++++++++----------- buildSrc/settings.gradle.kts | 2 +- buildSrc/src/main/kotlin/Android.kt | 4 +- gradle/libs.versions.toml | 74 ++++++++------- gradle/wrapper/gradle-wrapper.properties | 2 +- services/network/build.gradle.kts | 7 ++ settings.gradle.kts | 16 +++- 9 files changed, 162 insertions(+), 95 deletions(-) create mode 100644 .github/workflows/on_pull_request.yml diff --git a/.github/workflows/on_pull_request.yml b/.github/workflows/on_pull_request.yml new file mode 100644 index 0000000..9f94de3 --- /dev/null +++ b/.github/workflows/on_pull_request.yml @@ -0,0 +1,32 @@ +name: Checks and Tests + +on: + workflow_dispatch: + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + gradleTask: [assembleDebug testDebugUnitTest, lintDebug, ktlintCheck] + steps: + - name: Git checkout + uses: actions/checkout@v4 + + - name: Setup Java JDK + uses: actions/setup-java@v4.5.0 + with: + java-version: 21 + distribution: temurin + cache: 'gradle' + + - name: Check Gradle + uses: gradle/actions/wrapper-validation@v3 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build with Gradle + run: ./gradlew ${{ matrix.gradleTask }} \ No newline at end of file diff --git a/.gitignore b/.gitignore index 16dcd12..72b6204 100644 --- a/.gitignore +++ b/.gitignore @@ -30,4 +30,6 @@ render.experimental.xml google-services.json # Android Profiling -*.hprof \ No newline at end of file +*.hprof + +versions.properties \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index f33bcff..622e20f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,7 @@ import kotlin.random.Random // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { // Using gradle conventions instead + alias(libs.plugins.ktLint) } // here are some very simple scripts that used to transform the list extracted from wikipedia, @@ -14,82 +15,83 @@ plugins { val names by tasks.registering { group = "pets" doLast { - val c = file("plain.txt") - .readLines() - .joinToString("\n") { - it - .substringAfter("The ") - .substringBefore('(') - .substringBefore(' ') - .substringBefore(',') - .trim(' ', ',') - - } + val c = + file("plain.txt") + .readLines() + .joinToString("\n") { + it + .substringAfter("The ") + .substringBefore('(') + .substringBefore(' ') + .substringBefore(',') + .trim(' ', ',') + } file("names.txt").writeText(c) } } - val description by tasks.registering { group = "pets" doLast { - val c = file("plain.txt") - .readLines() - .joinToString("\n") { - it.substringAfter(")") - .trim(' ', ',', '.') - } + val c = + file("plain.txt") + .readLines() + .joinToString("\n") { + it.substringAfter(")") + .trim(' ', ',', '.') + } file("description.txt").writeText(c) } } val petTemplate = """{"id":"ID","name":"NAME","price":"PRICE","description":"DESC","type":"TYPE","dateOfBirth":"BDAY","priority":PRIORITY}""" -val petTypes = listOf( - "DOG", - "DOG", - "DOG", - "DOG", - "DOG", - "DOG", - "CAT", - "CAT", - "CAT", - "TURTLE", - "TURTLE", - "TURTLE", - "PARROT" -) +val petTypes = + listOf( + "DOG", + "DOG", + "DOG", + "DOG", + "DOG", + "DOG", + "CAT", + "CAT", + "CAT", + "TURTLE", + "TURTLE", + "TURTLE", + "PARROT", + ) val pets by tasks.registering { group = "pets" doLast { val names = file("names.txt").readLines() val desc = file("description.txt").readLines() - val data = buildList(names.size) { - repeat(names.size) { index -> - val name = names[index] - val description = desc[index] - - val bDay = - (LocalDateTime.now() - Duration.ofDays(10L + Random.nextLong(3000))) - .toInstant(ZoneOffset.UTC) - .toString() + val data = + buildList(names.size) { + repeat(names.size) { index -> + val name = names[index] + val description = desc[index] - val prio = Random.nextFloat() - add( - prio to petTemplate - .replace("ID", UUID.randomUUID().toString()) - .replace("NAME", name) - .replace("PRICE", (1200 + Random.nextInt(8000)).toString()) - .replace("DESC", description) - .replace("TYPE", petTypes.random()) - .replace("BDAY", bDay) - .replace("PRIORITY", prio.toString()) + val bDay = + (LocalDateTime.now() - Duration.ofDays(10L + Random.nextLong(3000))) + .toInstant(ZoneOffset.UTC) + .toString() - ) - - } - }.sortedBy { it.first }.joinToString("\n") { it.second } + val prio = Random.nextFloat() + add( + prio to + petTemplate + .replace("ID", UUID.randomUUID().toString()) + .replace("NAME", name) + .replace("PRICE", (1200 + Random.nextInt(8000)).toString()) + .replace("DESC", description) + .replace("TYPE", petTypes.random()) + .replace("BDAY", bDay) + .replace("PRIORITY", prio.toString()), + ) + } + }.sortedBy { it.first }.joinToString("\n") { it.second } file("jsons.txt").writeText(data) } -} \ No newline at end of file +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 3739443..62991c1 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,4 +1,4 @@ -rootProject.name="buildSrc" +rootProject.name = "buildSrc" dependencyResolutionManagement { versionCatalogs { diff --git a/buildSrc/src/main/kotlin/Android.kt b/buildSrc/src/main/kotlin/Android.kt index bef4e9a..f601a25 100644 --- a/buildSrc/src/main/kotlin/Android.kt +++ b/buildSrc/src/main/kotlin/Android.kt @@ -1,5 +1,5 @@ internal object Android { - const val COMPILE_SDK = 34 - const val TARGET_SDK = 34 + const val COMPILE_SDK = 35 + const val TARGET_SDK = 35 const val MIN_SDK = 27 } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3c53b82..09a761d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,27 +1,4 @@ -[versions] -agp = "8.6.1" -kotlin = "2.0.20" -coreKtx = "1.15.0" -junit = "4.13.2" -junitVersion = "1.2.1" -espressoCore = "3.6.1" -lifecycleRuntimeKtx = "2.8.7" -activityCompose = "1.9.3" -composeBom = "2024.10.01" -appcompat = "1.7.0" -material = "1.12.0" -viewModel = "2.8.7" -koin = "3.5.0" -coroutines = "1.8.1" -ktor = "2.3.12" -datetime = "0.6.1" -json = "1.7.2" -ksp = "2.0.20-1.0.24" -room = "2.6.1" -truth = "1.4.4" -runner = "1.6.2" -turbine = "1.1.0" -timber = "5.0.1" +## Generated by $ ./gradlew refreshVersionsCatalog [bundles] @@ -40,7 +17,48 @@ feature = [ "koin-compose", ] +[plugins] + +android-application = { id = "com.android.application", version.ref = "agp" } +android-library = { id = "com.android.library", version.ref = "agp" } +kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } +ktLint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktLint" } + +[versions] + +agp = "8.7.2" +kotlin = "2.0.21" +coreKtx = "1.15.0" +junit = "4.13.2" +junitVersion = "1.2.1" +espressoCore = "3.6.1" +lifecycleRuntimeKtx = "2.8.7" +activityCompose = "1.9.3" +composeBom = "2024.10.01" +appcompat = "1.7.0" +material = "1.12.0" +viewModel = "2.8.7" +koin = "3.5.6" +##⬆ = "4.0.0" +coroutines = "1.9.0" +ktor = "2.3.12" +##⬆ = "3.0.0" +##⬆ = "3.0.1" +datetime = "0.6.1" +json = "1.7.3" +ksp = "2.0.21-1.0.26" +room = "2.6.1" +truth = "1.4.4" +runner = "1.6.2" +turbine = "1.2.0" +timber = "5.0.1" +ktLint = "12.1.1" + [libraries] + androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } junit = { group = "junit", name = "junit", version.ref = "junit" } androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } @@ -88,11 +106,3 @@ convention-compose = { group = "org.jetbrains.kotlin", name = "compose-compiler- truth = { module = "com.google.truth:truth", version.ref = "truth" } turbine = { module = "app.cash.turbine:turbine", version.ref = "turbine" } - -[plugins] -android-application = { id = "com.android.application", version.ref = "agp" } -android-library = { id = "com.android.library", version.ref = "agp" } -kotlin = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } -compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } -kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } -ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e20e76a..e832ad1 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Wed Sep 04 17:27:35 CEST 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/services/network/build.gradle.kts b/services/network/build.gradle.kts index 8e9efed..3168bc1 100644 --- a/services/network/build.gradle.kts +++ b/services/network/build.gradle.kts @@ -3,6 +3,13 @@ plugins { alias(libs.plugins.kotlin.serialization) } +android { + lint { + disable += "UnsafeOptInUsageWarning" + disable += "UnsafeOptInUsageError" + } +} + dependencies { implementation(libs.ktor.client) diff --git a/settings.gradle.kts b/settings.gradle.kts index 96514f5..bc57ae8 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,6 +11,20 @@ pluginManagement { gradlePluginPortal() } } + +plugins { + // See https://jmfayard.github.io/refreshVersions + id("de.fayard.refreshVersions") version "0.60.5" +} + +refreshVersions { + rejectVersionIf { + @Suppress("UnstableApiUsage") + candidate.stabilityLevel != de.fayard.refreshVersions.core.StabilityLevel.Stable + } +} + +@Suppress("UnstableApiUsage") dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -31,4 +45,4 @@ include(":repositories:pets:") include(":repositories:cart:") include(":services:network:") -include(":services:database:") \ No newline at end of file +include(":services:database:")