2019-09-15 19:03:50 +00:00
|
|
|
version: 2
|
|
|
|
jobs:
|
|
|
|
build:
|
|
|
|
docker:
|
|
|
|
- image: cibuilds/hugo:0.57
|
|
|
|
working_directory: ~/project
|
|
|
|
environment:
|
|
|
|
BRANCH: master
|
2019-09-15 19:06:05 +00:00
|
|
|
TARGET_REPO: moontools-docs/moontools-docs.github.io.git
|
2019-09-15 19:49:31 +00:00
|
|
|
DOCS_CHECKOUT_DIR: ~/docs
|
|
|
|
HUGO_BUILD_DIR: ~/build
|
2019-09-15 19:03:50 +00:00
|
|
|
steps:
|
|
|
|
- checkout
|
2019-09-15 19:31:37 +00:00
|
|
|
- run:
|
|
|
|
command: git submodule sync && git submodule update --init
|
2019-09-15 19:03:50 +00:00
|
|
|
- run:
|
|
|
|
name: "Run Hugo"
|
2019-09-15 19:31:37 +00:00
|
|
|
command: HUGO_ENV=production hugo -v -d $HUGO_BUILD_DIR
|
2019-09-15 19:03:50 +00:00
|
|
|
- deploy:
|
2019-09-15 19:21:55 +00:00
|
|
|
name: "Deploy website"
|
2019-09-15 19:03:50 +00:00
|
|
|
command: |
|
|
|
|
if [ "${CIRCLE_BRANCH}" = "master" ]; then
|
|
|
|
echo -e "Starting to deploy to Github Pages\n"
|
2019-09-15 19:16:59 +00:00
|
|
|
cd ~/project
|
2019-09-15 19:03:50 +00:00
|
|
|
git config --global user.email "builds@circleci.com"
|
|
|
|
git config --global user.name "CircleCI"
|
|
|
|
#using token clone gh-pages branch
|
2019-09-15 19:31:37 +00:00
|
|
|
git clone --quiet --branch=$CIRCLE_BRANCH https://${GH_TOKEN}@github.com/$TARGET_REPO $DOCS_CHECKOUT_DIR > /dev/null
|
2019-09-15 19:49:31 +00:00
|
|
|
#rsync
|
2019-09-15 19:03:50 +00:00
|
|
|
echo "rsync built code with checked out code..."
|
2019-09-15 19:49:31 +00:00
|
|
|
rsync -a --exclude=.git --delete $HUGO_BUILD_DIR/ $DOCS_CHECKOUT_DIR/bonk
|
2019-09-15 19:03:50 +00:00
|
|
|
#add, commit and push files
|
|
|
|
echo "add files to git..."
|
2019-09-15 19:49:31 +00:00
|
|
|
cd $DOCS_CHECKOUT_DIR
|
2019-09-15 19:31:37 +00:00
|
|
|
git add --all
|
2019-09-15 19:03:50 +00:00
|
|
|
echo "commit files to git repository..."
|
|
|
|
if git commit -m "CircleCI build $CIRCLE_BUILD_NUM pushed to Github Pages" ; then
|
|
|
|
echo "git push files with force..."
|
|
|
|
git push -fq origin $BRANCH > /dev/null
|
|
|
|
echo -e "Deploy completed\n"
|
|
|
|
else
|
|
|
|
echo "Content not changed, nothing to deploy"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Not master branch, dry run only"
|
|
|
|
fi
|