|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +git config --global user.name "Travis CI" |
| 5 | +git config --global user.email "noreply+travis@fossasia.org" |
| 6 | + |
| 7 | +export DEPLOY_BRANCH=${DEPLOY_BRANCH:-development} |
| 8 | +export PUBLISH_BRANCH=${PUBLISH_BRANCH:-master} |
| 9 | + |
| 10 | +if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_REPO_SLUG" != "fossasia/phimpme-android" ] || ! [ "$TRAVIS_BRANCH" == "$DEPLOY_BRANCH" -o "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then |
| 11 | + echo "We upload apk only for changes in development or master, and not PRs. So, let's skip this shall we ? :)" |
| 12 | + exit 0 |
| 13 | +fi |
| 14 | + |
| 15 | + |
| 16 | +git clone --quiet --branch=apk https://fossasia:$GITHUB_API_KEY@github.com/fossasia/phimpme-android apk > /dev/null |
| 17 | +cd apk |
| 18 | + |
| 19 | +if [[ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]]; then |
| 20 | + /bin/rm -f * |
| 21 | +else |
| 22 | + /bin/rm -f phimpme-dev-*.apk |
| 23 | +fi |
| 24 | + |
| 25 | +\cp -r ../app/build/outputs/apk/app-debug.apk app-debug.apk |
| 26 | +\cp -r ../app/build/outputs/apk/app-release-unsigned.apk app-release-unsigned.apk |
| 27 | + |
| 28 | +# Signing Apps |
| 29 | + |
| 30 | +if [ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then |
| 31 | + echo "Push to master branch detected, signing the app..." |
| 32 | + cp app-release-unsigned.apk app-release-unaligned.apk |
| 33 | + jarsigner -verbose -tsa http://timestamp.comodoca.com/rfc3161 -sigalg SHA1withRSA -digestalg SHA1 -keystore ../scripts/key.jks -storepass $STORE_PASS -keypass $KEY_PASS app-release-unaligned.apk $ALIAS |
| 34 | + ${ANDROID_HOME}/build-tools/26.0.3/zipalign -v -p 4 app-release-unaligned.apk app-release.apk |
| 35 | +fi |
| 36 | + |
| 37 | +if [ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then |
| 38 | + for file in app*; do |
| 39 | + if [[ $file = "phimpme"* ]]; then |
| 40 | + continue |
| 41 | + fi |
| 42 | + mv $file phimpme-master-${file%%} |
| 43 | + done |
| 44 | +fi |
| 45 | + |
| 46 | +if [ "$TRAVIS_BRANCH" == "$DEPLOY_BRANCH" ]; then |
| 47 | + for file in app*; do |
| 48 | + if [[ $file = "phimpme"* ]]; then |
| 49 | + continue |
| 50 | + fi |
| 51 | + mv $file phimpme-dev-${file%%} |
| 52 | + done |
| 53 | +fi |
| 54 | + |
| 55 | +# Create a new branch that will contain only latest apk |
| 56 | +git checkout --orphan temporary |
| 57 | + |
| 58 | +# Add generated APK |
| 59 | +git add --all . |
| 60 | +git commit -am "[Auto] Update Test Apk ($(date +%Y-%m-%d.%H:%M:%S))" |
| 61 | + |
| 62 | +# Delete current apk branch |
| 63 | +git branch -D apk |
| 64 | +# Rename current branch to apk |
| 65 | +git branch -m apk |
| 66 | + |
| 67 | +# Force push to origin since histories are unrelated |
| 68 | +git push origin apk --force --quiet > /dev/null |
| 69 | + |
| 70 | +# Publish App to Play Store |
| 71 | +if [ "$TRAVIS_BRANCH" != "$PUBLISH_BRANCH" ]; then |
| 72 | + echo "We publish apk only for changes in master branch. So, let's skip this shall we ? :)" |
| 73 | + exit 0 |
| 74 | +fi |
| 75 | + |
| 76 | +gem install fastlane |
| 77 | +fastlane supply --apk phimpme-master-app-release.apk --track alpha --json_key ../scripts/fastlane.json --package_name $PACKAGE_NAME |
0 commit comments