Merge pull request #3948 from kiwix/Fixes#3942

Fixed: Automatically publish to PlayStore for internal testing team.
This commit is contained in:
Kelson 2024-07-19 21:50:38 +02:00 committed by GitHub
commit d068166d0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 98 additions and 58 deletions

View File

@ -28,7 +28,7 @@ jobs:
java-version: 11 java-version: 11
- name: Restore Cache - name: Restore Cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches

View File

@ -12,10 +12,10 @@ jobs:
environment: nightly environment: nightly
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v4
with: with:
java-version: 11 java-version: 11
distribution: temurin distribution: temurin

View File

@ -12,12 +12,12 @@ jobs:
steps: steps:
- name: checkout - name: checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
with: with:
fetch-depth: 1 fetch-depth: 1
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v4
with: with:
java-version: 11 java-version: 11
distribution: temurin distribution: temurin

View File

@ -13,18 +13,18 @@ jobs:
continue-on-error: true continue-on-error: true
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
with: with:
fetch-depth: 1 fetch-depth: 1
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v4
with: with:
java-version: 11 java-version: 11
distribution: temurin distribution: temurin
- name: Restore Cache - name: Restore Cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches
@ -51,18 +51,18 @@ jobs:
continue-on-error: true continue-on-error: true
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
with: with:
fetch-depth: 1 fetch-depth: 1
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v4
with: with:
java-version: 11 java-version: 11
distribution: temurin distribution: temurin
- name: Restore Cache - name: Restore Cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches
@ -89,18 +89,18 @@ jobs:
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v3 uses: actions/checkout@v4
with: with:
fetch-depth: 1 fetch-depth: 1
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v4
with: with:
java-version: 11 java-version: 11
distribution: temurin distribution: temurin
- name: Restore Cache - name: Restore Cache
uses: actions/cache@v3 uses: actions/cache@v4
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches
@ -127,12 +127,12 @@ jobs:
continue-on-error: true continue-on-error: true
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
with: with:
fetch-depth: 1 fetch-depth: 1
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v4
with: with:
java-version: 11 java-version: 11
distribution: temurin distribution: temurin

View File

@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v4
- name: Set up JDK 11 - name: Set up JDK 11
uses: actions/setup-java@v3 uses: actions/setup-java@v4
with: with:
java-version: 11 java-version: 11
distribution: temurin distribution: temurin

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@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
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}" 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" val apkPrefix get() = System.getenv("TAG") ?: "kiwix"
android { android {
@ -36,7 +18,7 @@ android {
base.archivesName.set(apkPrefix) base.archivesName.set(apkPrefix)
resValue("string", "app_name", "Kiwix") resValue("string", "app_name", "Kiwix")
resValue("string", "app_search_string", "Search Kiwix") resValue("string", "app_search_string", "Search Kiwix")
versionCode = generateVersionCode() versionCode = "".getVersionCode()
versionName = generateVersionName() versionName = generateVersionName()
manifestPlaceholders["permission"] = "android.permission.MANAGE_EXTERNAL_STORAGE" manifestPlaceholders["permission"] = "android.permission.MANAGE_EXTERNAL_STORAGE"
} }
@ -90,7 +72,7 @@ play {
enabled.set(true) enabled.set(true)
serviceAccountCredentials.set(file("../playstore.json")) serviceAccountCredentials.set(file("../playstore.json"))
track.set("internal") 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) resolutionStrategy.set(com.github.triplet.gradle.androidpublisher.ResolutionStrategy.FAIL)
} }
@ -103,7 +85,7 @@ task("generateVersionCodeAndName") {
file.printWriter().use { file.printWriter().use {
it.print( it.print(
"${generateVersionName()}\n" + "${generateVersionName()}\n" +
"7${generateVersionCode()}" "7" + "".getVersionCode()
) )
} }
} }

View File

@ -0,0 +1,38 @@
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/>.
*
*/
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
}

View File

@ -19,27 +19,9 @@ plugins.apply(KiwixConfigurationPlugin::class)
apply(plugin = "io.objectbox") apply(plugin = "io.objectbox")
apply(plugin = "com.jakewharton.butterknife") 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 { android {
defaultConfig { defaultConfig {
buildConfigField("long", "VERSION_CODE", "${generateVersionCode()}") buildConfigField("long", "VERSION_CODE", "".getVersionCode().toString())
} }
buildTypes { buildTypes {
getByName("release") { getByName("release") {