-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update: デプロイ用スクリプトを 8b9257b の状態に戻してみる
- Loading branch information
Showing
2 changed files
with
25 additions
and
63 deletions.
There are no files selected for viewing
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
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 |
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