Last active
March 7, 2018 15:54
-
-
Save Code0987/e56ba378ad089c71efd6837585606ad8 to your computer and use it in GitHub Desktop.
gradle_android.gitlab_ci.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
image: openjdk:8-jdk | |
stages: | |
- build | |
- test | |
- package | |
#################################################################################################### | |
# BUILD | |
# | |
.build_template: &build_template_def | |
stage: build | |
artifacts: | |
expire_in: 4 hours | |
paths: | |
- ./src/app/build/outputs/**.apk | |
- ~/.android/ | |
- ~/ci-log.log | |
before_script: | |
- export LOG=~/ci-log.log | |
- touch $LOG | |
# Extract the SDK version that we're building against | |
- export ANDROID_SDK_TOOLS=3859397 | |
- export ANDROID_BUILD_TOOLS=26.0.2 | |
- export ANDROID_COMPILE_SDK=25 | |
#`egrep '^[[:blank:]]+compileSdkVersion' ./src/mobile/build.gradle | awk '{print $2}'` | |
# Explict output for logging purpose only | |
- echo $ANDROID_SDK_TOOLS | |
- echo $ANDROID_BUILD_TOOLS | |
- echo $ANDROID_COMPILE_SDK | |
# Set up environment variables | |
- export ANDROID_HOME=~/.android | |
- export ANDROID_NDK_HOME=$ANDROID_HOME/ndk-bundle # Remove if you don't need NDK | |
- export PATH=$PATH:$ANDROID_HOME/platform-tools/:$ANDROID_NDK_HOME | |
- mkdir -p $ANDROID_HOME/ && touch $ANDROID_HOME/repositories.cfg | |
# Fetch the specified SDK tools version to build with | |
- wget --quiet --output-document=/tmp/sdk-tools-linux.zip https://dl.google.com/android/repository/sdk-tools-linux-${ANDROID_SDK_TOOLS}.zip >> $LOG | |
- unzip /tmp/sdk-tools-linux.zip -d $ANDROID_HOME/ >> $LOG | |
# Install platform tools and Android SDK for the compile target | |
- echo 'count=0' > $ANDROID_HOME/repositories.cfg | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager --update >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'tools' >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platform-tools' >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'build-tools;'$ANDROID_BUILD_TOOLS >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'platforms;android-'$ANDROID_COMPILE_SDK >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;android;m2repository' >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;google_play_services' >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'extras;google;m2repository' >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'cmake;3.6.4111459' >> $LOG | |
- echo y | $ANDROID_HOME/tools/bin/sdkmanager 'ndk-bundle' >> $LOG | |
- chmod +x ./src/gradlew | |
build_debug: | |
<<: *build_template_def | |
only: | |
- develop | |
script: | |
- ./src/gradlew -p ./src assembleMainDebug --stacktrace | |
build_release: | |
<<: *build_template_def | |
only: | |
- master | |
script: | |
- ./src/gradlew -p ./src assembleMainReleaseBeta --stacktrace | |
#################################################################################################### | |
# UNIT TESTING | |
# | |
unit_test: | |
stage: test | |
only: | |
- master | |
- develop | |
before_script: | |
- export ANDROID_HOME=$PWD/.android | |
- export PATH=$PATH:$PWD/.android/platform-tools/ | |
script: | |
- ./src/gradlew test | |
#################################################################################################### | |
# PACKAGE APK FOR DOWNLOADING | |
# | |
.package_template: &package_template_def | |
before_script: | |
- export VERSION_NAME=`egrep '^[[:blank:]]+versionName[[:blank:]]' ./src/mobile/build.gradle | awk '{print $2}' | sed s/\"//g` | |
- export VERSION_CODE=`egrep '^[[:blank:]]+versionCode[[:blank:]]' ./src/mobile/build.gradle | awk '{print $2}'` | |
- mkdir -p deliverables | |
# Store some information about the build | |
- touch ./deliverables/info.txt | |
- echo "Build date $(date)" >> ./deliverables/info.txt | |
- echo "App version name ${VERSION_NAME}" >> ./deliverables/info.txt | |
- echo "App version code ${VERSION_CODE}" >> ./deliverables/info.txt | |
- echo "Git branch ${CI_COMMIT_REF_NAME}" >> ./deliverables/info.txt | |
- echo "Git commit ${CI_COMMIT_SHA}" >> ./deliverables/info.txt | |
- echo "Gitlab pipeline ${CI_PIPELINE_ID}" >> ./deliverables/info.txt | |
package_develop: | |
<<: *package_template_def | |
stage: package | |
environment: Development | |
only: | |
- develop | |
script: | |
- mv ./src/app/build/outputs/**.apk ./deliverables/ | |
- mv $LOG ./deliverables/ | |
artifacts: | |
expire_in: 3 days | |
paths: | |
- deliverables | |
package_release: | |
<<: *package_template_def | |
stage: package | |
environment: Release | |
only: | |
- master | |
script: | |
- mv ./src/app/build/outputs/**.apk ./deliverables/ | |
artifacts: | |
expire_in: 4 weeks | |
paths: | |
- deliverables |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment