mirror of
https://github.com/inspec/inspec
synced 2024-11-10 07:04:15 +00:00
add build tasks for www
This commit is contained in:
parent
543db25b56
commit
d842771b68
4 changed files with 112 additions and 3 deletions
4
Gemfile
4
Gemfile
|
@ -6,6 +6,7 @@ gemspec
|
|||
# detecting that net-ssh 3 does not work with 1.9.3
|
||||
if Gem::Version.new(RUBY_VERSION) <= Gem::Version.new('1.9.3')
|
||||
gem 'net-ssh', '~> 2.9'
|
||||
gem 'tins', '~> 1.6.0'
|
||||
end
|
||||
|
||||
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
|
||||
|
@ -23,6 +24,8 @@ group :test do
|
|||
gem 'simplecov', '~> 0.10'
|
||||
gem 'concurrent-ruby', '~> 0.9'
|
||||
gem 'mocha', '~> 1.1'
|
||||
gem 'ruby-progressbar', '~> 1.8'
|
||||
gem 'inquirer'
|
||||
end
|
||||
|
||||
group :integration do
|
||||
|
@ -46,7 +49,6 @@ group :tools do
|
|||
gem 'rb-readline'
|
||||
gem 'license_finder'
|
||||
gem 'github_changelog_generator', '~> 1'
|
||||
gem 'ruby-progressbar', '~> 1.8'
|
||||
end
|
||||
|
||||
# gems for Maintainers.md generation
|
||||
|
|
3
Rakefile
3
Rakefile
|
@ -5,8 +5,9 @@ require 'bundler'
|
|||
require 'bundler/gem_tasks'
|
||||
require 'rake/testtask'
|
||||
require 'rubocop/rake_task'
|
||||
require_relative 'tasks/maintainers'
|
||||
require_relative 'tasks/docs'
|
||||
require_relative 'tasks/maintainers'
|
||||
require_relative 'tasks/www'
|
||||
|
||||
# Rubocop
|
||||
desc 'Run Rubocop lint checks'
|
||||
|
|
93
tasks/www.rb
Normal file
93
tasks/www.rb
Normal file
|
@ -0,0 +1,93 @@
|
|||
# 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.
|
||||
#
|
||||
|
||||
require 'inquirer'
|
||||
|
||||
namespace :www do
|
||||
desc 'Builds the site locally'
|
||||
task :build do
|
||||
Bundler.with_clean_env {
|
||||
system('cd www/ && bundle install && bundle exec middleman build')
|
||||
}
|
||||
end
|
||||
|
||||
desc 'Releases the site to gh-pages'
|
||||
task :release do
|
||||
# This folder contains the built files
|
||||
dst = 'www/build'
|
||||
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'))
|
||||
fail 'It looks like the site was not build. Aborting.'
|
||||
end
|
||||
|
||||
# check if git exists
|
||||
system('command -v git >/dev/null 2>&1') ||
|
||||
fail("It looks like `git` isn't installed. It is required to run this build task.")
|
||||
|
||||
unless system('git diff-index --quiet HEAD --')
|
||||
fail 'Please make sure you have no uncommitted changes in this repository.'
|
||||
end
|
||||
|
||||
File.write('www/build/CNAME', 'inspec.io')
|
||||
file_count = Dir['www/build/*'].length
|
||||
file_size = `du -hs www/build`.sub(/\s+.*$/m, '')
|
||||
|
||||
puts '----> Remove local gh-pages branch'
|
||||
system('git branch -D gh-pages')
|
||||
|
||||
current_branch = `git rev-parse --abbrev-ref HEAD`.strip
|
||||
if current_branch.empty?
|
||||
fail 'Cannot determine current branch to go back to! Aborting.'
|
||||
end
|
||||
|
||||
puts '----> Create empty gh-pages branch'
|
||||
system('git checkout --orphan gh-pages')
|
||||
|
||||
puts '----> Clear out all local git files!'
|
||||
system('git rm -rf .')
|
||||
|
||||
puts "----> Add the built files in #{dst}"
|
||||
system("git add #{dst}")
|
||||
|
||||
puts '----> Remove all other files in this empty branch'
|
||||
system('git clean -df')
|
||||
|
||||
puts '----> Move the site to the root directory'
|
||||
system("git mv #{File.join(dst, '*')} .")
|
||||
|
||||
puts '----> Commit to gh-pages'
|
||||
system("git commit -m 'website update'")
|
||||
|
||||
if Ask.confirm("Ready to go, I have #{file_count} files at #{file_size}. "\
|
||||
'Do you want to push this live?', default: false)
|
||||
puts '----> push to origin, this may take a moment'
|
||||
system('git push -u origin --force-with-lease gh-pages')
|
||||
else
|
||||
puts 'Aborted.'
|
||||
end
|
||||
|
||||
system("git checkout #{current_branch}")
|
||||
end
|
||||
end
|
||||
|
||||
task :www do
|
||||
Rake::Task['www:release'].invoke
|
||||
end
|
|
@ -19,5 +19,18 @@ bundle exec middleman server
|
|||
To build to a local static folder, run:
|
||||
|
||||
```bash
|
||||
bundle exec middleman server
|
||||
bundle exec middleman build
|
||||
```
|
||||
|
||||
## Releasing
|
||||
|
||||
To push a new version of the website, make sure that you have built the site
|
||||
(see previous section) and that you are happy with the results. If so, run:
|
||||
|
||||
```
|
||||
bundle exec rake www:release
|
||||
```
|
||||
|
||||
It will clear and create a local `gh-pages` branch, add the site to it,
|
||||
and ask you before it pushes everything to `origin/gh-pages` i.e. the live
|
||||
website.
|
||||
|
|
Loading…
Reference in a new issue