[www] Adding a website acceptance environment

If changes are detected in the docs or www directory, a website
build will be generated that pushes up to Netlify. This will allow
teams to validate web changes without requiring pulling down the
branch and building locally.

Signed-off-by: Adam Leff <adam@leff.co>
This commit is contained in:
Adam Leff 2017-04-05 18:30:00 -04:00
parent b527c30a2f
commit a1b7e3167e
5 changed files with 97 additions and 2 deletions

View file

@ -53,6 +53,21 @@ matrix:
bundler_args: "--without guard tools"
script: bundle exec rake $SUITE
env: SUITE=test:integration OS='default-fedora-24' DOCKER=true
- rvm: 2.4.1
sudo: false
cache:
apt: true
bundle: true
addons:
apt:
packages:
- curl
- nodejs
env:
- AFFECTED_DIRS="www"
- secure: "jdzXUhP1o7RkfSikZLKgUcCIaKqLjqWa35dnxWnz7qAQ2draRKa7I7cXmUv76BZkW8HBUUH11dOi8YOVxPYPOzaqvcTCfqNqGVxsT9epgWa7rA8aXMXkECp548ry1rYJQpti9zpwsoe2GQyNPr9vNiWMiyj51CaABmZ6JzmFEEqlZc8vqpqWeqJvIqaibQGk7ByLKmi4R44fVwFKIG39RuxV+alc/G4nnQ2zmNTFuy8uFGs5EghQvRytzWY+s2AKtDiZ0YXYOII1Nl1unXNnNoQt9oI209ztlSm1+XOuTPelW6bEIx5i7OZFaSRPgJzWnkGN85C9nBE08L2az9Jz18/rYJF4fdVRttdGskueyYI21lh1FwlAg51ZG0RfLTYk2Pq+k4c+NO1cfmGcaXBwihfD5BWqrILU5HHkYszXCSmgl4hscC7/BS4Kgcq2z32JJwV8B+x4XngM0G4uzIn1Soia3lZXEKdnfVsxFDdMQ7FK60F3uQlq/44LRkZujRhqfAKOiz+0tsLexWzj7wK+DJY9Y00CUfh7xcxRxDxFNpOv1FWYFB9lUlaOt3HDHgUoksqbURiUzhOZZzTE/1MAtF2K6mbpME5CbN08J88L5JBlb+CX79XCzj30lNMeS0I/dCRQEmkygr2eJYxvRO2qsBNuphs4SWk8NZyS/llVZFI="
before_install: ./ci/fast_pass.sh || exit 0
script: ./ci/deploy_website_to_acceptance.sh
allow_failures:
- env: SUITE="test:resources config=test/test.yaml" N=2
- env: SUITE="test:resources config=test/test-extra.yaml" N=2

View file

@ -0,0 +1,11 @@
set -eux
if [ "z${TRAVIS_PULL_REQUEST}" == "zfalse" ]; then
echo "This change is not a pull request - skipping acceptance deploy"
exit 0
fi
cd www
npm install -g gulp
bundle install
bundle exec rake www:acceptance

31
ci/fast_pass.sh Executable file
View file

@ -0,0 +1,31 @@
#!/bin/bash
#
# Check to see what directories have been affected by a change. If directories
# have not been affected, exit 0
#
# Since we can only stop the build early by calling "exit" from within the
# .travis.yml in the `before_install`, we exit non-zero if we want the build to
# be skipped, so we can do `|| exit 0` in the YAML.
echo "TAG: $TRAVIS_TAG"
echo "PR: $TRAVIS_PULL_REQUEST"
echo "COMMIT_RANGE: $TRAVIS_COMMIT_RANGE"
if [ -n "$STEAM_ROLLER" ]; then
echo 'STEAM_ROLLER is set. Not exiting and running everything.'
elif [ -z "$AFFECTED_DIRS" ]; then
# Don't do anything if $AFFECTED_DIRS is not set
echo 'AFFECTED_DIRS is not set. Not exiting and running everything.'
else
# If $AFFECTED_DIRS (a "|" separated list of directories) is set, see if we have
# any changes
# TRAVIS_COMMIT_RANGE is empty for the first push to a new branch (which is how our bot
# validates before merge), so if TRAVIS_COMMIT_RANGE is empty, we'll look for the
# last merge commit and check from there.
COMMIT_RANGE=${TRAVIS_COMMIT_RANGE:-$(git show :/^Merge --pretty=format:%H)}
git diff --name-only "$COMMIT_RANGE" | grep -qE "^($AFFECTED_DIRS)" || {
echo "No files in $AFFECTED_DIRS have changed. Skipping CI run."
exit 1
}
fi

View file

@ -1,8 +1,8 @@
PATH
remote: /Users/aleff/projects/inspec
specs:
inspec (1.18.0)
addressable (~> 2.5)
inspec (1.19.1)
addressable (~> 2.4)
faraday (>= 0.9.0)
hashie (~> 3.4)
json (>= 1.8, < 3.0)

View file

@ -18,6 +18,9 @@
$LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
require 'uri'
require 'net/http'
require_relative '../tasks/docs.rb'
require_relative '../tasks/shared.rb'
@ -135,6 +138,41 @@ namespace :www do
sh("git checkout #{current_branch}")
end
desc 'Release the site to the Netlify acceptance environment'
task :acceptance do
raise 'NETLIFYKEY environment variable not set' unless ENV.key?('NETLIFYKEY')
Log.info 'Cleaning the existing build directory'
Rake::Task['www:clean'].invoke
Log.info 'Building the docs'
Rake::Task['docs'].invoke
Log.info 'Building the site'
Rake::Task['www:build'].invoke
Log.info 'Creating zip file of website contents'
Dir.chdir(File.join(Dir.pwd, 'build')) do
sh('zip -r inspec-acceptance.zip *')
end
Log.info 'Uploading to Netlify'
uri = URI.parse('https://api.netlify.com/api/v1/sites/inspec-acceptance.netlify.com/deploys')
request = Net::HTTP::Post.new(uri)
request['Content-Type'] = 'application/zip'
request['Authorization'] = "Bearer #{ENV['NETLIFYKEY']}"
request.body = File.read(File.join(Dir.pwd, 'build', 'inspec-acceptance.zip'), mode: 'rb')
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
raise "Failed to upload to Netlify: #{response.code} -- #{response.body}" unless response.code == '200'
Log.info 'Removing zip file'
File.unlink(File.join(Dir.pwd, 'build', 'inspec-acceptance.zip'))
end
end
desc 'Full website release: includes local clean, docs build, site build, and then release'