From e38dd7dedbb0ccc15dc5943a26c5b01814820434 Mon Sep 17 00:00:00 2001 From: Koen Date: Wed, 28 Jun 2023 12:36:49 +0200 Subject: [PATCH] Build and deploy Android Cloudflare compatibility. --- .gitlab-ci.yml | 3 +-- receivers/android/.gitlab-ci.yml | 21 ++++----------------- receivers/android/deploy.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 19 deletions(-) create mode 100644 receivers/android/deploy.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6cbcd08..4fb321d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,5 @@ stages: - - buildAndDeployApk - - buildAndDeployPlayStoreAab + - buildAndDeployAndroid - deployWebsite - buildAndDeployElectron diff --git a/receivers/android/.gitlab-ci.yml b/receivers/android/.gitlab-ci.yml index 6bfd256..1a6bef5 100644 --- a/receivers/android/.gitlab-ci.yml +++ b/receivers/android/.gitlab-ci.yml @@ -1,20 +1,7 @@ -buildAndDeployApk: - stage: buildAndDeployApk +buildAndDeployAndroid: + stage: buildAndDeployAndroid before_script: - cd receivers/android script: - - if [ -z "$ANDROID_VERSION_NAME" ] || [ -z "$ANDROID_VERSION_CODE" ]; then echo "Version name or code not specified. Skipping build."; exit 0; fi - - ./gradlew --stacktrace assembleRelease -PversionName=$ANDROID_VERSION_NAME -PversionCode=$ANDROID_VERSION_CODE - - cp ./app/build/outputs/apk/defaultFlavor/release/app-defaultFlavor-release.apk /var/www/html/fcast-release.apk - - echo $ANDROID_VERSION_CODE > /var/www/html/fcast-version.txt - when: manual - -buildAndDeployPlayStoreAab: - stage: buildAndDeployPlayStoreAab - before_script: - - cd receivers/android - script: - - if [ -z "$ANDROID_VERSION_NAME" ] || [ -z "$ANDROID_VERSION_CODE" ]; then echo "Version name or code not specified. Skipping build."; exit 0; fi - - ./gradlew --stacktrace bundlePlaystoreRelease -PversionName=$ANDROID_VERSION_NAME -PversionCode=$ANDROID_VERSION_CODE - - cp ./app/build/outputs/bundle/playstoreRelease/app-playstore-release.aab /var/www/html/fcast-playstore-release.aab - when: manual + - sh deploy.sh + when: manual \ No newline at end of file diff --git a/receivers/android/deploy.sh b/receivers/android/deploy.sh new file mode 100644 index 0000000..c5d9ffc --- /dev/null +++ b/receivers/android/deploy.sh @@ -0,0 +1,30 @@ +#!/bin/sh +if [ -z "$ANDROID_VERSION_NAME" ] || [ -z "$ANDROID_VERSION_CODE" ]; then echo "Version name or code not specified. Skipping build."; exit 0; fi + +DOCUMENT_ROOT=/var/www/html + +# Build content +echo "Building content..." +./gradlew --stacktrace assembleRelease -PversionName=$ANDROID_VERSION_NAME -PversionCode=$ANDROID_VERSION_CODE +./gradlew --stacktrace bundlePlaystoreRelease -PversionName=$ANDROID_VERSION_NAME -PversionCode=$ANDROID_VERSION_CODE + +# Take site offline +echo "Taking site offline..." +touch $DOCUMENT_ROOT/maintenance.file + +# Swap over the content +echo "Deploying content..." +echo $ANDROID_VERSION_CODE > /var/www/html/fcast-version.txt +cp ./app/build/outputs/apk/defaultFlavor/release/app-defaultFlavor-release.apk /var/www/html/fcast-release.apk +cp ./app/build/outputs/bundle/playstoreRelease/app-playstore-release.aab /var/www/html/fcast-playstore-release.aab + +# Notify Cloudflare to wipe the CDN cache +echo "Purging Cloudflare cache..." +curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/purge_cache" \ + -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + -H "Content-Type: application/json" \ + --data '{"purge_everything":true}' + +# Take site back online +echo "Bringing site back online..." +rm $DOCUMENT_ROOT/maintenance.file \ No newline at end of file