Skip to content

Commit d4d13eb

Browse files
committed
Added new circleCI config
1 parent 1e31aa1 commit d4d13eb

File tree

9 files changed

+159
-3
lines changed

9 files changed

+159
-3
lines changed

.circleci/config.yml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/android:api-25-alpha
6+
environment:
7+
GRADLE_OPTS: '-Dorg.gradle.jvmargs="-Xmx2048m -XX:+HeapDumpOnOutOfMemoryError"'
8+
steps:
9+
- checkout
10+
- restore_cache:
11+
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
12+
13+
# Copy environment vars to gradle.properties
14+
- run:
15+
name: Copy Environment Vars
16+
command: scripts/cp-env-to-properties.sh
17+
18+
# Decrypt any secret files / keys
19+
- run:
20+
name: Decrypt secret files
21+
command: scripts/decrypt-secrets.sh
22+
23+
- run:
24+
name: Download Dependencies
25+
command: ./gradlew androidDependencies
26+
- save_cache:
27+
paths:
28+
- ~/.gradle
29+
key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }}
30+
- run:
31+
name: Run Tests
32+
command: ./gradlew test
33+
34+
- store_artifacts:
35+
path: app/build/reports
36+
destination: reports
37+
38+
- store_test_results:
39+
path: app/build/test-results
40+
41+
# Compile release apks
42+
- run:
43+
name: Compile APKs
44+
command: ./gradlew assembleRelease
45+
46+
47+
# Copy APK files to artifacts
48+
- run:
49+
name: Copy APK Files
50+
command: |
51+
set -xu
52+
mkdir -p /tmp/artifacts
53+
find . -name "*release.apk" -type f -exec echo {} \;
54+
find . -name "*release.apk" -type f -exec cp {} /tmp/artifacts/ \;
55+
56+
# Save artifacts
57+
- store_artifacts:
58+
name: Save APK Files
59+
path: /tmp/artifacts
60+
destination: build
61+
62+
# Upload to beta if requested and then publish webhooks
63+
- run:
64+
name: Publish to Google Play
65+
command: scripts/webhooks.sh
66+

.circleci/key.p12.enc

2.44 KB
Binary file not shown.
File renamed without changes.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
/build
1010
/captures
1111
TODO
12+
key.p12

app/build.gradle

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@ buildscript {
66

77
dependencies {
88
classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
9+
10+
// This is so we can publish straight to Google Play
11+
classpath 'com.github.triplet.gradle:play-publisher:1.1.5'
912
}
1013
}
1114

1215
apply plugin: 'com.android.application'
1316
apply plugin: 'spoon'
17+
apply plugin: 'com.github.triplet.play'
18+
19+
play {
20+
track = 'alpha'
21+
serviceAccountEmail = 'androidnetworktoolspublisher@api-6650335122940819061-609121.iam.gserviceaccount.com'
22+
pk12File = file('../key.p12')
23+
}
1424

1525
android {
1626
compileSdkVersion compileSdkVer
@@ -20,8 +30,8 @@ android {
2030
applicationId "com.stealthcotper.networktools"
2131
minSdkVersion minSdkVer
2232
targetSdkVersion targetSdkVer
23-
versionCode 7
24-
versionName "0.1.10"
33+
versionCode 8
34+
versionName "0.1.12"
2535
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
2636
}
2737

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ buildscript {
66
}
77
dependencies {
88
classpath 'com.android.tools.build:gradle:2.2.2'
9-
109
// NOTE: Do not place your application dependencies here; they belong
1110
// in the individual module build.gradle files
1211
}

scripts/cp-env-to-properties.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copy env variables to app module gradle properties file
4+
#
5+
6+
set +x // dont print the next lines on run script
7+
mkdir ~/.gradle
8+
printenv | tr ' ' '\n' | grep ANDROID_NETWORK_TOOLS > ~/.gradle/gradle.properties
9+
set -x

scripts/decrypt-secrets.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
# Following this guide to encrypt / decrypt files
4+
# https://github.com/circleci/encrypted-files
5+
6+
openssl aes-256-cbc -d -in .circleci/key.p12.enc -out key.p12 -k $ANDROID_NETWORK_TOOLS_DECRYPTKEY1

scripts/webhooks.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
# Fires a webhook to slack to notify of successful upload to beta
4+
function webhook {
5+
6+
gradle_app_name="$1"
7+
message="$2"
8+
channel="#mat-testing"
9+
git_hash=`git rev-parse --short HEAD`
10+
version=`cat ${gradle_app_name}/build.gradle | grep -m 1 versionName | cut -d'"' -f 2`
11+
12+
# TESTING WEBHOOK https://hooks.slack.com/services/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
13+
14+
app_name="Sample App"
15+
icon_url="https://github.com/stealthcopter/AndroidNetworkTools/raw/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png"
16+
17+
echo $message
18+
echo $channel $gradle_app_name $app_name $version $icon_url
19+
20+
curl -X POST --data-urlencode 'payload={"channel": "'"$channel"'", "username": "CirclCI Deployment Bot", "text": "*'"$app_name"'* version *'"$version"'* <'"https://github.com/scottyab/rootbeer/commits/$git_hash"'|'"$git_hash"'> '"$message"'", "icon_url": "'"$icon_url"'"}' https://hooks.slack.com/services/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
21+
22+
}
23+
24+
# Uploads a build to Beta
25+
function upload_to_beta {
26+
echo "Uploading $1 to Beta"
27+
28+
if ./gradlew :$1:crashlyticsUploadDistributionRelease ; then
29+
webhook "${1}" "Uploading to Beta Succeeded"
30+
else
31+
webhook "${1}" "Uploading to Beta Play FAILED :("
32+
fi
33+
}
34+
35+
# Uploads a build to Google Play
36+
function upload_to_google_play {
37+
echo "Uploading $1 to Google Play"
38+
39+
if ./gradlew :$1:publishApkRegularRelease ; then
40+
webhook "${1}" "Uploading to Google Play Succeeded"
41+
else
42+
webhook "${1}" "Uploading to Google Play FAILED :("
43+
fi
44+
}
45+
46+
GIT_COMMIT_DESC=`git log -n 1 $CIRCLE_SHA1`
47+
GIT_CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
48+
49+
50+
# Only deploy releases if we are on the master branch
51+
# if [[ $GIT_CURRENT_BRANCH != "master" ]]; then
52+
# echo "Not on master branch, so not deploying"
53+
# exit 0
54+
# fi
55+
56+
57+
# UNCOMMENT TO TEST
58+
GIT_COMMIT_DESC="#DEPLOY"
59+
60+
# Print the git commit message
61+
echo "Git commit message: ${GIT_COMMIT_DESC}"
62+
63+
if [[ $GIT_COMMIT_DESC == *"#DEPLOY"* ]]; then
64+
upload_to_google_play "app"
65+
fi

0 commit comments

Comments
 (0)