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.
This commit is contained in:
MohitMaliFtechiz 2024-07-17 23:46:08 +05:30
parent 8c25521f43
commit 882784d0ea
4 changed files with 82 additions and 40 deletions

38
.github/workflows/testing_release.yml vendored Normal file
View File

@ -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

View File

@ -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()}"
)
}
}

View File

@ -0,0 +1,40 @@
import java.time.LocalDate
import java.time.temporal.ChronoUnit
/*
* Kiwix Android
* Copyright (c) 2024 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
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
}
}

View File

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