Skip to content

Instantly share code, notes, and snippets.

@chrisroane
Created September 1, 2017 18:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisroane/116f4ab90dafc3534d412db7f2988b01 to your computer and use it in GitHub Desktop.
Save chrisroane/116f4ab90dafc3534d412db7f2988b01 to your computer and use it in GitHub Desktop.
# https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs
defaults: &defaults
docker:
- image: chrisroane/frontline-docker-image:0.0.4
working_directory: ~/medstat
environment:
TZ: "/usr/share/zoneinfo/America/New_York"
version: 2
jobs:
build:
<<: *defaults
parallelism: 2
steps:
- checkout
# If the cache was already created, use that.
- restore_cache:
key: v1-dependency-cache
# Install the necessary dependencies.
- run:
name: Install Dependencies
command: |
chmod 0777 ./.circleci/set-up-globals.sh
./.circleci/set-up-globals.sh
# Make sure the PHP + JS code passes validation.
- run:
name: Linting
command: case $CIRCLE_NODE_INDEX in 0) gulp phpcs --exit ;; 1) gulp eslint ;; esac
# Run aquifer build.
- run:
name: Aquifer Build
command: aquifer build
# Install Registry rebuild module.
- run:
name: Install Registry Rebuild Module
command: drush @medstat.local dl registry_rebuild-7.x-2.3 -n
# Start Selenium.
- run:
name: Start Selenium
command: java -jar selenium-server-standalone-2.48.2.jar
background: true
# Start Solr.
- run:
name: Start Solr
command: cd $HOME/solr/example/; java -jar start.jar >> $HOME/solr.log
background: true
# Save the cache directories.
- save_cache:
key: v1-dependency-cache
paths:
- $HOME/.composer/cache
- vendor
- .aquifer
- ~/.drush
- ~/solr
- node_modules
- $HOME/.terminus
- $HOME/terminus
# Persist the cache in the workspace.
#- persist_to_workspace:
# root: .
# paths:
# - vendor
# - .aquifer
# - node_modules
# Grabs the latest db backup from the Fresh database on pantheon.
database:
<<: *defaults
steps:
- checkout
# Attach the workspace.
- attach_workspace:
at: /tmp
# Need to copy the cached folders into the working directory.
#- run:
# name: Copy workspace cached directories
# command: |
# cp -r /tmp/vendor .
# cp -r /tmp/.aquifer .
# cp -r /tmp/node_modules .
# First restore the cache.
- restore_cache:
keys:
- v1-dependency-cache
- v1-db-cache
# Prevent ssh logs which muddy up our sql dump.
- run:
name: SSH Logs
command: echo $'Host *\nLogLevel quiet' >> ~/.ssh/config
# Get the canonical database and files.
- run:
name: Copy Fresh DB Backup
no_output_timeout: 720
command: aquifer run fresh-ci
# Prevent issues with the files directory.
- run:
name: Files Directory Permissions
command: |
sudo chmod -R g+s ~/medstat/files
sudo chmod -R 777 ~/medstat/files
# Run updates, cache clears, etc.
- run:
name: Final Aquifer Command - Clear drupal caches
command: aquifer run local
# Save the db cache directory.
- save_cache:
key: v1-db-cache
paths:
- db
# Persist the cache in the workspace.
- persist_to_workspace:
root: .
paths:
- db
# Run tests.
behat_tests:
<<: *defaults
parallelism: 2
steps:
- checkout
# Attach the workspace.
- attach_workspace:
at: /tmp
- restore_cache:
keys:
- v1-dependency-cache
- v1-db-cache
# Need to copy the cached folders into the working directory.
#- run:
# name: Copy workspace cached directories
# command: |
# cp -r /tmp/vendor .
# cp -r /tmp/.aquifer .
# cp -r /tmp/node_modules .
# cp -r /tmp/db .
# Create error screenshots directory.
- run:
name: Create Error Screenshots Directory
command: |
mkdir behat_screenshots
chmod 777 behat_screenshots
# Run Behat Tests in parallel.
- run:
name: Run Behat Tests
command: case $CIRCLE_NODE_INDEX in 0) behat -c behat.local.yml --tags "@node-0&&~@wip" ;; 1) behat -c behat.local.yml --tags "@node-1&&~@wip" ;; esac
# Store the artifacts.
- store_artifacts:
path: /tmp/artifacts
destination: build
# Add a file to the error screenshots directory so that the directory isn't empty (else copy will fail).
- run:
name: Move Screenshots
command: |
touch behat_screenshots/keep
cp behat_screenshots/* $CIRCLE_ARTIFACTS/
rm $CIRCLE_ARTIFACTS/keep
# This is meant to push the code from github master to the Pantheon dev environment.
push_to_pantheon_dev:
<<: *defaults
steps:
- checkout
# Attach the workspace.
- attach_workspace:
at: /tmp
- restore_cache:
keys:
- v1-dependency-cache
- v1-db-cache
# Need to copy the cached folders into the working directory.
- run:
name: Copy workspace cached directories
command: |
cp -r /tmp/vendor .
cp -r /tmp/.aquifer .
cp -r /tmp/node_modules .
cp -r /tmp/db .
# Deploy to the master branch on Pantheon.
- run:
name: Deploy Code to Dev Pantheon
command: aquifer deploy-git -m "Automated deployment at $CIRCLE_SHA1" -b "master" -n "Deploy Bot" -a "devs@fourkitchens.com"
# Refresh the dev environment against the new codebase.
- run:
name: Final Aquifer Command - Clear drupal caches on Pantheon Dev
command: aquifer run dev
workflows:
version: 2
build_and_test:
jobs:
# Install the dev dependencies.
- build
# Grab the fresh database.
- database:
requires:
- build
# Run the behat tests.
- behat_tests:
requires:
- build
- database
# Push to the Pantheon Dev environment.
- push_to_pantheon_dev:
requires:
- build
- database
- behat_tests
filters:
branches:
only: master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment