diff --git a/.github/workflows/dummy_bundle_and_apk.yml b/.github/workflows/dummy_bundle_and_apk.yml index d43215f37..4a43c47f8 100644 --- a/.github/workflows/dummy_bundle_and_apk.yml +++ b/.github/workflows/dummy_bundle_and_apk.yml @@ -1,13 +1,10 @@ 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. -# 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). +# This workflow will trigger when the 'dummy_bundle_and_apk' is pushed. on: push: tags: - '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: publish_dummy_bundle_and_apk: @@ -28,19 +25,17 @@ jobs: run: | echo "$KEYSTORE" | base64 -d > kiwix-android.keystore - - name: Retrieve date from TAG - id: extract_date + - name: Retrieve date from git revision + id: git_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]}" + DATE=$(git log -1 --format=%cd --date=format:%Y-%m-%d || echo "NoCommits") + if [ "$DATE" = "NoCommits" ]; then + RELEASE_DATE="" else - RELEASE_DATE="" + RELEASE_DATE="$DATE" fi echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV + shell: bash - name: Generate dummy Bundle and APKs env: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c0c2e8304..f540ce8d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 + 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 env: KEYSTORE: ${{ secrets.keystore }} @@ -37,6 +49,7 @@ jobs: KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} UNIVERSAL_RELEASE_APK: app/build/outputs/apk/standalone/*universal*.apk ARCHIVE_NAME: kiwix-${{ github.event.release.tag_name }}.apk + KIWIX_ANDROID_RELEASE_DATE: ${{ env.KIWIX_ANDROID_RELEASE_DATE }} run: | ./gradlew assembleStandalone cp ${UNIVERSAL_RELEASE_APK} ${ARCHIVE_NAME} @@ -64,6 +77,7 @@ jobs: KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} KEY_STORE_PASSWORD: ${{ secrets.KEY_STORE_PASSWORD }} PLAYSTORE_JSON: ${{ secrets.PLAYSTORE_JSON }} + KIWIX_ANDROID_RELEASE_DATE: ${{ env.KIWIX_ANDROID_RELEASE_DATE }} run: | echo "$PLAYSTORE_JSON" > playstore.json ./gradlew publishPlayStoreBundle --scan diff --git a/.github/workflows/testing_release.yml b/.github/workflows/testing_release.yml index 6a894fc37..de0590758 100644 --- a/.github/workflows/testing_release.yml +++ b/.github/workflows/testing_release.yml @@ -1,15 +1,13 @@ name: Publish App to Play Store # 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. -# In 'internal_testing_v*', '*' represents a dynamic date (e.g., 2024-12-18). +# It runs every Monday at 12:00 UTC and also when the 'internal_testing' tag is pushed. on: schedule: - cron: '0 12 * * 1' # Runs every Monday at 12:00 push: tags: - 'internal_testing' # internal_testing Tag - - 'internal_testing_v*' # Dynamic date tag for internal testing jobs: publish: @@ -32,19 +30,17 @@ jobs: echo "$KEYSTORE" | base64 -d > kiwix-android.keystore echo "$PLAYSTORE_JSON" > playstore.json - - name: Retrieve date from TAG - id: extract_date + - name: Retrieve date from git revision + id: git_date run: | - # Check if the tag matches the pattern 'internal_testing_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. - # 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]}" + DATE=$(git log -1 --format=%cd --date=format:%Y-%m-%d || echo "NoCommits") + if [ "$DATE" = "NoCommits" ]; then + RELEASE_DATE="" else - RELEASE_DATE="" + RELEASE_DATE="$DATE" fi echo "KIWIX_ANDROID_RELEASE_DATE=$RELEASE_DATE" >> $GITHUB_ENV + shell: bash - name: Publish bundle in internal testing on Google Play env: diff --git a/README.md b/README.md index b06610c61..c88da6ac7 100644 --- a/README.md +++ b/README.md @@ -101,16 +101,10 @@ are interested in our custom apps, they have their own repo ## 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. -This ensures that every new build is generated with a unique version code daily. -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: - -- `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. +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 +can override this by setting the environment variable `KIWIX_ANDROID_RELEASE_DATE` to a specific +date in the `YYYY-MM-DD` format. This will use the provided date for the version code calculation +instead of the current date. ## Libraries Used