version: 2 jobs: build: docker: - image: cibuilds/hugo:0.57 working_directory: ~/project environment: BRANCH: master TARGET_REPO: moontools-docs/moontools-docs.github.io.git DOCS_CHECKOUT_DIR: ~/build HUGO_BUILD_DIR: ~/build/bonk steps: - checkout - run: command: git submodule sync && git submodule update --init - run: name: "Run Hugo" command: HUGO_ENV=production hugo -v -d $HUGO_BUILD_DIR - deploy: name: "Deploy website" command: | if [ "${CIRCLE_BRANCH}" = "master" ]; then echo -e "Starting to deploy to Github Pages\n" cd ~/project git config --global user.email "builds@circleci.com" git config --global user.name "CircleCI" #using token clone gh-pages branch git clone --quiet --branch=$CIRCLE_BRANCH https://${GH_TOKEN}@github.com/$TARGET_REPO $DOCS_CHECKOUT_DIR > /dev/null #go into directory and copy data we're interested in to that directory cd $HUGO_BUILD_DIR echo "rsync built code with checked out code..." rsync -r --exclude=.git --delete ~/project/public $HUGO_BUILD_DIR #add, commit and push files echo "add files to git..." git add --all 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