Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to generate APK for a specified date. #4156

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Jan 2, 2025

Fixes #4120

  • To generate the APK for a specific date, set the KIWIX_ANDROID_RELEASE_DATE environment variable in the format YYYY-MM-DD. The APK will be generated for the specified date. If the variable is not set, the APK will be generated for the current date.
  • 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. See https://github.com/kiwix/kiwix-android/actions/runs/12608455860/job/35140926560.
  • Documented this new feature in the README.md file.
  • The testing_release job is skipped, if the application is being uploaded with the same version as the previously uploaded one, and Play Store gives the error for same version code. This prevents the CD pipeline from failing due to this error, while for all other errors, the workflow will fail as expected.

Copy link
Collaborator

@kelson42 kelson42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here my request for changes:

  • Rename the variable KIWIX_ANDROID_RELEASE_DATE
  • lastDate should be clearly identified as a constant in variable type and naming (should be LAST_DATE)
  • Document properly the feature in the README in a new section "Release".
  • Modify the CI and the CD so we use this feature

Copy link

codecov bot commented Jan 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.03%. Comparing base (359a1fc) to head (0ec90f0).

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4156      +/-   ##
============================================
- Coverage     57.09%   57.03%   -0.06%     
+ Complexity     1525     1522       -3     
============================================
  Files           313      313              
  Lines         13399    13399              
  Branches       1662     1662              
============================================
- Hits           7650     7642       -8     
- Misses         4597     4601       +4     
- Partials       1152     1156       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 14 to 70
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin

- name: Preparing signing material
env:
KEYSTORE: ${{ secrets.keystore }}
run: |
echo "$KEYSTORE" | base64 -d > kiwix-android.keystore

- name: Retrieve date from TAG
id: extract_date
run: |
# Check if the tag matches the pattern 'dummy_bundle_and_apk_vYYYY-MM-DD'.
# If the date is found in the tag, it will be extracted and set as the RELEASE_DATE.
# If no date is found or the tag does not match, an empty string will be set for 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
RELEASE_DATE=""
fi
echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV

- name: Generate dummy Bundle and APKs
env:
KEY_ALIAS: ${{ secrets.KEY_ALIAS }}
KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }}
KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }}
KIWIX_ANDROID_RELEASE_DATE: ${{ env.KIWIX_ANDROID_RELEASE_DATE }}
run: |
./gradlew bundlePlayStore assembleRelease --scan


- name: Get Bundle and APKs name and path
id: get-bundle-and-apk-paths
run: |
BUNDLE_PATH="app/build/outputs/bundle/playStore/kiwix-playStore.aab"
BUNDLE_NAME="PlayStoreDummyBundle.aab"
echo "bundle_path=$BUNDLE_PATH" >> $GITHUB_ENV
echo "bundle_name=$BUNDLE_NAME" >> $GITHUB_ENV
APK_DIR="app/build/outputs/apk/release/"
echo "apk_dir=$APK_DIR" >> $GITHUB_ENV

- name: Upload Bundle as an artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.bundle_name }}
path: ${{ env.bundle_path }}

- name: Upload All Release APKs as artifacts
uses: actions/upload-artifact@v4
with:
name: ReleaseApks
path: ${{ env.apk_dir }}*.apk

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions Job or Workflow does not set permissions
@MohitMaliFtechiz
Copy link
Collaborator Author

Here my request for changes:
Rename the variable KIWIX_ANDROID_RELEASE_DATE
lastDate should be clearly identified as a constant in variable type and naming (should be LAST_DATE)
Document properly the feature in the README in a new section "Release".
Modify the CI and the CD so we use this feature

@kelson42 I have made the changes as you requested. If anything we can improve in this, please let me know.

Copy link
Collaborator

@kelson42 kelson42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wy LAST_DATE is not a const?

@MohitMaliFtechiz
Copy link
Collaborator Author

Wy LAST_DATE is not a const?

@kelson42 we can only declare primitives and strings in const, but here the type was LocalDate that's why LAST_DATE was not const. But you have a valid point so I have changed the logic and made the LAST_DATE const d06985e.

@kelson42
Copy link
Collaborator

kelson42 commented Jan 3, 2025

  • Refactored testing_release CD workflow to generate and publish the application on the Play Store based on a specified date, using a new tag format internal_testing_v* where * is replaced by the date in YYYY-MM-DD, which is extracted and set as an environment variable to generate the app bundle for that date, defaulting to the current date if no date is provided, and uploading the generated app bundle to the Play Store.
  • We refactored our dummy_bundle.yml workflow to generate the dummy bundle and APKs based on a specified date, using a new tag format dummy_bundle_and_apk_v*, where * is replaced by the date in YYYY_MM_DD. This date is extracted and set as an environment variable to generate the app bundle and APK for that date, defaulting to the current date if no date is provided. See https://github.com/kiwix/kiwix-android/actions/runs/12594061109

Why do you need that? I expect you to just modify the workflows to extract the date from the concerned git revision? Something you have forgotten to do on the release.yml too... looks like.

* To generate the APK for a specific date, set the "RELEASE_DATE" environment variable in the format `YYYY-MM-DD`. The APK will be generated for the specified date. If the variable is not set, the APK will be generated for the current date.
* Made `LAST_DATE` and `BASE_VERSION_CODE` constants, as these values are crucial for our app and should not be changed. We have marked them as constants and added comments to ensure they remain unchanged.
…application on the Play Store based on a specified date, using a new tag format `internal_testing_v*` where `*` is replaced by the date, which is extracted and set as an environment variable to generate the app bundle for that date, defaulting to the current date if no date is provided, and uploading the generated app bundle to the Play Store.
…undle and APKs based on a specified date, using a new tag format `dummy_bundle_and_apk_v*`, where `*` is replaced by the date in `YYYY_MM_DD`. This date is extracted and set as an environment variable to generate the app bundle and APK for that date, defaulting to the current date if no date is provided.

* Now, our `dummy_bundle.yml` will generate both the app bundle and APKs, so if we need the APK for a specified date, we can easily retrieve it.
* Added comments in both workflows to understand the flow of the workflows.
@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Jan 4, 2025

Why do you need that?

@kelson42 We need this to generate the APK or app bundle for the given date if we want to generate the APK or app bundle for a specific day. Like here we are not able to rebuild the APK for the same date while uploading it on the IzzyOnDroid. Since it can not generate the APK with the same version code if some other commits are added(on the next day).

I expect you to just modify the workflows to extract the date from the concerned git revision?

Okay, but it could lead to issues with our testing_release workflow. Here's why:

  • The testing_release workflow runs every Monday, even if no new commits are added. In such cases, it would try to build and upload the APK for the same date as the last published version. This would fail due to a duplicate version code.
  • However, the release workflow will work as intended since it only triggers when a new release is created.

Due to these reasons, I have made the changes like this. The current approach provides an additional feature, but I can remove it if you think it is not necessary. For the rest(extracting the date from git revision), we can add this with the current feature so that when these tags are not pushed it extracts the date from the concerned git revision generates the apk, and uploads it on the playStore(For testing_release, and dummy_bundle workflows). For the release workflow, I am making the changes.

Edited
I have thought more about this, and I believe uploading a new APK with the same codebase to the Play Store does not make sense since it lacks any new fixes. If the testing_release workflow fails due to the same version code issue, it should not be a significant problem. For generating the APK with the same version code, @IzzySoft handles it on their side by retrieving the date and providing it via an environment variable. For the dummy bundle and APK, our git revision feature will work fine since we cannot upload an APK to the Play Store with a previous version code. Therefore, we can proceed with the git revision feature.

… 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.
@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft January 4, 2025 06:54
@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review January 4, 2025 07:04
@kelson42
Copy link
Collaborator

kelson42 commented Jan 4, 2025

Indeed, but worflow should not fail, it should detect if the upload error is because of same version and just say "upload skipped because very same version"... other upload reason should make the workflow fail.

Maybe even better is to check this... before uploading.

@MohitMaliFtechiz
Copy link
Collaborator Author

Maybe even better is to check this... before uploading.

@kelson42 I was also thinking about this, but there is no direct way to check the previously uploaded app's version code from the Play Store. To achieve this, we have to manually manage this like storing the previously uploaded app's version code somewhere and then receiving it on the CD.

Indeed, but worflow should not fail, it should detect if the upload error is because of same version and just say "upload skipped because very same version"... other upload reason should make the workflow fail.

We can do it.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft January 4, 2025 09:16
…ded with the same version as the previously uploaded one, and Play Store gives the error for same version code. This prevents the CD pipeline from failing due to this error, while for all other errors, the workflow will fail as expected.
@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review January 4, 2025 11:06
@MohitMaliFtechiz
Copy link
Collaborator Author

I have made the changes in the testing_release workflow.

Copy link
Collaborator

@kelson42 kelson42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few changes required.

id: git_date
run: |
DATE=$(git log -1 --format=%cd --date=format:%Y-%m-%d || echo "NoCommits")
if [ "$DATE" = "NoCommits" ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which scenario should here lead to "NoCommits" ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scenario can only occur when no commit is available in the concerned branch; I had added this just for the fallback mechanism. But it is unnecessary since this workflow always runs on the main branch and always has the commits.

else
RELEASE_DATE="$DATE"
fi
echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't echo here in workflows.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kelson42 It is for setting the env variable, not for printing its value see, without echo it will not store the output of "RELASE_DATE". However, this is a non-critical env variable so github printing it in the next job see.

val currentDate = if (!System.getenv("KIWIX_ANDROID_RELEASE_DATE").isNullOrEmpty()) {
LocalDate.parse(System.getenv("KIWIX_ANDROID_RELEASE_DATE"))
} else {
LocalDate.now()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug message should be here making clear the value of the date and where it comes from

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added the log.

@@ -21,6 +21,18 @@ jobs:
- name: Set tag variable
run: echo "TAG=$(echo ${GITHUB_REF:10})" >> $GITHUB_ENV

- name: Retrieve date from git revision
id: git_date
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variable name should better be git_head_revision_date

…gging purposes.

* Improved the ID of the "Retrieve date from git revision" job.
* Removed unnecessary conditions from the workflow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reproducible Builds
3 participants