2015-09-03 17:25:43 +00:00
|
|
|
#!/usr/bin/env rake
|
|
|
|
# encoding: utf-8
|
|
|
|
|
2015-11-05 17:50:53 +00:00
|
|
|
require 'bundler'
|
|
|
|
require 'bundler/gem_tasks'
|
2015-09-02 02:13:59 +00:00
|
|
|
require 'rake/testtask'
|
2016-09-22 19:26:19 +00:00
|
|
|
require_relative 'tasks/maintainers'
|
2015-09-03 17:25:43 +00:00
|
|
|
|
2017-04-27 18:08:28 +00:00
|
|
|
# The docs tasks rely on ruby-progressbar. If we can't load it, then don't
|
|
|
|
# load the docs tasks. This is necessary to allow this Rakefile to work
|
|
|
|
# when the "tests" gem group in the Gemfile has been excluded, such as
|
|
|
|
# during an appbundle-updater run.
|
|
|
|
begin
|
|
|
|
require 'ruby-progressbar'
|
|
|
|
require_relative 'tasks/docs'
|
|
|
|
rescue LoadError
|
|
|
|
puts 'docs tasks are unavailable because the ruby-progressbar gem is not available.'
|
2015-09-03 17:25:43 +00:00
|
|
|
end
|
|
|
|
|
2017-04-27 18:08:28 +00:00
|
|
|
# Rubocop
|
|
|
|
begin
|
|
|
|
require 'rubocop/rake_task'
|
|
|
|
RuboCop::RakeTask.new(:lint)
|
|
|
|
rescue LoadError
|
|
|
|
puts 'rubocop is not available. Install the rubocop gem to run the lint tests.'
|
|
|
|
end
|
2015-09-02 02:13:59 +00:00
|
|
|
|
2016-08-25 01:28:43 +00:00
|
|
|
# update command output for demo
|
2016-08-25 15:24:22 +00:00
|
|
|
desc 'Run inspec commands and save results to www/app/responses'
|
2016-08-25 01:28:43 +00:00
|
|
|
task :update_demo do
|
2016-09-14 07:18:25 +00:00
|
|
|
ruby 'www/tutorial/scripts/build_simulator_runtime.rb'
|
|
|
|
ruby 'www/tutorial/scripts/run_simulator_recording.rb'
|
2016-08-25 01:28:43 +00:00
|
|
|
end
|
|
|
|
|
2015-09-03 17:25:43 +00:00
|
|
|
# run tests
|
2017-05-03 19:29:47 +00:00
|
|
|
task default: [:lint, :test]
|
2015-10-13 09:29:10 +00:00
|
|
|
|
2015-09-02 02:13:59 +00:00
|
|
|
Rake::TestTask.new do |t|
|
|
|
|
t.libs << 'test'
|
2015-10-17 20:53:21 +00:00
|
|
|
t.pattern = 'test/unit/**/*_test.rb'
|
2015-09-02 02:13:59 +00:00
|
|
|
t.warning = true
|
|
|
|
t.verbose = true
|
2015-09-03 18:35:23 +00:00
|
|
|
t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
|
2015-09-02 02:13:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
namespace :test do
|
|
|
|
task :isolated do
|
2015-09-15 13:52:07 +00:00
|
|
|
Dir.glob('test/unit/*_test.rb').all? do |file|
|
2015-09-02 02:13:59 +00:00
|
|
|
sh(Gem.ruby, '-w', '-Ilib:test', file)
|
2015-09-14 08:29:31 +00:00
|
|
|
end or fail 'Failures'
|
2015-09-02 02:13:59 +00:00
|
|
|
end
|
2015-09-03 11:22:15 +00:00
|
|
|
|
2016-03-16 07:22:46 +00:00
|
|
|
Rake::TestTask.new(:functional) do |t|
|
|
|
|
t.libs << 'test'
|
|
|
|
t.pattern = 'test/functional/**/*_test.rb'
|
|
|
|
t.warning = true
|
|
|
|
t.verbose = true
|
|
|
|
t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
|
|
|
|
end
|
|
|
|
|
2015-09-14 08:28:07 +00:00
|
|
|
task :resources do
|
2015-09-22 17:35:31 +00:00
|
|
|
tests = Dir['test/resource/*_test.rb']
|
2015-09-03 11:22:15 +00:00
|
|
|
return if tests.empty?
|
2015-09-22 15:43:08 +00:00
|
|
|
sh(Gem.ruby, 'test/docker_test.rb', *tests)
|
2015-09-03 11:22:15 +00:00
|
|
|
end
|
2015-10-21 20:52:41 +00:00
|
|
|
|
2016-05-10 17:23:11 +00:00
|
|
|
task :integration do
|
|
|
|
concurrency = ENV['CONCURRENCY'] || 1
|
|
|
|
os = ENV['OS'] || ''
|
|
|
|
sh('sh', '-c', "bundle exec kitchen test -c #{concurrency} #{os}")
|
2015-10-21 20:52:41 +00:00
|
|
|
end
|
2015-12-18 21:54:56 +00:00
|
|
|
|
|
|
|
task :ssh, [:target] do |_t, args|
|
|
|
|
tests_path = File.join(File.dirname(__FILE__), 'test', 'integration', 'test', 'integration', 'default')
|
|
|
|
key_files = ENV['key_files'] || File.join(ENV['HOME'], '.ssh', 'id_rsa')
|
|
|
|
|
|
|
|
sh_cmd = "bin/inspec exec #{tests_path}/"
|
|
|
|
sh_cmd += ENV['test'] ? "#{ENV['test']}_spec.rb" : '*'
|
2015-12-19 00:43:23 +00:00
|
|
|
sh_cmd += " --sudo" unless args[:target].split('@')[0] == 'root'
|
2015-12-18 21:54:56 +00:00
|
|
|
sh_cmd += " -t ssh://#{args[:target]}"
|
|
|
|
sh_cmd += " --key_files=#{key_files}"
|
|
|
|
sh_cmd += " --format=#{ENV['format']}" if ENV['format']
|
|
|
|
|
|
|
|
sh('sh', '-c', sh_cmd)
|
|
|
|
end
|
2015-09-02 02:13:59 +00:00
|
|
|
end
|
2015-11-20 21:38:12 +00:00
|
|
|
|
2015-11-26 17:58:53 +00:00
|
|
|
# Print the current version of this gem or update it.
|
|
|
|
#
|
|
|
|
# @param [Type] target the new version you want to set, or nil if you only want to show
|
|
|
|
def inspec_version(target = nil)
|
|
|
|
path = 'lib/inspec/version.rb'
|
|
|
|
require_relative path.sub(/.rb$/, '')
|
|
|
|
|
|
|
|
nu_version = target.nil? ? '' : " -> #{target}"
|
|
|
|
puts "Inspec: #{Inspec::VERSION}#{nu_version}"
|
|
|
|
|
|
|
|
unless target.nil?
|
|
|
|
raw = File.read(path)
|
2016-01-15 20:41:20 +00:00
|
|
|
nu = raw.sub(/VERSION.*/, "VERSION = '#{target}'.freeze")
|
2015-11-26 17:58:53 +00:00
|
|
|
File.write(path, nu)
|
|
|
|
load(path)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check if a command is available
|
|
|
|
#
|
|
|
|
# @param [Type] x the command you are interested in
|
|
|
|
# @param [Type] msg the message to display if the command is missing
|
|
|
|
def require_command(x, msg = nil)
|
|
|
|
return if system("command -v #{x} || exit 1")
|
|
|
|
msg ||= 'Please install it first!'
|
|
|
|
puts "\033[31;1mCan't find command #{x.inspect}. #{msg}\033[0m"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check if a required environment variable has been set
|
|
|
|
#
|
|
|
|
# @param [String] x the variable you are interested in
|
|
|
|
# @param [String] msg the message you want to display if the variable is missing
|
|
|
|
def require_env(x, msg = nil)
|
|
|
|
exists = `env | grep "^#{x}="`
|
|
|
|
return unless exists.empty?
|
|
|
|
puts "\033[31;1mCan't find environment variable #{x.inspect}. #{msg}\033[0m"
|
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
|
|
|
|
# Check the requirements for running an update of this repository.
|
|
|
|
def check_update_requirements
|
|
|
|
require_command 'git'
|
|
|
|
require_command 'github_changelog_generator', "\n"\
|
|
|
|
"For more information on how to install it see:\n"\
|
|
|
|
" https://github.com/skywinder/github-changelog-generator\n"
|
|
|
|
require_env 'CHANGELOG_GITHUB_TOKEN', "\n"\
|
|
|
|
"Please configure this token to make sure you can run all commands\n"\
|
|
|
|
"against GitHub.\n\n"\
|
|
|
|
"See github_changelog_generator homepage for more information:\n"\
|
|
|
|
" https://github.com/skywinder/github-changelog-generator\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
# Show the current version of this gem.
|
|
|
|
desc 'Show the version of this gem'
|
|
|
|
task :version do
|
|
|
|
inspec_version
|
|
|
|
end
|
|
|
|
|
2015-12-11 17:27:16 +00:00
|
|
|
desc 'Generate the changelog'
|
|
|
|
task :changelog do
|
|
|
|
require_relative 'lib/inspec/version'
|
2017-04-04 15:06:16 +00:00
|
|
|
system "github_changelog_generator -u chef -p inspec --future-release v#{Inspec::VERSION} --since-tag 0.7.0"
|
2015-12-11 17:27:16 +00:00
|
|
|
end
|
|
|
|
|
2015-11-26 17:58:53 +00:00
|
|
|
# Update the version of this gem and create an updated
|
|
|
|
# changelog. It covers everything short of actually releasing
|
|
|
|
# the gem.
|
|
|
|
desc 'Bump the version of this gem'
|
|
|
|
task :bump_version, [:version] do |_, args|
|
|
|
|
v = args[:version] || ENV['to']
|
2016-01-05 15:58:09 +00:00
|
|
|
fail "You must specify a target version! rake bump_version to=1.2.3" if v.empty?
|
2015-11-26 17:58:53 +00:00
|
|
|
check_update_requirements
|
|
|
|
inspec_version(v)
|
|
|
|
Rake::Task['changelog'].invoke
|
2016-08-26 09:45:00 +00:00
|
|
|
Rake::Task['docs:cli'].invoke
|
2015-11-26 17:58:53 +00:00
|
|
|
end
|
2016-05-13 10:59:33 +00:00
|
|
|
|
|
|
|
desc 'Release a new docker image'
|
|
|
|
task :release_docker do
|
|
|
|
version = Inspec::VERSION
|
|
|
|
cmd = "rm *.gem; gem build *gemspec && "\
|
|
|
|
"mv *.gem inspec.gem && "\
|
|
|
|
"docker build -t chef/inspec:#{version} . && "\
|
2016-11-28 11:59:29 +00:00
|
|
|
"docker push chef/inspec:#{version} && "\
|
|
|
|
"docker tag chef/inspec:#{version} chef/inspec:latest &&"\
|
2016-11-21 04:51:39 +00:00
|
|
|
"docker push chef/inspec:latest"
|
2016-05-13 10:59:33 +00:00
|
|
|
puts "--> #{cmd}"
|
|
|
|
sh('sh', '-c', cmd)
|
|
|
|
end
|
2016-10-11 21:07:44 +00:00
|
|
|
|
|
|
|
desc 'Release a new Habitat package'
|
|
|
|
task :release_habitat do
|
|
|
|
version = Inspec::VERSION
|
|
|
|
ENV['HAB_ORIGIN'] = "chef"
|
|
|
|
if Dir.exist?("./results") then
|
|
|
|
raise "Please remove the ./results directory"
|
|
|
|
end
|
|
|
|
if ! ENV.has_key?("HAB_AUTH_TOKEN") then
|
|
|
|
raise "Please set the HAB_AUTH_TOKEN environment variable"
|
|
|
|
end
|
|
|
|
cmd = "echo #{version} > ./habitat/VERSION && "\
|
|
|
|
"hab studio build ./habitat && " \
|
|
|
|
"hab pkg upload ./results/*.hart"
|
|
|
|
puts "--> #{cmd}"
|
|
|
|
sh('sh', '-c', cmd)
|
|
|
|
end
|
2017-03-22 15:58:12 +00:00
|
|
|
|
|
|
|
desc 'Release the website [deprecated]'
|
|
|
|
task :www do
|
|
|
|
puts 'The Rake tasks for releasing the website are now in the www/ directory.'
|
|
|
|
puts 'Run `cd www` and then `rake --tasks` for a list of the www-related tasks available.'
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
namespace :www do
|
|
|
|
desc 'Release the website [deprecated]'
|
|
|
|
task :release do
|
|
|
|
puts 'The Rake tasks for releasing the website are now in the www/ directory.'
|
|
|
|
puts 'Run `cd www` and then `rake --tasks` for a list of the www-related tasks available.'
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|