diff --git a/Rakefile b/Rakefile index dcf587c1a..3d3880a04 100755 --- a/Rakefile +++ b/Rakefile @@ -4,17 +4,11 @@ require "bundler" require "bundler/gem_helper" require "rake/testtask" require "train" -require_relative "tasks/spdx" require "fileutils" Bundler::GemHelper.install_tasks name: "inspec-core" Bundler::GemHelper.install_tasks name: "inspec" -def prompt(message) - print(message) - STDIN.gets.chomp -end - # 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 @@ -26,13 +20,6 @@ rescue LoadError puts "docs tasks are unavailable because the ruby-progressbar gem is not available." end -begin - require "git" - require_relative "tasks/contrib" -rescue LoadError - puts "contrib tasks are unavailable because the git gem is not available." -end - task :install do inspec_bin_path = ::File.join(::File.dirname(__FILE__), "inspec-bin") Dir.chdir(inspec_bin_path) @@ -74,18 +61,6 @@ namespace :test do puts Dir[*GLOBS].sort end - task :missing do - missing = Dir["test/**/*"] - Dir[*GLOBS] - - missing.reject! { |f| ! File.file? f } - missing.reject! { |f| f =~ %r{test/(integration|cookbooks)} } - missing.reject! { |f| f =~ %r{test/fixtures} } - missing.reject! { |f| f =~ /test.*helper/ } - missing.reject! { |f| f =~ %r{test/docker} } - - puts missing.sort - end - # rubocop:disable Style/BlockDelimiters,Layout/ExtraSpacing,Lint/AssignmentInCondition def n_threads_run(n_workers, jobs) @@ -255,80 +230,6 @@ namespace :test do end # Inject a prerequisite task task unit: [:accept_license] - - task :kitchen, [:os] do |task, args| - concurrency = ENV["CONCURRENCY"] || 1 - os = args[:os] || ENV["OS"] || "" - ENV["DOCKER"] = "true" if ENV["docker"].nil? - sh("bundle exec kitchen test -c #{concurrency} #{os}") - end - # Inject a prerequisite task - task kitchen: [:accept_license] - - 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" : "*" - sh_cmd += " --sudo" unless args[:target].split("@")[0] == "root" - 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 end -# 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) - nu = raw.sub(/VERSION.*/, "VERSION = '#{target}'.freeze") - 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" -end - -# Show the current version of this gem. -desc "Show the version of this gem" -task :version do - inspec_version -end +# NOTE: Rakefile clean-up was done in PR #6367 (https://github.com/inspec/inspec/pull/6367) diff --git a/tasks/contrib.rb b/tasks/contrib.rb deleted file mode 100644 index 651671ecf..000000000 --- a/tasks/contrib.rb +++ /dev/null @@ -1,70 +0,0 @@ -# Rake tasks to assist in coordinating operations with separately -# maintained projects. - -require "fileutils" -require "yaml" -require "git" - -CONTRIB_DIR = File.expand_path(File.join(__dir__, "..", "contrib")).freeze -RESOURCE_DOC_DIR = File.expand_path(File.join(__dir__, "..", "docs", "resources")).freeze - -namespace :contrib do # rubocop: disable Metrics/BlockLength - config = nil - - task :read_config do - config = YAML.load(File.read(File.join(CONTRIB_DIR, "contrib.yaml"))) - end - - task fetch_resource_packs: [:read_config] do - puts "Fetching contrib resource packs..." - config["resource_packs"].each do |name, info| - clone_path = File.join(CONTRIB_DIR, name) - git = nil - verb = nil - if File.exist?(clone_path) - git = Git.open(clone_path) - git.fetch - verb = "fetched" - else - git = Git.clone(info["git_repo"], name, path: CONTRIB_DIR) - verb = "cloned" - end - - sha = git.log[0].sha[0..6] - branch = git.current_branch - puts " #{name}: #{verb}, now at #{sha}" + (branch ? " (#{branch})" : "") - end - end - - desc "Copy docs from resource packs into the core for doc building" - task copy_docs: [:fetch_resource_packs] do - config["resource_packs"].each do |name, info| - doc_sub_dir = info["doc_sub_dir"] || "docs/resources" - doc_src_path = File.join(CONTRIB_DIR, name, doc_sub_dir) - dest_path = RESOURCE_DOC_DIR - Dir.chdir(doc_src_path) do - Dir["*.md*"].sort.each do |file| - # TODO: check file for Availability section in markdown? - FileUtils.cp(file, dest_path) - end - end - end - end - - desc "Cleanup docs from resource packs in core" - task cleanup_docs: [:read_config] do - # TODO: I don't see the point of this cleanup phase - config["resource_packs"].each do |name, info| - doc_sub_dir = info["doc_sub_dir"] || "docs/resources" - doc_src_path = File.join(CONTRIB_DIR, name, doc_sub_dir) - dest_path = RESOURCE_DOC_DIR - Dir.chdir(doc_src_path) do - Dir["*.md*"].sort.each do |file| - cruft = File.join(dest_path, file) - FileUtils.rm_f(cruft) - end - end - end - end -end -# rubocop enable: Metrics/BlockLength diff --git a/tasks/docs.rb b/tasks/docs.rb index 77e7305b2..51b5015b6 100644 --- a/tasks/docs.rb +++ b/tasks/docs.rb @@ -17,9 +17,7 @@ require "erb" require "fileutils" require "yaml" -require_relative "./shared" require "git" -require_relative "./contrib" DOCS_DIR = "../docs".freeze @@ -121,112 +119,6 @@ class RST end end -class ResourceDocs - def initialize(root) - @paths = {} # cache of paths - @root = root # relative root path for all docs - end - - def render(path) - @paths[path] ||= render_path(path) - end - - def partial(x) - render(x + ".md.erb") - end - - def overview_page(resource_doc_files) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength - renderer = Markdown - markdown = renderer.meta(title: "InSpec Resources Reference") - markdown << renderer.h1("InSpec Resources Reference") - markdown << renderer.p("The following list of InSpec resources are available.") - - contrib_config = YAML.load(File.read(File.join(CONTRIB_DIR, "contrib.yaml"))) - - # TODO: clean this up using Hash.new and friends - - # Build a list of resources keyed on the group they are a part of. - # We'll determine the group using regexes. - group_regexes = [ - # These are hardcoded present in the main repo. If they become resource - # packs, this should change. - { group_name: "AWS", regex: /^aws_/ }, - { group_name: "Azure", regex: /^azure(rm)?_/ }, - ] - # Also pick up regexes and group names from contrib resource packs. - contrib_config["resource_packs"].values.each do |project_info| - group_regexes << { group_name: project_info["doc_group_title"], regex: Regexp.new(project_info["resource_file_regex"]) } - end - - # OK, apply the regexes we have to the resource doc file list we were passed. - # doc_file looks like /resources/foo.md.erb - trim off directory and file extension - trimmed_doc_files = resource_doc_files.dup.map { |file| File.basename(file).sub(/\.md(\.erb)?$/, "") } - resources_by_group = Hash[group_regexes.map { |info| [info[:group_name], []] }] # Initialize each group to an empty array - resources_by_group["OS"] = [] - trimmed_doc_files.each do |doc_file| - matched = false - group_regexes.each do |group_info| - next if matched - - if doc_file =~ group_info[:regex] - resources_by_group[group_info[:group_name]] << doc_file - matched = true - end - end - # Any resources that don't match a regex are assumed to be 'os' resources. - resources_by_group["OS"] << doc_file unless matched - end - - # Now transform the resource lists into HTML - markdown_resource_links_by_group = {} - resources_by_group.each do |group_name, resource_list| - markdown_resource_links_by_group[group_name] = resource_list.map do |resource_name| - renderer.li(renderer.a(resource_name.gsub("_", '\\_'), "resources/" + resource_name + ".html")) - end.join("") - end - - # Remove any groups that have no resource docs. - resources_by_group.reject! { |_, resource_list| resource_list.empty? } - - # Generate the big buttons that jump to the section of the page for each group. - markdown << '