-
-
Save kenjiskywalker/12728de1e08795a03ffde0e2bb4d9e2a to your computer and use it in GitHub Desktop.
Sync to S3 and notify via Slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -x | |
export SHA1=`echo ${CIRCLE_SHA1} | cut -c1-7` | |
# 引数で配布先のbucketを分けたい | |
if [ $#$ -ne 1 ]; then | |
export SL_COLOR="danger" | |
export SL_TEXT="Sync failure: Not enough args in CircleCI: $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 | |
export STAGE=`echo $1` | |
export S3_BUCKET="${STAGE}.${DOMAIN}" | |
aws --region $REGION s3 sync ./dist/ s3://$S3_BUCKET/ --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", "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