-
-
Notifications
You must be signed in to change notification settings - Fork 463
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 beLAST_DATE
)- Document properly the feature in the README in a new section "Release".
- Modify the CI and the CD so we use this feature
ef1e846
to
887d543
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
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
@kelson42 I have made the changes as you requested. If anything we can improve in this, please let me know. |
There was a problem hiding this 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?
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.
…e can be easily used.
@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).
Okay, but it could lead to issues with our testing_release workflow. Here's why:
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 |
… 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.
0897c89
to
66f3d4d
Compare
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. |
@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.
We can do it. |
…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.
I have made the changes in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few changes required.
.github/workflows/release.yml
Outdated
id: git_date | ||
run: | | ||
DATE=$(git log -1 --format=%cd --date=format:%Y-%m-%d || echo "NoCommits") | ||
if [ "$DATE" = "NoCommits" ]; then |
There was a problem hiding this comment.
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" ?
There was a problem hiding this comment.
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.
.github/workflows/release.yml
Outdated
else | ||
RELEASE_DATE="$DATE" | ||
fi | ||
echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
val currentDate = if (!System.getenv("KIWIX_ANDROID_RELEASE_DATE").isNullOrEmpty()) { | ||
LocalDate.parse(System.getenv("KIWIX_ANDROID_RELEASE_DATE")) | ||
} else { | ||
LocalDate.now() |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
.github/workflows/release.yml
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
Fixes #4120
KIWIX_ANDROID_RELEASE_DATE
environment variable in the formatYYYY-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.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.