Created
February 22, 2016 00:58
-
-
Save reinkim/903f45f751052deb16af to your computer and use it in GitHub Desktop.
Fetch upstream and the build & copy binary packge to host (w/ slack notification)
This file contains 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 | |
CHANNEL=${CHANNEL:-"build"} | |
SLACK_DOMAIN=${SLACK_DOMAIN:-"your-project"} | |
SLACK_TOKEN=${SLACK_TOKEN:-"some-slack-token"} | |
BOT=${BOT:-"buildbot"} | |
REPOSITORY=${REPOSITORY:-"https://github.com/github/hello-world"} | |
DEST_HOST=${DEV_HOST:-"dest.example.com"} | |
cd ${BUILD_HOME} | |
git remote update | |
LOCAL=$(git rev-parse HEAD) | |
UPSTREAM=$(git rev-parse master@{upstream}) | |
if [[ $LOCAL == $UPSTREAM ]]; then | |
exit 0 | |
fi | |
curl -X POST "https://${SLACK_DOMAIN}.slack.com/services/hooks/incoming-webhook?token=${SLACK_TOKEN}" \ | |
-H 'Content-Type: application/json' \ | |
-d "{\"channel\": \"${CHANNEL}\", \"username\": \"${BOT}\", \"icon_emoji\": \":rocket:\", \"text\": \"저장소가 업데이트 되었습니다.\"}" | |
git pull | |
COMMIT_NAME=$(git log --pretty=format:'(%h) %s %cd' -1) | |
COMMIT_HASH=$(git log --pretty=format:'%H' -1) | |
curl -X POST "https://${SLACK_DOMAIN}.slack.com/services/hooks/incoming-webhook?token=${SLACK_TOKEN}" \ | |
-H 'Content-Type: application/json' \ | |
-d "{\"channel\": \"${CHANNEL}\", \"username\": \"${BOT}\", \"icon_emoji\": \":rocket:\", \"text\": \"${COMMIT_NAME}: Build started.\\n${REPOSITORY}/commit/${COMMIT_HASH}/\"}" | |
rm -rf *.rpm && make clean && make -j$(nproc) && find . -name '*.so' -exec strip {} ';' && make package && scp *.rpm ${DEST_HOST}: | |
if [[ "$?" == "0" ]]; then | |
curl -X POST "https://${SLACK_DOMAIN}.slack.com/services/hooks/incoming-webhook?token=${SLACK_TOKEN}" \ | |
-H 'Content-Type: application/json' \ | |
-d "{\"channel\": \"${CHANNEL}\", \"username\": \"${BOT}\", \"icon_emoji\": \":rocket:\", \"text\": \"${COMMIT_NAME}: Package uploaded. (${DEST_HOST})\"}" | |
else | |
curl -X POST 'https://${SLACK_DOMAIN}.slack.com/services/hooks/incoming-webhook?token=${SLACK_TOKEN}' \ | |
-H 'Content-Type: application/json' \ | |
-d "{\"channel\": \"${CHANNEL}\", \"username\": \"${BOT}\", \"icon_emoji\": \":goberserk:\", \"text\": \"${COMMIT_NAME}: Build failed.\"}" | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment