.circleci/config.yml
version: 2
jobs:
build:
branches:
ignore:
- gh-pages
docker:
- image: circleci/node:10
environment:
- SOURCE_BRANCH: master
- TARGET_BRANCH: gh-pages
steps:
- checkout
- run:
name: Update NPM
command: 'sudo npm install -g npm@latest'
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}
- run:
name: Install dependencies
command: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}
paths:
- ./node_modules
- run:
name: Run tests
command: npm test
- deploy:
name: Deploy
command: |
if [ $CIRCLE_BRANCH == $SOURCE_BRANCH ]; then
git config --global user.email $GH_EMAIL
git config --global user.name $GH_NAME
git clone $CIRCLE_REPOSITORY_URL out
cd out
git checkout $TARGET_BRANCH || git checkout --orphan $TARGET_BRANCH
git rm -rf .
cd ..
npm run build:example
cp -a dist/. out/.
mkdir -p out/.circleci && cp -a .circleci/. out/.circleci/.
cd out
git add -A
git commit -m "Automated deployment to GitHub Pages: ${CIRCLE_SHA1}" --allow-empty
git push origin $TARGET_BRANCH
fi