Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improved build scripts with deploy #462

Merged
merged 1 commit into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:[email protected]/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 ? :)"