Skip to content

Commit

Permalink
Update: デプロイ用スクリプトを 8b9257b の状態に戻してみる
Browse files Browse the repository at this point in the history
  • Loading branch information
kubosho committed Jul 11, 2015
1 parent c775366 commit bfb2fe2
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 63 deletions.
86 changes: 25 additions & 61 deletions .bin/deploy-to-gh-pages.sh
Original file line number Diff line number Diff line change
@@ -1,84 +1,48 @@
#!/bin/bash

function init {
repo=$1
target_dir=$2
readonly REPOSITORY="https://$GH_TOKEN@github.com/kubosho/Nico.git"
readonly PROJECT_ROOT=`git rev-parse --show-toplevel`
readonly BUILD_DIR=$PROJECT_ROOT/build
readonly PUBLISH_BRANCH='gh-pages'

function init {
# build directory doesn't exist?
if [ ! -d "$target_dir" ]; then
mkdir $target_dir
if [ ! -d "$BUILD_DIR" ]; then
mkdir $BUILD_DIR
fi

if [ ! -d $target_dir/.git ]; then
rm -rf $target_dir
git clone --quiet $repo $target_dir
fi
}
cd $PROJECT_ROOT

function sync {
target_branch=$1
if [ ! -d $BUILD_DIR/.git ]; then
rm -rf $BUILD_DIR
git clone --quiet $1 $BUILD_DIR
fi

git checkout --orphan $target_branch
cd $BUILD_DIR
git checkout --orphan $2
git fetch origin
git reset --hard origin/$target_branch
git reset --hard origin/$PUBLISH_BRANCH
}

function clean {
target_dir=$1

rm -rf $target_dir/*.*
rm -rf $BUILD_DIR/*.*
}

function build {
base_dir=$1
output_dir=$2

npm run release
cp -r $base_dir/dist/* $output_dir
cp -r $PROJECT_ROOT/dist/* $BUILD_DIR
}

function commit {
base_dir=$1
output_dir=$2

cd $base_dir

function push_to_branch {
cd $PROJECT_ROOT
sha1=`git rev-parse $(git log --oneline -n 1 . | awk '{{print $1}}')`

cd $output_dir

cd $BUILD_DIR
git add -A
git commit -m "[ci skip] Update with ${sha1}"
git push --quiet $REPOSITORY $PUBLISH_BRANCH
}

function push_to_ghpages {
repo=$1
branch=$2

git push --quiet $repo $branch
}

# ------------------------------

readonly PROJECT_ROOT=`git rev-parse --show-toplevel`
readonly REMOTE_REPOSITORY=`git config --get remote.origin.url`
readonly BUILD_DIR=$PROJECT_ROOT/build
readonly PUBLISH_BRANCH='gh-pages'

base_repo=`echo $REMOTE_REPOSITORY | sed -e 's/ssh:\/\/git@github\.com\(.*\)/https:\/\/$GH_TOKEN@github\.com\1\.git/'`
repo=$base_repo

if [ "$GH_TOKEN" = "" ]; then
repo=$REMOTE_REPOSITORY
else
repo=$base_repo
fi

cd $PROJECT_ROOT
init $repo $BUILD_DIR
cd $BUILD_DIR
sync $PUBLISH_BRANCH
clean $BUILD_DIR
build $PROJECT_ROOT $BUILD_DIR
commit $PROJECT_ROOT $BUILD_DIR
push_to_ghpages $repo $PUBLISH_BRANCH
init $REPOSITORY $PUBLISH_BRANCH
clean
build
push_to_branch $PUBLISH_BRANCH
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,5 @@ script:
- npm start

after_success:
- git config credential.helper "store --file=.git/credentials"
- echo "https://${GH_TOKEN}:@github.com" > .git/credentials
- '[ "$TRAVIS_BRANCH" == "master" ] && [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [
"$GH_TOKEN" ] && ./.bin/deploy-to-gh-pages.sh > /dev/null'

0 comments on commit bfb2fe2

Please sign in to comment.