Skip to content

Instantly share code, notes, and snippets.

@erdemolkun
Created May 30, 2016 14:36
Show Gist options
  • Save erdemolkun/9e9b748724447797e9333cf3176119c9 to your computer and use it in GitHub Desktop.
Save erdemolkun/9e9b748724447797e9333cf3176119c9 to your computer and use it in GitHub Desktop.
Circle CI Release
#!/usr/bin/env bash
STARTTIME=$(date +%s)
HOCKEY_ID=$1
APK_NAME=$2
USE_RELEASE_NOTES=$3
printf "HOCKEY APPLICATION ID $HOCKEY_ID\n"
printf "BUILD APK NAME $APK_NAME\n"
if [ -z "${USE_RELEASE_NOTES}" ]; then
printf "> Reading Commit Messages...\n"
#Find Last Build Commit Id
#CIRCLE_COMPARE_URL=https://github.com/dtprotel/protel360/compare/e8f67d33a268...1d340f4990b5
#Parsing this variable inside circle ci exports.
#Get Commit Ids Part
COMMIT_ID_PARTS=""
IFS='/'
splittedArray=$CIRCLE_COMPARE_URL
for x in $splittedArray
do
COMMIT_ID_PARTS=$x
done
printf "> Build is between commits : $COMMIT_ID_PARTS\n"
#Get Commit Id Part
IFS='...'
COMMIT_ID=""
splittedArray=$COMMIT_ID_PARTS
for x in $splittedArray
do
if [ -z "${COMMIT_ID}" ]; then
COMMIT_ID=$x
fi
done
printf "> FIRST COMMIT_ID : $COMMIT_ID\n"
export COMMIT_MESSAGE=`git log --pretty=format:"- %s" $COMMIT_ID...HEAD`
export LAST_COMMIT_MESSAGE=`git log -1 --pretty=%B`
printf "> COMMIT_MESSAGE :\n$COMMIT_MESSAGE\n"
NOTES=$COMMIT_MESSAGE
if [[ $LAST_COMMIT_MESSAGE == *"[no_release]"* ]]
then
printf "Not Releasing. Quit.\n"
exit 0
fi
else
printf "> Reading Release Notes...\n"
export NOTES_PATH="RELEASE_NOTES.md"
export VERSION_NAME=`cat app-build.properties | sed -n -e 's/^\s*version_name\s*=\s*//p'`
export LOG_PYTHON=`python -m markdown RELEASE_NOTES.md`
# export NOTES_READ=`python -m markdown $NOTES_PATH | $GOPATH/bin/pup "h2:contains(\"$(cat version.properties | sed -n -e 's/^\s*version_name\s*=\s*//p')\") + pre code text{}"`
export NOTES_READ=`python -m markdown $NOTES_PATH | pup "h2:contains(\"$VERSION_NAME\") + pre code text{}"`
# NOTES=$(< $NOTES_PATH) #read notes file.
printf "> NOTES :\n $NOTES_READ\n"
NOTES=$NOTES_READ
fi
printf "> Uploading started\n"
curl \
--progress-bar \
-F "status=2" \
-F "notify=0" \
-F "notes=$NOTES" \
-F "notes_type=1" \
-F "ipa=@app/build/outputs/apk/$APK_NAME" \
-H "X-HockeyAppToken: $HOCKEY_API_TOKEN" \
https://rink.hockeyapp.net/api/2/apps/$HOCKEY_ID/app_versions/upload
if [ $? -eq 0 ]
then
END=$(date +%s)
DIFF_TIME=$(( $END - $STARTTIME ))
printf "\n> Uploading completed in $DIFF_TIME seconds\n"
else
printf "\n> Uploading failed\n"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment