From b3a1469312ef7c59f51c3ac9bf7404dd311f29ee Mon Sep 17 00:00:00 2001 From: Dan Head Date: Wed, 9 Jan 2019 14:57:58 +0000 Subject: [PATCH] Optimize circleci build --- .circleci/config.yml | 60 ++++++++++++++++++++++++++++++++------------ build/deploy.sh | 7 +++++- 2 files changed, 50 insertions(+), 17 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index e701e81..939831f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,48 +1,76 @@ +defaults: &defaults + working_directory: ~/tmp/windycoys + docker: + - image: circleci/node:10.15 + version: 2 jobs: - test: - docker: - - image: circleci/node:10.0.0 + install: + <<: *defaults steps: + - attach_workspace: + at: ~/tmp/windycoys - checkout - run: name: Install dependencies command: npm install + - persist_to_workspace: + root: . + paths: . + test: + <<: *defaults + steps: + - attach_workspace: + at: ~/tmp/windycoys - run: name: Run tests command: npm test - build-latest: - docker: - - image: circleci/node:10.0.0 + build: + <<: *defaults steps: - - checkout - - run: - name: Install rsync - command: sudo apt install -y rsync - - run: - name: Install dependencies - command: npm install + - attach_workspace: + at: ~/tmp/windycoys - run: name: Build CSS and JavaScript command: npm run build - run: name: Generate timestamp command: bash build/generate_timestamp.sh + - persist_to_workspace: + root: . + paths: . + deploy: + <<: *defaults + steps: + - attach_workspace: + at: ~/tmp/windycoys + - run: + name: Install rsync + command: sudo apt install -y rsync - run: name: Deploy theme command: bash build/deploy.sh - run: name: Purge Cloudflare cache command: bash build/purge_cache.sh + workflows: version: 2 - build-latest: + test-deploy: jobs: - - test - - build-latest: + - install + - test: requires: + - install + - build: + requires: + - install + - deploy: + requires: + - build - test filters: branches: only: - master + - develop diff --git a/build/deploy.sh b/build/deploy.sh index 5cbcdfb..d37d014 100755 --- a/build/deploy.sh +++ b/build/deploy.sh @@ -1,10 +1,15 @@ #!/usr/bin/env bash +# Ensure target is defined +[ -z "$CIRCLE_BRANCH" ] && { echo >&2 "Error: Build target not defined. Aborting."; exit 1; } + # Test rsync is installed and ENV variables are set hash rsync 2>/dev/null || { echo >&2 "Error: rsync is not installed. Aborting."; exit 1; } [ -z "$SSH_IP" ] && { echo >&2 "Error: SSH_IP is missing. Aborting."; exit 1; } [ -z "$SSH_USER" ] && { echo >&2 "Error: SSH_USER is missing. Aborting."; exit 1; } +echo "Deploying to $CIRCLE_BRANCH" + # Deploy theme with rsync rsync -e "ssh -o StrictHostKeyChecking=no" -avzuh --progress \ - theme/. $SSH_USER@$SSH_IP:~/windycoys_theme + theme/. $SSH_USER@$SSH_IP:~/windycoys_theme_$CIRCLE_BRANCH