Skip to content

Instantly share code, notes, and snippets.

@ijin
Last active December 26, 2016 06:59
Show Gist options
  • Save ijin/364d46491e83a4f232cab32d2423e92c to your computer and use it in GitHub Desktop.
Save ijin/364d46491e83a4f232cab32d2423e92c to your computer and use it in GitHub Desktop.
Sync to S3 and notify via Slack
#!/bin/bash
set -x
export S3=`echo $1`
export SHA1=`echo ${CIRCLE_SHA1} | cut -c1-7`
export ENV=`echo $1 | rev | cut -d \- -f1 | rev`
aws --region $REGION s3 sync . s3://$S3/ --exclude 'circle.yml' --exclude '.*' --exclude '*.swp' --exclude 's3*.sh' --delete
if [ $? -eq 0 ]; then
export SL_COLOR="good"
export SL_TEXT="Sync success: $S3 - ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!"
export SL_ICON="http://cdn.dev.classmethod.jp/wp-content/uploads/2014/05/aws_icon-s3_white-200x200.png"
export EXIT=0
else
export SL_COLOR="danger"
export SL_TEXT="Sync failure: $S3 - ${CIRCLE_BRANCH} (<${CIRCLE_COMPARE_URL}|${SHA1}>) by ${CIRCLE_USERNAME} !!"
export SL_ICON="http://cdn.dev.classmethod.jp/wp-content/uploads/2014/05/aws_icon-s3_white-200x200.png"
export EXIT=1
fi
curl -X POST --data-urlencode 'payload={"username": "S3 ('"$CIRCLE_PROJECT_REPONAME"')", "icon_url": "'"$SL_ICON"'", "channel": "'"${CHANNEL:-#test}"'", "attachments": [{ "color": "'"$SL_COLOR"'", "text": "'"$SL_TEXT"'", "mrkdwn_in": ["text"] }] }' https://hooks.slack.com/services/${SLACK_HOOK}
exit $EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment