Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[www] Adding a website acceptance environment #1634

Merged
merged 2 commits into from
Apr 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ./support/ci/fast_pass.sh || exit 0
script: ./support/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
Expand Down
11 changes: 11 additions & 0 deletions support/ci/deploy_website_to_acceptance.sh
Original file line number Diff line number Diff line change
@@ -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 changes: 31 additions & 0 deletions support/ci/fast_pass.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions www/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
38 changes: 38 additions & 0 deletions www/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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'
Expand Down