Skip to content

Commit

Permalink
chore: improved build scripts with deploy (#462)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityastic authored and iamareebjamal committed Aug 6, 2019
1 parent d28ca2e commit fe2999c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 36 deletions.
12 changes: 10 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,20 @@ cache:
- "${TRAVIS_BUILD_DIR}/gradle/wrapper/dists/"
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"

install:
- bundle install

before_script:
- bash scripts/prep-key.sh

script:
- ./gradlew spotlessCheck
- ./gradlew build --stacktrace
after_success:
- bash scripts/upload-apk.sh

deploy:
provider: script
script: bash scripts/upload-apk.sh
on:
all_branches: true
condition: $TRAVIS_BRANCH =~ ^(master|development)$
45 changes: 11 additions & 34 deletions scripts/upload-apk.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,66 +1,43 @@
#!/bin/sh
set -e

git config --global user.name "Travis CI"
git config --global user.email "[email protected]"

export DEPLOY_BRANCH=${DEPLOY_BRANCH:-development}
export PUBLISH_BRANCH=${PUBLISH_BRANCH:-master}

if [ "$TRAVIS_PULL_REQUEST" != "false" -o "$TRAVIS_REPO_SLUG" != "fossasia/badge-magic-android" ] || ! [ "$TRAVIS_BRANCH" == "$DEPLOY_BRANCH" -o "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]; then
echo "We upload apk only for changes in development or master, and not PRs. So, let's skip this shall we ? :)"
exit 0
fi

bundle exec fastlane buildAAB

git clone --quiet --branch=apk https://fossasia:$GITHUB_KEY@github.com/fossasia/badge-magic-android apk > /dev/null
cd apk

if [[ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]]; then
/bin/rm -f *
if [[ $TRAVIS_BRANCH =~ ^(master)$ ]]; then
rm -rf *
else
/bin/rm -f badge-magic-dev-*
rm -rf badge-magic-dev*
fi

find ../app/build/outputs -type f \( -name '*.apk' -o -name '*.aab' \) -exec cp -v {} . \;

#removing unused apps
for file in app*; do
if [[ "$TRAVIS_BRANCH" == "$PUBLISH_BRANCH" ]]; then
if [[ ${file} =~ ".aab" ]]; then
mv ${file} badge-magic-master-${file}
else
mv ${file} badge-magic-master-${file:4}
fi
elif [[ "$TRAVIS_BRANCH" == "$DEPLOY_BRANCH" ]]; then
if [[ ${file} =~ ".aab" ]]; then
mv ${file} badge-magic-dev-${file}
else
mv ${file} badge-magic-dev-${file:4}
fi
if [[ $file =~ ".aab" ]]; then
mv $file badge-magic-$TRAVIS_BRANCH-$file
else
mv $file badge-magic-$TRAVIS_BRANCH-${file:4}
fi
done

# Create a new branch that will contains only latest apk
git checkout --orphan temporary

# Add generated APK
git add --all .
git commit -am "[Auto] Update Test Apk ($(date +%Y-%m-%d.%H:%M:%S))"

# Delete current apk branch
git branch -D apk
# Rename current branch to apk
git branch -m apk

# Force push to origin since histories are unrelated
git push origin apk --force --quiet > /dev/null

# Publish App to Play Store
if [[ "$TRAVIS_BRANCH" != "$PUBLISH_BRANCH" ]]; then
echo "We publish apk only for changes in master branch. So, let's skip this shall we ? :)"
if [[ $TRAVIS_BRANCH =~ ^(master)$ ]]; then
cd ..
bundle exec fastlane uploadToPlaystore
exit 0
fi

bundle exec fastlane uploadToPlaystore
echo "We publish apk only for changes in master branch. So, let's skip this shall we ? :)"

0 comments on commit fe2999c

Please sign in to comment.