taler-android

Android apps for GNU Taler (wallet, PoS, cashier)
Log | Files | Refs | README | LICENSE

deploy.sh (5015B)


      1 #!/bin/bash
      2 set -exuo pipefail
      3 
      4 ARTIFACT_PATH="/artifacts/taler-android/${CI_COMMIT_REF}/wallet"
      5 NIGHTLY_APK_PATH="wallet/build/outputs/apk/nightly/release/wallet-nightly-release-unsigned.apk"
      6 NIGHTLY_LINT_PATH="wallet/build/reports/lint-results-fdroidDebug.html"
      7 FDROID_APK_ARCHS=(x86_64 x86 arm64-v8a armeabi-v7a)
      8 FDROID_APK_TEMPLATE="wallet/build/outputs/apk/fdroid/release/wallet-fdroid-%s-release-unsigned.apk"
      9 
     10 set +o pipefail
     11 TAG_REGEX='wallet-[0-9.]+(\+.*)?$'
     12 TAG_MATCH="$(git tag --points-at "${CI_COMMIT_REF}" | grep -E "${TAG_REGEX}" | head -1)"
     13 FDROID_VERSION="${TAG_MATCH#wallet-}"
     14 set -o pipefail
     15 
     16 
     17 # F-Droid nightly build (https://f-droid.org/docs/Publishing_Nightly_Builds/)
     18 function build_nightly_apk {
     19     [[ ! -f "${NIGHTLY_KEYSTORE_PATH}" ]] && return 1
     20     echo "Building nightly APK ..."
     21 
     22     # Test and build the APK
     23     ./gradlew :wallet:check :wallet:assembleNightlyRelease
     24 
     25     # Sign the APK
     26     apksigner sign \
     27               --ks "${NIGHTLY_KEYSTORE_PATH}" \
     28               --ks-key-alias "${NIGHTLY_KEYSTORE_ALIAS}" \
     29               --ks-pass env:NIGHTLY_KEYSTORE_PASS \
     30               "${NIGHTLY_APK_PATH}"
     31 
     32     # Copy the APK and lint report to artifacts folder
     33     mkdir -p "${ARTIFACT_PATH}"
     34     cp "${NIGHTLY_APK_PATH}" "${ARTIFACT_PATH}"/wallet-nightly-debug.apk
     35     cp "${NIGHTLY_LINT_PATH}" "${ARTIFACT_PATH}"
     36 }
     37 
     38 
     39 # F-Droid reproducible build (https://f-droid.org/en/docs/Reproducible_Builds/)
     40 # only build if commit contains release tag e.g. wallet-1.4.0+p1
     41 function build_fdroid_apk {
     42     [[ -z "${FDROID_VERSION}" ]] && return 0
     43     [[ ! -f "${FDROID_KEYSTORE_PATH}" ]] && return 0
     44     echo "Building F-Droid APK (${FDROID_VERSION}) ..."
     45 
     46     # Test and build the APK
     47     ./gradlew -PsplitApk :wallet:assembleRelease
     48 
     49     # Sign the APK for all architectures
     50     # see https://github.com/obfusk/apksigcopier#what-about-signatures-made-by-apksigner-from-build-tools--3500-rc1
     51     for arch in "${FDROID_APK_ARCHS[@]}"; do
     52         apksigner sign \
     53                   --ks "${FDROID_KEYSTORE_PATH}" \
     54                   --ks-key-alias "${FDROID_KEYSTORE_ALIAS}" \
     55                   --ks-pass env:FDROID_KEYSTORE_PASS \
     56                   --alignment-preserved \
     57                   "$(printf "${FDROID_APK_TEMPLATE}" "${arch}")"
     58     done
     59 }
     60 
     61 
     62 function deploy_nightly_apk {
     63     [[ ! -f "${SCP_SSH_KEY}" ]] && return 0
     64     [[ ! -f "${NIGHTLY_APK_PATH}" ]] && return 0
     65     echo "Deploying nightly APK to taler.net/files ..."
     66 
     67     apk_dest="${SCP_SSH_PATH}"/wallet/wallet-nightly-debug-$(date -u +%s).apk
     68     latest_dest="${SCP_SSH_PATH}"/wallet/wallet-nightly-debug-latest.apk
     69 
     70     # Deploy APK to taler.net/files/wallet
     71     scp -i "${SCP_SSH_KEY}" \
     72         -o StrictHostKeyChecking=no \
     73         -o UserKnownHostsFile=/dev/null \
     74         "${NIGHTLY_APK_PATH}" \
     75         "${SCP_SSH_HOST}":"${apk_dest}"
     76 
     77     # Create symbolic link to the latest version
     78     ssh -i "${SCP_SSH_KEY}" \
     79         -o StrictHostKeyChecking=no \
     80         -o UserKnownHostsFile=/dev/null \
     81         "${SCP_SSH_HOST}" \
     82         ln -sfr "${apk_dest}" "${latest_dest}"
     83 }
     84 
     85 
     86 function deploy_fdroid_apk {
     87     [[ -z "${FDROID_VERSION}" ]] && return 0
     88     [[ ! -f "${SCP_SSH_KEY}" ]] && return 0
     89     echo "Deploying F-Droid APK (${FDROID_VERSION}) to taler.net/files ..."
     90 
     91     # Deploy APK for all architectures to taler.net/files/wallet
     92     for arch in "${FDROID_APK_ARCHS[@]}"; do
     93         apk_path="$(printf "${FDROID_APK_TEMPLATE}" "${arch}")"
     94         [[ ! -f "${apk_path}" ]] && return 1
     95         # extract version name and code (encodes arch)
     96         version_name="$(aapt2 dump badging "${apk_path}" | grep "versionName" | sed -e "s/.*versionName='//" -e "s/' .*//")"
     97         version_code="$(aapt2 dump badging "${apk_path}" | grep "versionCode" | sed -e "s/.*versionCode='//" -e "s/' .*//")"
     98         apk_dest="${SCP_SSH_PATH}"/wallet/fdroid/wallet-fdroid-"${version_name}"-"${version_code}".apk
     99         scp -i "${SCP_SSH_KEY}" \
    100             -o StrictHostKeyChecking=no \
    101             -o UserKnownHostsFile=/dev/null \
    102             "${apk_path}" \
    103             "${SCP_SSH_HOST}":"${apk_dest}"
    104     done
    105 }
    106 
    107 
    108 function deploy_nightly_fdroid {
    109     [[ ! -f "${FDROID_REPO_KEY}" ]] && return 0
    110     echo "Deploying APK to F-droid nightly ..."
    111 
    112     # Copy keystore where SDK can find it
    113     cp "${NIGHTLY_KEYSTORE_PATH}" /root/.android/debug.keystore
    114 
    115     # Rename APK, so fdroid nightly accepts it (looks for *-debug.apk)
    116     cp "${NIGHTLY_APK_PATH}" wallet-debug.apk
    117 
    118     fdroid --version
    119 
    120     set +x
    121     export DEBUG_KEYSTORE=$(cat "$FDROID_REPO_KEY")
    122     set -x
    123 
    124     # Deploy APK to nightly repository
    125     export CI=
    126     export CI_PROJECT_URL="https://gitlab.com/gnu-taler/fdroid-repo"
    127     export CI_PROJECT_PATH="gnu-taler/fdroid-repo"
    128     export GITLAB_USER_NAME="$(git log -1 --pretty=format:'%an')"
    129     export GITLAB_USER_EMAIL="$(git log -1 --pretty=format:'%ae')"
    130 
    131     fdroid nightly -v --archive-older 6
    132 }
    133 
    134 
    135 # nightly
    136 build_nightly_apk
    137 deploy_nightly_apk
    138 deploy_nightly_fdroid
    139 
    140 # f-droid
    141 build_fdroid_apk
    142 deploy_fdroid_apk