deploy.sh (2848B)
1 #!/bin/bash 2 set -exuo pipefail 3 4 ARTIFACT_PATH="/artifacts/taler-android/${CI_COMMIT_REF}/cashier" 5 APK_PATH="cashier/build/outputs/apk/release/cashier-release-unsigned.apk" 6 LINT_PATH="cashier/build/reports/lint-results-debug.html" 7 8 export versionCode=$(date '+%s') 9 10 function build_apk { 11 [[ ! -f "${NIGHTLY_KEYSTORE_PATH}" ]] && return 1 12 echo "Building APK ..." 13 14 # Rename nightly app 15 sed -i 's,<string name="app_name">.*</string>,<string name="app_name">Cashier Nightly</string>,' cashier/src/main/res/values*/strings.xml 16 17 # Set time-based version code 18 sed -i "s,^\(\s*versionCode\) *[0-9].*,\1 $versionCode," cashier/build.gradle 19 20 # Set nightly application ID 21 sed -i "s,^\(\s*applicationId\) \"*[a-z\.].*\",\1 \"net.taler.cashier.nightly\"," cashier/build.gradle 22 23 # Test and build the APK 24 ./gradlew :cashier:check :cashier:assembleRelease 25 26 # Sign the APK 27 apksigner sign \ 28 --ks "${NIGHTLY_KEYSTORE_PATH}" \ 29 --ks-key-alias "${NIGHTLY_KEYSTORE_ALIAS}" \ 30 --ks-pass env:NIGHTLY_KEYSTORE_PASS \ 31 "${APK_PATH}" 32 33 # Copy the APK and lint report to artifacts folder 34 mkdir -p "${ARTIFACT_PATH}" 35 cp "${APK_PATH}" "${ARTIFACT_PATH}"/cashier-debug.apk 36 cp "${LINT_PATH}" "${ARTIFACT_PATH}" 37 } 38 39 40 function deploy_apk { 41 [[ ! -f "${SCP_SSH_KEY}" ]] && return 0 42 echo "Deploying APK to taler.net/files ..." 43 44 apk_dest="${SCP_SSH_PATH}"/cashier/cashier-nightly-debug-${versionCode}.apk 45 latest_dest="${SCP_SSH_PATH}"/cashier/cashier-nightly-debug-latest.apk 46 47 # Deploy APK to taler.net/files/cashier 48 scp -i "${SCP_SSH_KEY}" \ 49 -o StrictHostKeyChecking=no \ 50 -o UserKnownHostsFile=/dev/null \ 51 "${APK_PATH}" \ 52 "${SCP_SSH_HOST}":"${apk_dest}" 53 54 # Create symbolic link to the latest version 55 ssh -i "${SCP_SSH_KEY}" \ 56 -o StrictHostKeyChecking=no \ 57 -o UserKnownHostsFile=/dev/null \ 58 "${SCP_SSH_HOST}" \ 59 ln -sfr "${apk_dest}" "${latest_dest}" 60 } 61 62 63 function deploy_fdroid { 64 [[ ! -f "${FDROID_REPO_KEY}" ]] && return 0 65 echo "Deploying APK to F-droid nightly ..." 66 67 # Copy keystore where SDK can find it 68 cp "${NIGHTLY_KEYSTORE_PATH}" /root/.android/debug.keystore 69 70 # Rename APK, so fdroid nightly accepts it (looks for *-debug.apk) 71 cp "${APK_PATH}" cashier-debug.apk 72 73 fdroid --version 74 75 set +x 76 export DEBUG_KEYSTORE=$(cat "$FDROID_REPO_KEY") 77 set -x 78 79 # Deploy APK to nightly repository 80 export CI= 81 export CI_PROJECT_URL="https://gitlab.com/gnu-taler/fdroid-repo" 82 export CI_PROJECT_PATH="gnu-taler/fdroid-repo" 83 export GITLAB_USER_NAME="$(git log -1 --pretty=format:'%an')" 84 export GITLAB_USER_EMAIL="$(git log -1 --pretty=format:'%ae')" 85 86 fdroid nightly -v --archive-older 6 87 } 88 89 build_apk 90 deploy_apk 91 deploy_fdroid