2017-03-22 15:58:12 +00:00
|
|
|
#!/usr/bin/env rake
|
2016-09-22 19:26:19 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
# Copyright:: Copyright (c) 2015 Chef Software, Inc.
|
|
|
|
# License:: Apache License, Version 2.0
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
|
|
|
|
2017-03-22 15:58:12 +00:00
|
|
|
$LOAD_PATH.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
|
|
|
|
|
|
|
|
require_relative '../tasks/docs.rb'
|
|
|
|
require_relative '../tasks/shared.rb'
|
|
|
|
|
|
|
|
task :default do
|
|
|
|
puts 'There is no default task - see `rake --tasks` for available www-related tasks.'
|
|
|
|
puts 'Run `rake www` to do a full website release.'
|
|
|
|
exit(1)
|
|
|
|
end
|
2016-09-22 19:26:19 +00:00
|
|
|
|
|
|
|
namespace :www do
|
2016-09-23 13:26:22 +00:00
|
|
|
desc 'Builds the tutorial contents'
|
|
|
|
task :tutorial do
|
2017-03-22 15:58:12 +00:00
|
|
|
Log.section 'Build the online tutorial in tutorial/'
|
|
|
|
sh('cd tutorial/ && npm install')
|
|
|
|
sh('cd tutorial/ && gulp build')
|
|
|
|
Verify.file('tutorial/dist/index.html')
|
|
|
|
Verify.file('tutorial/dist/css/inspec_tutorial.css')
|
|
|
|
Verify.file('tutorial/dist/scripts/inspec_tutorial.js')
|
|
|
|
Verify.file('tutorial/dist/dist/inspec_tutorial.js')
|
2016-09-23 13:26:22 +00:00
|
|
|
end
|
2016-09-23 09:29:22 +00:00
|
|
|
|
2016-09-23 13:26:22 +00:00
|
|
|
desc 'Builds the middleman site'
|
|
|
|
task :site do
|
2017-03-22 15:58:12 +00:00
|
|
|
Log.section 'Build middleman project'
|
2016-09-22 19:26:19 +00:00
|
|
|
Bundler.with_clean_env {
|
2017-03-22 15:58:12 +00:00
|
|
|
sh('bundle install && bundle exec middleman build')
|
2016-09-22 19:26:19 +00:00
|
|
|
}
|
2017-03-22 15:58:12 +00:00
|
|
|
Verify.file('build/index.html')
|
|
|
|
Verify.file('build/javascripts/all.js')
|
|
|
|
Verify.file('build/stylesheets/site.css')
|
2016-09-22 19:26:19 +00:00
|
|
|
end
|
|
|
|
|
2016-09-23 13:26:22 +00:00
|
|
|
desc 'Assemble the website site from middleman and the tutorial'
|
|
|
|
task :assemble do
|
|
|
|
Log.section 'Copy only tutorial into middleman build directory'
|
2017-03-22 15:58:12 +00:00
|
|
|
sh('rsync -a --exclude=index.html tutorial/dist/* build/')
|
|
|
|
sh('cp tutorial/dist/index.html build/tutorial.html')
|
2016-09-23 13:26:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Builds the full site locally'
|
|
|
|
task build: ['www:tutorial', 'www:site', 'www:assemble']
|
|
|
|
|
2016-09-26 04:25:49 +00:00
|
|
|
task :clean do
|
2017-03-22 15:58:12 +00:00
|
|
|
dst = 'build'
|
2016-09-26 04:25:49 +00:00
|
|
|
FileUtils.rm_rf(dst) if File.directory?(dst)
|
|
|
|
end
|
|
|
|
|
2016-09-22 19:26:19 +00:00
|
|
|
desc 'Releases the site to gh-pages'
|
|
|
|
task :release do
|
|
|
|
# This folder contains the built files
|
2017-03-22 15:58:12 +00:00
|
|
|
dst = 'build'
|
2016-09-22 19:26:19 +00:00
|
|
|
unless File.directory?(dst) && File.file?(File.join(dst, 'index.html'))
|
|
|
|
puts 'It looks like you have not built the site yet. Calling rake www:build'
|
|
|
|
Rake::Task['www:build'].invoke
|
|
|
|
end
|
|
|
|
|
|
|
|
unless File.directory?(dst) && File.file?(File.join(dst, 'index.html'))
|
2017-02-08 22:49:16 +00:00
|
|
|
raise 'It looks like the site was not build. Aborting.'
|
2016-09-22 19:26:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# check if git exists
|
2016-09-28 14:39:26 +00:00
|
|
|
sh('command -v git >/dev/null 2>&1') ||
|
2017-02-08 22:49:16 +00:00
|
|
|
raise("It looks like `git` isn't installed. It is required to run this build task.")
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-09-28 14:39:26 +00:00
|
|
|
unless sh('git diff-index --quiet HEAD --')
|
2017-02-08 22:49:16 +00:00
|
|
|
raise 'Please make sure you have no uncommitted changes in this repository.'
|
2016-09-22 19:26:19 +00:00
|
|
|
end
|
|
|
|
|
2017-03-22 15:58:12 +00:00
|
|
|
File.write('build/CNAME', 'inspec.io')
|
|
|
|
file_count = Dir['build/*'].length
|
|
|
|
file_size = `du -hs build`.sub(/\s+.*$/m, '')
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-12-01 18:37:44 +00:00
|
|
|
if system('git rev-parse --verify gh-pages')
|
|
|
|
Log.info 'Remove local gh-pages branch'
|
|
|
|
sh('git branch -D gh-pages')
|
|
|
|
end
|
2016-09-22 19:26:19 +00:00
|
|
|
|
|
|
|
current_branch = `git rev-parse --abbrev-ref HEAD`.strip
|
|
|
|
if current_branch.empty?
|
2017-02-08 22:49:16 +00:00
|
|
|
raise 'Cannot determine current branch to go back to! Aborting.'
|
2016-09-22 19:26:19 +00:00
|
|
|
end
|
|
|
|
|
2016-09-23 09:29:22 +00:00
|
|
|
Log.info 'Create empty gh-pages branch'
|
2016-09-28 14:39:26 +00:00
|
|
|
sh('git checkout --orphan gh-pages')
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-09-23 09:29:22 +00:00
|
|
|
Log.info 'Clear out all local git files!'
|
2016-09-28 14:39:26 +00:00
|
|
|
sh('git rm -rf .')
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-09-23 09:29:22 +00:00
|
|
|
Log.info "Add the built files in #{dst}"
|
2016-09-28 14:39:26 +00:00
|
|
|
sh("git add #{dst}")
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-09-23 09:29:22 +00:00
|
|
|
Log.info 'Remove all other files in this empty branch'
|
2016-09-28 14:39:26 +00:00
|
|
|
sh('git clean -df')
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-09-23 09:29:22 +00:00
|
|
|
Log.info 'Move the site to the root directory'
|
2016-09-28 14:39:26 +00:00
|
|
|
sh("git mv #{File.join(dst, '*')} .")
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-09-23 09:29:22 +00:00
|
|
|
Log.info 'Commit to gh-pages'
|
2016-09-28 14:39:26 +00:00
|
|
|
sh("git commit -m 'website update'")
|
2016-09-22 19:26:19 +00:00
|
|
|
|
2016-09-27 18:00:01 +00:00
|
|
|
require 'inquirer'
|
2016-09-22 19:26:19 +00:00
|
|
|
if Ask.confirm("Ready to go, I have #{file_count} files at #{file_size}. "\
|
|
|
|
'Do you want to push this live?', default: false)
|
2016-09-23 09:29:22 +00:00
|
|
|
Log.info 'push to origin, this may take a moment'
|
2016-09-28 14:39:26 +00:00
|
|
|
sh('git push -u origin --force-with-lease gh-pages')
|
2016-09-22 19:26:19 +00:00
|
|
|
else
|
|
|
|
puts 'Aborted.'
|
|
|
|
end
|
|
|
|
|
2016-09-28 14:39:26 +00:00
|
|
|
sh("git checkout #{current_branch}")
|
2016-09-22 19:26:19 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-22 15:58:12 +00:00
|
|
|
desc 'Full website release: includes local clean, docs build, site build, and then release'
|
2016-09-22 19:26:19 +00:00
|
|
|
task :www do
|
2016-09-26 04:25:49 +00:00
|
|
|
Rake::Task['www:clean'].invoke
|
2016-09-26 05:03:37 +00:00
|
|
|
Rake::Task['docs'].invoke
|
2016-09-26 04:25:49 +00:00
|
|
|
Rake::Task['www:build'].invoke
|
2016-09-22 19:26:19 +00:00
|
|
|
Rake::Task['www:release'].invoke
|
|
|
|
end
|