From 882784d0ea2e92160bec89a701d874ea556eb0f2 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 17 Jul 2024 23:46:08 +0530 Subject: [PATCH 1/5] Fixed: Automatically publish to PlayStore for internal testing team. * Implemented a method to automatically generate a unique version code by calculating the number of days from the reference date (July 17, 2024) to the current date and adding this value to the base version code (231101) from the last release. * Added a workflow that automatically generates the bundle and uploads it to internal testing every Monday at 12:00. This workflow will also trigger under the `internal_testing` tag. * Since we are implementing this, it is necessary to directly release the bundle to internal testing instead of placing it in draft (to eliminate manual steps), so we have refactored our code accordingly. --- .github/workflows/testing_release.yml | 38 ++++++++++++++++++ app/build.gradle.kts | 24 ++--------- .../src/main/kotlin/GenerateVersionCode.kt | 40 +++++++++++++++++++ core/build.gradle.kts | 20 +--------- 4 files changed, 82 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/testing_release.yml create mode 100644 buildSrc/src/main/kotlin/GenerateVersionCode.kt diff --git a/.github/workflows/testing_release.yml b/.github/workflows/testing_release.yml new file mode 100644 index 000000000..faca767f7 --- /dev/null +++ b/.github/workflows/testing_release.yml @@ -0,0 +1,38 @@ +name: Publish App to Play Store + +# Trigger the workflow on a schedule (every Monday at 12:00 UTC) +on: + schedule: + - cron: '0 12 * * 1' # Runs every Monday at 12:00 + push: + tags: + - 'internal_testing' # internal_testing Tag + +jobs: + publish: + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v3 + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: temurin + + - name: Retrieve secrets to files + env: + KEYSTORE: ${{ secrets.keystore }} + PLAYSTORE_JSON: ${{ secrets.PLAYSTORE_JSON }} + run: | + echo "$KEYSTORE" | base64 -d > kiwix-android.keystore + echo "$PLAYSTORE_JSON" > playstore.json + + - name: Publish bundle in internal testing on Google Play + env: + KEY_ALIAS: ${{ secrets.KEY_ALIAS }} + KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} + KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} + run: | + ./gradlew publishPlayStoreBundle --scan diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 9d8fe2d5d..75be75443 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -10,24 +10,6 @@ apply(from = rootProject.file("jacoco.gradle")) fun generateVersionName() = "${Config.versionMajor}.${Config.versionMinor}.${Config.versionPatch}" -/* -* max version code: 21-0-0-00-00-00 -* our template : UU-D-A-ZZ-YY-XX -* where: -* X = patch version -* Y = minor version -* Z = major version (+ 20 to distinguish from previous, non semantic, versions of the app) -* A = number representing ABI split -* D = number representing density split -* U = unused -*/ - -fun generateVersionCode() = - 20 * 10000 + - Config.versionMajor * 10000 + - Config.versionMinor * 100 + - Config.versionPatch - val apkPrefix get() = System.getenv("TAG") ?: "kiwix" android { @@ -36,7 +18,7 @@ android { base.archivesName.set(apkPrefix) resValue("string", "app_name", "Kiwix") resValue("string", "app_search_string", "Search Kiwix") - versionCode = generateVersionCode() + versionCode = GenerateVersionCode.getVersionCode() versionName = generateVersionName() manifestPlaceholders["permission"] = "android.permission.MANAGE_EXTERNAL_STORAGE" } @@ -90,7 +72,7 @@ play { enabled.set(true) serviceAccountCredentials.set(file("../playstore.json")) track.set("internal") - releaseStatus.set(com.github.triplet.gradle.androidpublisher.ReleaseStatus.DRAFT) + releaseStatus.set(com.github.triplet.gradle.androidpublisher.ReleaseStatus.COMPLETED) resolutionStrategy.set(com.github.triplet.gradle.androidpublisher.ResolutionStrategy.FAIL) } @@ -103,7 +85,7 @@ task("generateVersionCodeAndName") { file.printWriter().use { it.print( "${generateVersionName()}\n" + - "7${generateVersionCode()}" + "7${GenerateVersionCode.getVersionCode()}" ) } } diff --git a/buildSrc/src/main/kotlin/GenerateVersionCode.kt b/buildSrc/src/main/kotlin/GenerateVersionCode.kt new file mode 100644 index 000000000..4e7872fb4 --- /dev/null +++ b/buildSrc/src/main/kotlin/GenerateVersionCode.kt @@ -0,0 +1,40 @@ +import java.time.LocalDate +import java.time.temporal.ChronoUnit + +/* + * Kiwix Android + * Copyright (c) 2024 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +object GenerateVersionCode { + fun getVersionCode(): Int { + // the date when the automatic version code generation started + val lastDate = LocalDate.of(2020, 7, 17) + + // Calculate the number of days between the lastDate and today's date. + // This gives us the total number of days since the last version code was set. + val daysDifference = ChronoUnit.DAYS.between(lastDate, LocalDate.now()).toInt() + + // Base version code. This is the version code of the last release uploaded to the Play Store. + // We use this as the starting point for generating new version codes automatically. + val baseVersionCode = 231101 + + // Generate and return the new version code. + // The new version code is calculated by adding the number of days since lastDate + // to the base version code. This creates a unique version code for each day. + return baseVersionCode + daysDifference + } +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index c21ee52b1..6ff5ca2ae 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -19,27 +19,9 @@ plugins.apply(KiwixConfigurationPlugin::class) apply(plugin = "io.objectbox") apply(plugin = "com.jakewharton.butterknife") -/* -* max version code: 21-0-0-00-00-00 -* our template : UU-D-A-ZZ-YY-XX -* where: -* X = patch version -* Y = minor version -* Z = major version (+ 20 to distinguish from previous, non semantic, versions of the app) -* A = number representing ABI split -* D = number representing density split -* U = unused -*/ - -fun generateVersionCode() = - 20 * 10000 + - Config.versionMajor * 10000 + - Config.versionMinor * 100 + - Config.versionPatch - android { defaultConfig { - buildConfigField("long", "VERSION_CODE", "${generateVersionCode()}") + buildConfigField("long", "VERSION_CODE", "${GenerateVersionCode.getVersionCode()}") } buildTypes { getByName("release") { From e0731197fc63e0e72a5ba5714e3ec7e203d9726c Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 17 Jul 2024 23:49:53 +0530 Subject: [PATCH 2/5] Removed the testing date from code. --- buildSrc/src/main/kotlin/GenerateVersionCode.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/kotlin/GenerateVersionCode.kt b/buildSrc/src/main/kotlin/GenerateVersionCode.kt index 4e7872fb4..7cf277771 100644 --- a/buildSrc/src/main/kotlin/GenerateVersionCode.kt +++ b/buildSrc/src/main/kotlin/GenerateVersionCode.kt @@ -22,7 +22,7 @@ import java.time.temporal.ChronoUnit object GenerateVersionCode { fun getVersionCode(): Int { // the date when the automatic version code generation started - val lastDate = LocalDate.of(2020, 7, 17) + val lastDate = LocalDate.of(2024, 7, 17) // Calculate the number of days between the lastDate and today's date. // This gives us the total number of days since the last version code was set. From 8e62954d4a3f5b6622b499d66dbcfd19bdc0faca Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 18 Jul 2024 18:23:45 +0530 Subject: [PATCH 3/5] Using latest versions of actions. * Updated the version of actions used in our workflows. --- .github/workflows/ci.yml | 2 +- .github/workflows/fdroid_nightly.yml | 4 ++-- .github/workflows/nightly.yml | 4 ++-- .github/workflows/pull_request.yml | 6 +++--- .github/workflows/release.yml | 4 ++-- .github/workflows/testing_release.yml | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7dc9cd4df..1a177223f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: java-version: 11 - name: Restore Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/caches diff --git a/.github/workflows/fdroid_nightly.yml b/.github/workflows/fdroid_nightly.yml index 99f253d1f..57db24c08 100644 --- a/.github/workflows/fdroid_nightly.yml +++ b/.github/workflows/fdroid_nightly.yml @@ -12,10 +12,10 @@ jobs: environment: nightly steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index b15de8c8c..e2d7ffbc3 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -12,12 +12,12 @@ jobs: steps: - name: checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 266ad4318..3d1faa9b4 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -13,18 +13,18 @@ jobs: continue-on-error: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 1 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin - name: Restore Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/caches diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af1b19cdf..a71972918 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,10 +10,10 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin diff --git a/.github/workflows/testing_release.yml b/.github/workflows/testing_release.yml index faca767f7..3aafcc2ba 100644 --- a/.github/workflows/testing_release.yml +++ b/.github/workflows/testing_release.yml @@ -13,10 +13,10 @@ jobs: runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin From 79add751a4edac4a700d2b50414e493a730d67c1 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 18 Jul 2024 18:27:33 +0530 Subject: [PATCH 4/5] Updated the remaining action in pull_request.yml file. --- .github/workflows/pull_request.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 3d1faa9b4..c8dbc6060 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -51,18 +51,18 @@ jobs: continue-on-error: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 1 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin - name: Restore Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/caches @@ -89,18 +89,18 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 1 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin - name: Restore Cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: | ~/.gradle/caches @@ -127,12 +127,12 @@ jobs: continue-on-error: true steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 1 - name: Set up JDK 11 - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: 11 distribution: temurin From a5284afce620f14640c6136c33dfe37f826e1191 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 18 Jul 2024 23:20:36 +0530 Subject: [PATCH 5/5] Better naming for for top level function class. * Using top-level extension function instead of object class function. --- app/build.gradle.kts | 4 +- .../src/main/kotlin/GenerateVersionCode.kt | 40 ------------------- .../src/main/kotlin/VersionCodeGenerator.kt | 38 ++++++++++++++++++ core/build.gradle.kts | 2 +- 4 files changed, 41 insertions(+), 43 deletions(-) delete mode 100644 buildSrc/src/main/kotlin/GenerateVersionCode.kt create mode 100644 buildSrc/src/main/kotlin/VersionCodeGenerator.kt diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 75be75443..b1ce3b2f2 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -18,7 +18,7 @@ android { base.archivesName.set(apkPrefix) resValue("string", "app_name", "Kiwix") resValue("string", "app_search_string", "Search Kiwix") - versionCode = GenerateVersionCode.getVersionCode() + versionCode = "".getVersionCode() versionName = generateVersionName() manifestPlaceholders["permission"] = "android.permission.MANAGE_EXTERNAL_STORAGE" } @@ -85,7 +85,7 @@ task("generateVersionCodeAndName") { file.printWriter().use { it.print( "${generateVersionName()}\n" + - "7${GenerateVersionCode.getVersionCode()}" + "7" + "".getVersionCode() ) } } diff --git a/buildSrc/src/main/kotlin/GenerateVersionCode.kt b/buildSrc/src/main/kotlin/GenerateVersionCode.kt deleted file mode 100644 index 7cf277771..000000000 --- a/buildSrc/src/main/kotlin/GenerateVersionCode.kt +++ /dev/null @@ -1,40 +0,0 @@ -import java.time.LocalDate -import java.time.temporal.ChronoUnit - -/* - * Kiwix Android - * Copyright (c) 2024 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -object GenerateVersionCode { - fun getVersionCode(): Int { - // the date when the automatic version code generation started - val lastDate = LocalDate.of(2024, 7, 17) - - // Calculate the number of days between the lastDate and today's date. - // This gives us the total number of days since the last version code was set. - val daysDifference = ChronoUnit.DAYS.between(lastDate, LocalDate.now()).toInt() - - // Base version code. This is the version code of the last release uploaded to the Play Store. - // We use this as the starting point for generating new version codes automatically. - val baseVersionCode = 231101 - - // Generate and return the new version code. - // The new version code is calculated by adding the number of days since lastDate - // to the base version code. This creates a unique version code for each day. - return baseVersionCode + daysDifference - } -} diff --git a/buildSrc/src/main/kotlin/VersionCodeGenerator.kt b/buildSrc/src/main/kotlin/VersionCodeGenerator.kt new file mode 100644 index 000000000..269b31198 --- /dev/null +++ b/buildSrc/src/main/kotlin/VersionCodeGenerator.kt @@ -0,0 +1,38 @@ +import java.time.LocalDate +import java.time.temporal.ChronoUnit + +/* + * Kiwix Android + * Copyright (c) 2024 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +fun String.getVersionCode(): Int { + // the date when the automatic version code generation started + val lastDate = LocalDate.of(2024, 7, 17) + + // Calculate the number of days between the lastDate and today's date. + // This gives us the total number of days since the last version code was set. + val daysDifference = ChronoUnit.DAYS.between(lastDate, LocalDate.now()).toInt() + + // Base version code. This is the version code of the last release uploaded to the Play Store. + // We use this as the starting point for generating new version codes automatically. + val baseVersionCode = 231101 + + // Generate and return the new version code. + // The new version code is calculated by adding the number of days since lastDate + // to the base version code. This creates a unique version code for each day. + return baseVersionCode + daysDifference +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 6ff5ca2ae..383595731 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -21,7 +21,7 @@ apply(plugin = "com.jakewharton.butterknife") android { defaultConfig { - buildConfigField("long", "VERSION_CODE", "${GenerateVersionCode.getVersionCode()}") + buildConfigField("long", "VERSION_CODE", "".getVersionCode().toString()) } buildTypes { getByName("release") {