Skip to content

Commit a34a363

Browse files
committed
Testing CI integration #DEPLOY #RELEASE
1 parent 118a4ba commit a34a363

File tree

5 files changed

+71
-29
lines changed

5 files changed

+71
-29
lines changed

.circleci/config.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ jobs:
5858
name: Save APK Files
5959
path: /tmp/artifacts
6060
destination: build
61-
61+
62+
# Publish release to github if applicable
63+
- run:
64+
name: Publish release to Github
65+
command: scripts/github-release.sh
66+
6267
# Upload to beta if requested and then publish webhooks
6368
- run:
6469
name: Publish to Google Play

scripts/config.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
ENV_VAR_PREFIX="ANDROID_NETWORK_TOOLS"
3+
4+
APP_NAME="Android Network Tools Sample App"
5+
6+
# Slack webhook settings
7+
SLACK_CHANNEL="#mat-testing"
8+
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/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"
9+
ICON_URL="https://github.com/stealthcopter/AndroidNetworkTools/raw/master/app/src/main/res/mipmap-xhdpi/ic_launcher.png"
10+
11+
# Settings for github releases
12+
GITHUB_RELEASE_MODULE="library"
13+
GITHUB_RELEASE_DESC="This release was automatically generated by the CI server"
14+
GITHUB_RELEASE_URL="https://api.github.com/repos/stealthcopter/AndroidNetworkTools/releases"
15+
GITHUB_RELEASE_TOKEN=$ANDROID_NETWORK_TOOLS_GITHUB_RELEASE_TOKEN
16+
17+
# Fires a webhook to slack to notify of successful upload to beta
18+
function webhook {
19+
20+
gradle_app_name="$1"
21+
message="$2"
22+
git_hash=`git rev-parse --short HEAD`
23+
version=`cat ${gradle_app_name}/build.gradle | grep -m 1 versionName | cut -d'"' -f 2`
24+
25+
# TESTING WEBHOOK https://hooks.slack.com/services/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
26+
27+
echo $message
28+
echo $channel $gradle_app_name $APP_NAME $version $ICON_URL
29+
30+
curl -X POST --data-urlencode 'payload={"channel": "'"$SLACK_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"'"}' $SLACK_WEBHOOK_URL
31+
32+
}

scripts/cp-env-to-properties.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#
33
# Copy env variables to app module gradle properties file
44
#
5+
. config.sh
56

67
set +x // dont print the next lines on run script
78
mkdir ~/.gradle
8-
printenv | tr ' ' '\n' | grep ANDROID_NETWORK_TOOLS > ~/.gradle/gradle.properties
9+
printenv | tr ' ' '\n' | grep $ENV_VAR_PREFIX > ~/.gradle/gradle.properties
910
set -x

scripts/github-release.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
. config.sh
3+
4+
function create_github_release {
5+
6+
version=`cat $1/build.gradle | grep -m 1 versionName | cut -d'"' -f 2`
7+
8+
curl -v -i -X POST -H "Content-Type:application/json" -H "Authorization: token $GITHUB_RELEASE_TOKEN" -d '{"tag_name": "'$version'","name": "'$version'","body": '$GITHUB_RELEASE_DESC',"draft": true}' $GITHUB_RELEASE_URL
9+
10+
}
11+
12+
# Only deploy releases if we are on the master branch
13+
# if [[ $GIT_CURRENT_BRANCH != "master" ]]; then
14+
# echo "Not on master branch, so not deploying release"
15+
# exit 0
16+
# fi
17+
18+
if [[ $GIT_COMMIT_DESC == *"#RELEASE"* ]]; then
19+
echo "Creating github release"
20+
if create_github_release $GITHUB_RELEASE_MODULE; then
21+
webhook "${1}" "Created github release"
22+
else
23+
webhook "${1}" "Failed to create github release :("
24+
fi
25+
fi

scripts/upload-apks.sh

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
#!/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="Android Network Tools 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-
}
2+
. config.sh
233

244
# Uploads a build to Beta
255
function upload_to_beta {
@@ -43,17 +23,16 @@ function upload_to_google_play {
4323
fi
4424
}
4525

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
26+
# # Only deploy releases if we are on the master branch
5127
# if [[ $GIT_CURRENT_BRANCH != "master" ]]; then
52-
# echo "Not on master branch, so not deploying"
28+
# echo "Not on master branch, so not deploying release"
5329
# exit 0
5430
# fi
5531

5632

33+
GIT_COMMIT_DESC=`git log -n 1 $CIRCLE_SHA1`
34+
GIT_CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
35+
5736
# Print the git commit message
5837
echo "Git commit message: ${GIT_COMMIT_DESC}"
5938

0 commit comments

Comments
 (0)