/tachikomakun.sh Secret
Created
August 22, 2017 04:07
Star
You must be signed in to star a gist
tachikomakun
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 | |
if [[ ! $BUILD_FOR =~ ^[-_0-9a-zA-Z]+$ ]]; then | |
echo 'Invalid $BUILD_FOR.' | |
fi | |
if [ ! $BASE_REMOTE_BRANCH ]; then | |
BASE_REMOTE_BRANCH=origin/master | |
fi | |
if [ ! $PULL_REQUEST_BASE ]; then | |
PULL_REQUEST_BASE=master | |
fi | |
if [ ! $TACHIKOMA_KUN_PATH ]; then | |
TACHIKOMA_KUN_PATH=$PWD | |
fi | |
if [ ! $GITHUB_OWNER ]; then | |
GITHUB_OWNER=moneyforward | |
fi | |
REPOSITORY_PREFIX=https://$GITHUB_ACCESS_TOKEN:x-oauth-basic@github.com/$GITHUB_OWNER | |
PULL_REQUEST_TITLE='Exec tachikoma kun update' | |
REPOSITORY_PATH=repos/$BUILD_FOR | |
REPOSITORY_URL=$REPOSITORY_PREFIX/$BUILD_FOR.git | |
FORKED_REPOSITORY_URL=${REPOSITORY_URL//$GITHUB_OWNER/$GITHUB_ACCOUNT} | |
cd $TACHIKOMA_KUN_PATH | |
if [ -d $REPOSITORY_PATH ];then | |
rm -fr $REPOSITORY_PATH | |
fi | |
git clone $REPOSITORY_URL $REPOSITORY_PATH | |
cd $REPOSITORY_PATH | |
HEAD_DATE=$(date +%Y%m%d_%H-%M-%S) | |
HEAD=tachikoma/update-$HEAD_DATE | |
git config user.name $COMMITER_NAME | |
git config user.email $COMMITER_EMAIL | |
git checkout -b $HEAD $BASE_REMOTE_BRANCH | |
export BUNDLE_PATH=./vendor/bundle | |
export BUNDLE_BUILD__LIBV8=--with-system-v8 | |
export BUNDLE_BUILD__THERUBYRACER=--with-v8-dir | |
bundle update $BUNDLE_UPDATE_GEMS | |
git add Gemfile.lock | |
git commit -m "Bundle update $HEAD_DATE" | |
export BUNDLE_GEMFILE=$TACHIKOMA_KUN_PATH/Gemfile | |
# 名前つけないとhttps with tokenでpushできなかったので一旦名前つけている | |
# 後続の処理で余計なremote urlがあるとoriginにPRしてくれないので、すぐに消す | |
git remote add forked $FORKED_REPOSITORY_URL | |
bundle exec git httpsable-push forked $HEAD | |
git remote remove forked | |
bundle exec pull-request-create \ | |
--title="$PULL_REQUEST_TITLE $HEAD_DATE" \ | |
--base=$PULL_REQUEST_BASE \ | |
--head=$GITHUB_ACCOUNT:$HEAD | |
# check Gemfile.lock diff | |
git diff --name-only $BASE_REMOTE_BRANCH \ | |
| grep ".*[gG]emfile.lock$" || RETURN_CODE=$? | |
case "$RETURN_CODE" in | |
"" ) echo "found" ;; | |
"1" ) | |
echo "not found" | |
exit 0 ;; | |
* ) | |
echo "Error" | |
exit $RETURN_CODE ;; | |
esac | |
# Post comment with CompareLinker | |
git diff --name-only $BASE_REMOTE_BRANCH \ | |
| grep ".*[gG]emfile.lock$" \ | |
| xargs bundle exec compare-linker-wrapper --base $BASE_REMOTE_BRANCH \ | |
--formatter CompareLinker::Formatter::Markdown \ | |
| bundle exec text-to-checkstyle \ | |
| bundle exec saddler report \ | |
--require saddler/reporter/github \ | |
--reporter Saddler::Reporter::Github::PullRequestComment |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment