Refactored all CD pipelines to generate APKs and app bundles based on the relevant git revision.

* The date is extracted from the specified git revision and set in the `KIWIX_ANDROID_RELEASE_DATE` environment variable, and the version code is generated for that date.
* This feature has been added to the Release section in the README file.
This commit is contained in:
MohitMaliFtechiz 2025-01-04 12:24:26 +05:30
parent ce830093f9
commit 66f3d4d7cd
4 changed files with 34 additions and 35 deletions

View File

@ -1,13 +1,10 @@
name: Generate dummy bundle and APK name: Generate dummy bundle and APK
# This workflow will trigger when the 'dummy_bundle_and_apk' or 'dummy_bundle_and_apk_v*' tag is pushed. # This workflow will trigger when the 'dummy_bundle_and_apk' is pushed.
# In 'dummy_bundle_and_apk_v*', '*' is a dynamic date pushed in the tag.
# The date format should be YYYY-MM-DD (e.g., 2024-12-18).
on: on:
push: push:
tags: tags:
- 'dummy_bundle_and_apk' # dummy_bundle_and_apk Tag. - 'dummy_bundle_and_apk' # dummy_bundle_and_apk Tag.
- 'dummy_bundle_and_apk_v*' # Trigger for generating dummy bundle and APKs with dynamic date.
jobs: jobs:
publish_dummy_bundle_and_apk: publish_dummy_bundle_and_apk:
@ -28,19 +25,17 @@ jobs:
run: | run: |
echo "$KEYSTORE" | base64 -d > kiwix-android.keystore echo "$KEYSTORE" | base64 -d > kiwix-android.keystore
- name: Retrieve date from TAG - name: Retrieve date from git revision
id: extract_date id: git_date
run: | run: |
# Check if the tag matches the pattern 'dummy_bundle_and_apk_vYYYY-MM-DD'. DATE=$(git log -1 --format=%cd --date=format:%Y-%m-%d || echo "NoCommits")
# If the date is found in the tag, it will be extracted and set as the RELEASE_DATE. if [ "$DATE" = "NoCommits" ]; then
# If no date is found or the tag does not match, an empty string will be set for RELEASE_DATE, RELEASE_DATE=""
# and Android will generate the APK and app bundle for the current date.
if [[ "${GITHUB_REF}" =~ dummy_bundle_and_apk_v([0-9]{4}-[0-9]{2}-[0-9]{2}) ]]; then
RELEASE_DATE="${BASH_REMATCH[1]}"
else else
RELEASE_DATE="" RELEASE_DATE="$DATE"
fi fi
echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV
shell: bash
- name: Generate dummy Bundle and APKs - name: Generate dummy Bundle and APKs
env: env:

View File

@ -21,6 +21,18 @@ jobs:
- name: Set tag variable - name: Set tag variable
run: echo "TAG=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV run: echo "TAG=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV
- name: Retrieve date from git revision
id: git_date
run: |
DATE=$(git log -1 --format=%cd --date=format:%Y-%m-%d || echo "NoCommits")
if [ "$DATE" = "NoCommits" ]; then
RELEASE_DATE=""
else
RELEASE_DATE="$DATE"
fi
echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV
shell: bash
- name: Retrieve secrets to files - name: Retrieve secrets to files
env: env:
KEYSTORE: ${{ secrets.keystore }} KEYSTORE: ${{ secrets.keystore }}
@ -37,6 +49,7 @@ jobs:
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
UNIVERSAL_RELEASE_APK: app/build/outputs/apk/standalone/*universal*.apk UNIVERSAL_RELEASE_APK: app/build/outputs/apk/standalone/*universal*.apk
ARCHIVE_NAME: kiwix-${{ github.event.release.tag_name }}.apk ARCHIVE_NAME: kiwix-${{ github.event.release.tag_name }}.apk
KIWIX_ANDROID_RELEASE_DATE: ${{ env.KIWIX_ANDROID_RELEASE_DATE }}
run: | run: |
./gradlew assembleStandalone ./gradlew assembleStandalone
cp ${UNIVERSAL_RELEASE_APK} ${ARCHIVE_NAME} cp ${UNIVERSAL_RELEASE_APK} ${ARCHIVE_NAME}
@ -64,6 +77,7 @@ jobs:
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
PLAYSTORE_JSON: ${{ secrets.PLAYSTORE_JSON }} PLAYSTORE_JSON: ${{ secrets.PLAYSTORE_JSON }}
KIWIX_ANDROID_RELEASE_DATE: ${{ env.KIWIX_ANDROID_RELEASE_DATE }}
run: | run: |
echo "$PLAYSTORE_JSON" > playstore.json echo "$PLAYSTORE_JSON" > playstore.json
./gradlew publishPlayStoreBundle --scan ./gradlew publishPlayStoreBundle --scan

View File

@ -1,15 +1,13 @@
name: Publish App to Play Store name: Publish App to Play Store
# This workflow is triggered on a schedule or when specific tags are pushed. # This workflow is triggered on a schedule or when specific tags are pushed.
# It runs every Monday at 12:00 UTC and also when the 'internal_testing' or 'internal_testing_v*' tag is pushed. # It runs every Monday at 12:00 UTC and also when the 'internal_testing' tag is pushed.
# In 'internal_testing_v*', '*' represents a dynamic date (e.g., 2024-12-18).
on: on:
schedule: schedule:
- cron: '0 12 * * 1' # Runs every Monday at 12:00 - cron: '0 12 * * 1' # Runs every Monday at 12:00
push: push:
tags: tags:
- 'internal_testing' # internal_testing Tag - 'internal_testing' # internal_testing Tag
- 'internal_testing_v*' # Dynamic date tag for internal testing
jobs: jobs:
publish: publish:
@ -32,19 +30,17 @@ jobs:
echo "$KEYSTORE" | base64 -d > kiwix-android.keystore echo "$KEYSTORE" | base64 -d > kiwix-android.keystore
echo "$PLAYSTORE_JSON" > playstore.json echo "$PLAYSTORE_JSON" > playstore.json
- name: Retrieve date from TAG - name: Retrieve date from git revision
id: extract_date id: git_date
run: | run: |
# Check if the tag matches the pattern 'internal_testing_vYYYY-MM-DD'. DATE=$(git log -1 --format=%cd --date=format:%Y-%m-%d || echo "NoCommits")
# If the date is found in the tag, it will be extracted and set as the RELEASE_DATE. if [ "$DATE" = "NoCommits" ]; then
# If no date is found or the tag does not match, an empty string will be set for RELEASE_DATE. RELEASE_DATE=""
# Android will use the current date for the APK generation.
if [[ "${GITHUB_REF}" =~ internal_testing_v([0-9]{4}-[0-9]{2}-[0-9]{2}) ]]; then
RELEASE_DATE="${BASH_REMATCH[1]}"
else else
RELEASE_DATE="" RELEASE_DATE="$DATE"
fi fi
echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV
shell: bash
- name: Publish bundle in internal testing on Google Play - name: Publish bundle in internal testing on Google Play
env: env:

View File

@ -101,16 +101,10 @@ are interested in our custom apps, they have their own repo
## Release ## Release
We have implemented an [automatic version code generation](https://github.com/kiwix/kiwix-android/blob/main/buildSrc/src/main/kotlin/VersionCodeGenerator.kt) system based on the current date. We have an [automatic version code generation](https://github.com/kiwix/kiwix-android/blob/main/buildSrc/src/main/kotlin/VersionCodeGenerator.kt) system based on the current date. However, you
This ensures that every new build is generated with a unique version code daily. can override this by setting the environment variable `KIWIX_ANDROID_RELEASE_DATE` to a specific
If you need to generate an APK or app bundle for a specific date, you can do so by creating and pushing one of the following tags: date in the `YYYY-MM-DD` format. This will use the provided date for the version code calculation
instead of the current date.
- `internal_testing_vYYYY-MM-DD`: If you want to publish the app bundle for a specific date on play store, create a tag e.g. `internal_testing_v2024-12-18` and push it.
This will automatically trigger the [testing_release](https://github.com/kiwix/kiwix-android/blob/main/.github/workflows/testing_release.yml) workflow, which generates the app bundle
and publishes the application to the internal testing track on the play store.
- `dummy_bundle_and_apk_vYYYY-MM-DD`: If you need a bundle or APK for specific date, create a tag e.g. `dummy_bundle_and_apk_v2024-12-18` and push it, it will automatically triggered
the [dummy_bundle_and_apk](https://github.com/kiwix/kiwix-android/blob/main/.github/workflows/dummy_bundle_and_apk.yml) workflow, which creates the app bundle and APK for specific date.
The generated files can be found in the triggered workflow.
## Libraries Used ## Libraries Used