-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
86 lines (79 loc) · 3.08 KB
/
.gitlab-ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
image: runmymind/docker-android-sdk:alpine-standalone
variables:
KEYSTORE_PATH: '.keystore/keystore.jks'
PLAY_KEYS_PATH: '.keystore/keys.json'
PROPERTIES_PATH: 'keystore.properties'
SLAVE_AAPT_TIMEOUT: '30'
GIT_SSL_NO_VERIFY: 1
HOST_NAME: "gitlab.milobella.com"
before_script:
- export GITLAB_USER_NAME=$(echo $GITLAB_USER_LOGIN)
- export GRADLE_USER_HOME=`pwd`/.gradle
- chmod +x gradlew
- echo $ANDROID_KEYSTORE | base64 -d > ${KEYSTORE_PATH}
- echo $ANDROID_PLAY_KEYS_JSON > ${PLAY_KEYS_PATH}
- echo "storeFile=${KEYSTORE_PATH}" >> ${PROPERTIES_PATH}
- echo "storePassword=${ANDROID_STORE_PASSWORD}" >> ${PROPERTIES_PATH}
- echo "keyAlias=${ANDROID_KEY_ALIAS}" >> ${PROPERTIES_PATH}
- echo "keyPassword=${ANDROID_KEY_PASSWORD}" >> ${PROPERTIES_PATH}
- echo "playKeysFile=${PLAY_KEYS_PATH}" >> ${PROPERTIES_PATH}
- git config user.email ${GITLAB_USER_EMAIL}
- git config user.name ${GITLAB_USER_NAME}
cache:
paths:
- .gradle/wrapper
- .gradle/caches
stages:
- build
- test
- version
- deploy
build:
stage: build
script:
- chmod +x gradlew
- ./gradlew clean assemble
artifacts:
paths:
- app/build/outputs/apk
tags: [docker]
except: [master]
test:
stage: test
script:
- chmod +x gradlew
- ./gradlew test
tags: [docker]
except: [master]
bump_version_and_deploy:
stage: version
script:
# Retrieves version name from app/build.gradle
- SNAPSHOT_VERSION_NAME=`./gradlew -q -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false printVersionName`
- DEPLOYED_VERSION_NAME=`echo ${SNAPSHOT_VERSION_NAME} | sed 's_-SNAPSHOT__'`
# Remove the snapshot suffix in app/build.gradle
- sed -i "s_${SNAPSHOT_VERSION_NAME}_${DEPLOYED_VERSION_NAME}_" app/build.gradle
# Store current bumped versionCode and versionName
- DEPLOYED_VERSION_CODE=`./gradlew -q -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false printVersionCode`
- DEPLOYED_VERSION_NAME=`./gradlew -q -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false printVersionName`
# Publish the release
- ./gradlew publish
# If the publication succeeded, commit and tag the bumped version
- git add app/build.gradle
- git commit -m "Bump version ${DEPLOYED_VERSION_NAME}"
- git tag ${DEPLOYED_VERSION_NAME}
# Increment versionCode and versionName
- NEW_VERSION_CODE=`./gradlew -q -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false computeNextVersionCode`
- NEW_VERSION_NAME=`./gradlew -q -Dorg.gradle.internal.launcher.welcomeMessageEnabled=false computeNextVersionName`-SNAPSHOT
# Update versions fields in app/build.gradle
- sed -i -r "s/versionCode\s+${DEPLOYED_VERSION_CODE}/versionCode ${NEW_VERSION_CODE}/" app/build.gradle
- sed -i -r "s/versionName\s+\"${DEPLOYED_VERSION_NAME}\"/versionName \"${NEW_VERSION_NAME}\"/" app/build.gradle
# Commit the start of the new version
- git add app/build.gradle
- git commit -m "Start a new version ${NEW_VERSION_NAME}"
# Push both of freshly created commits
- git push --tags http://Garcia:${GARCIA_PERSONAL_TOKEN}@${HOST_NAME}/${CI_PROJECT_PATH}.git HEAD:master
when: manual
allow_failure: false
only: [master]
tags: [docker]