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") {