Skip to content

Instantly share code, notes, and snippets.

@TrevorJTClarke
Created October 3, 2016 20:46
Show Gist options
  • Save TrevorJTClarke/b2917b610c54b70f8cdde6b7fc125a99 to your computer and use it in GitHub Desktop.
Save TrevorJTClarke/b2917b610c54b70f8cdde6b7fc125a99 to your computer and use it in GitHub Desktop.
Auto Deploy to ionic, once tests pass with your favorite CI!
#!/bin/bash
# Author: @trevorjtclarke
# Initialize a deployment based on your environment
deployEnv='dev'
branch=`git rev-parse --abbrev-ref HEAD`
message=`git log -1 --pretty=%B`
versionstring=`grep 'version":[^"]*"' package.json`
version='-'
emoji=':clap:'
# Find that version there!
if [[ $versionstring =~ ([[:digit:]]{1}.)[[:digit:]]{1}.[[:digit:]]{1,3} ]]; then
version=${BASH_REMATCH[0]}
fi
# Base the deployment on the branch
[ "$branch" == "master" ] && deployEnv='production' emoji=':smile:'
[ "$branch" == "staging" ] && deployEnv='staging' emoji=':smile:'
[ "$branch" == "development" ] && deployEnv='dev'
# Flag for non release, only if necessary
if [ "$1" == "dontrelease" ]
then
echo "No Deployment"
else
# runs an npm build command, use only if needed pre-deploy
eval "npm run $deployEnv"
# Login based off env variables, store these somewhere secure
eval "ionic login --email $ionicioemail --password $ioniciopass"
# Push into ionic!
eval "ionic upload --note \"$message, v$version\" --deploy=$deployEnv"
curl -X POST -H 'Content-type: application/json' --data "{ \"icon_emoji\": \"$emoji\", \"username\": \"$deployEnv\", \"text\": \"App Update!\nVersion:$version Environment:$deployEnv\nBuild Note: $message\nThis build has been auto-released!\" }" https://hooks.slack.com/services/YOUR_SLACK_API_ENDPOINT_KEY_HERE
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment