Skip to content

Commit

Permalink
Chefstyle autocorrect with the latest release
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Oct 31, 2019
1 parent bc90e43 commit 57e9459
Show file tree
Hide file tree
Showing 59 changed files with 232 additions and 250 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "bundler/gem_tasks"

require "rspec/core/rake_task"
[:unit, :functional].each do |type|
%i{unit functional}.each do |type|
RSpec::Core::RakeTask.new(type) do |t|
t.pattern = "spec/#{type}/**/*_spec.rb"
t.rspec_opts = [].tap do |a|
Expand Down
1 change: 1 addition & 0 deletions lib/omnibus/build_version_dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def maybe_append_timestamp(version)
def has_timestamp?(version)
_ver, build_info = version.split("+")
return false if build_info.nil?

build_info.split(".").any? do |part|
begin
Time.strptime(part, Omnibus::BuildVersion::TIMESTAMP_FORMAT)
Expand Down
11 changes: 6 additions & 5 deletions lib/omnibus/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ def patch(options = {})
clean_patch_path = patch_path
if windows?
clean_patch_path = Pathname.new(patch_path).relative_path_from(
Pathname.new(software.project_dir)).to_s
Pathname.new(software.project_dir)
).to_s
end

if target
Expand Down Expand Up @@ -385,6 +386,7 @@ def appbundle(software_name, lockdir: nil, gem: nil, without: nil, extra_bin_fil
if app_software.nil?
raise "could not find software definition for #{software_name}, add a dependency to it, or pass a lockdir argument to appbundle command."
end

app_software.project_dir
end

Expand Down Expand Up @@ -500,8 +502,7 @@ def erb(options = {})
render_template(source_path,
destination: dest,
mode: mode,
variables: vars
)
variables: vars)
end
end
expose :erb
Expand Down Expand Up @@ -596,7 +597,7 @@ def delete(path, options = {})
#
def strip(path)
regexp_ends = ".*(" + IGNORED_ENDINGS.map { |e| e.gsub(/\./, '\.') }.join("|") + ")$"
regexp_patterns = IGNORED_PATTERNS.map { |e| ".*" + e.gsub(/\//, '\/') + ".*" }.join("|")
regexp_patterns = IGNORED_PATTERNS.map { |e| ".*" + e.gsub(%r{/}, '\/') + ".*" }.join("|")
regexp = regexp_ends + "|" + regexp_patterns

# Do not actually care if strip runs on non-strippable file, as its a no-op. Hence the `|| true` appended.
Expand Down Expand Up @@ -727,7 +728,7 @@ def sync(source, destination, options = {})
# config.guess.to. Default: "."
# install [Array<Symbol>] parts of config.guess to copy.
# Default: [:config_guess, :config_sub]
def update_config_guess(target: ".", install: [:config_guess, :config_sub])
def update_config_guess(target: ".", install: %i{config_guess config_sub})
build_commands << BuildCommand.new("update_config_guess `target: #{target} install: #{install.inspect}'") do
config_guess_dir = "#{install_dir}/embedded/lib/config_guess"
%w{config.guess config.sub}.each do |c|
Expand Down
11 changes: 7 additions & 4 deletions lib/omnibus/changelog_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ def initialize(changelog, diff, source_path = "../")
end

def print(new_version)
puts "## #{new_version} (#{Time.now.strftime('%Y-%m-%d')})"
puts "## #{new_version} (#{Time.now.strftime("%Y-%m-%d")})"
print_changelog
if !diff.empty?
unless diff.empty?
print_components
puts ""
end
Expand All @@ -23,7 +23,7 @@ def print(new_version)

def print_changelog(cl = changelog, indent = 0)
cl.changelog_entries.each do |entry|
puts "#{' ' * indent}* #{entry.sub("\n", "\n #{' ' * indent}")}\n"
puts "#{" " * indent}* #{entry.sub("\n", "\n #{" " * indent}")}\n"
end
end

Expand All @@ -36,6 +36,7 @@ def print_components

def print_new_components
return if diff.added.empty?

puts "New Components"
diff.added.each do |entry|
puts "* #{entry[:name]} (#{entry[:new_version]})"
Expand All @@ -45,10 +46,11 @@ def print_new_components

def print_updated_components
return if diff.updated.empty?

puts "Updated Components"
diff.updated.each do |entry|
puts sprintf("* %s (%.8s -> %.8s)",
entry[:name], entry[:old_version], entry[:new_version])
entry[:name], entry[:old_version], entry[:new_version])
repo_path = ::File.join(source_path, entry[:name].to_s)
if entry[:source_type] == :git && ::File.directory?("#{repo_path}/.git")
cl = ChangeLog.new(entry[:old_version], entry[:new_version], GitRepository.new("#{repo_path}"))
Expand All @@ -60,6 +62,7 @@ def print_updated_components

def print_removed_components
return if diff.removed.empty?

puts "Removed Components"
diff.removed.each do |entry|
puts "* #{entry[:name]} (#{entry[:old_version]})"
Expand Down
3 changes: 3 additions & 0 deletions lib/omnibus/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ def clean_build_dir

def clean_package_dir
return unless purge?

FileSyncer.glob("#{Config.package_dir}/**/*").each(&method(:remove_file))
end

def clean_cache_dir
return unless purge?

FileSyncer.glob("#{Config.cache_dir}/**/*").each(&method(:remove_file))
end

def clean_install_dir
return unless purge?

remove_file(@project.install_dir)
end

Expand Down
48 changes: 24 additions & 24 deletions lib/omnibus/cli/changelog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@ class Command::ChangeLog < Command::Base
# $ omnibus changelog generate
#
method_option :source_path,
desc: "Path to local checkout of git dependencies",
type: :string,
default: "../"
desc: "Path to local checkout of git dependencies",
type: :string,
default: "../"

method_option :starting_manifest,
desc: "Path to version-manifest from the last version (we attempt to pull it from the git history if not given)",
type: :string
desc: "Path to version-manifest from the last version (we attempt to pull it from the git history if not given)",
type: :string

method_option :ending_manifest,
desc: "Path to the version-manifest from the current version",
type: :string,
default: "version-manifest.json"
desc: "Path to the version-manifest from the current version",
type: :string,
default: "version-manifest.json"

method_option :skip_components,
desc: "Don't include component changes in the changelog",
type: :boolean,
default: false
desc: "Don't include component changes in the changelog",
type: :boolean,
default: false

method_option :major,
desc: "Bump the major version",
type: :boolean,
default: false
desc: "Bump the major version",
type: :boolean,
default: false

method_option :minor,
desc: "Bump the minor version",
type: :boolean,
default: true
desc: "Bump the minor version",
type: :boolean,
default: true

method_option :patch,
desc: "Bump the patch version",
type: :boolean,
default: false
desc: "Bump the patch version",
type: :boolean,
default: false

method_option :version,
desc: "Explicit version for this changelog",
type: :string
desc: "Explicit version for this changelog",
type: :string

desc "generate [START] [END]", "Generate a changelog for a new release"
def generate(start_ref = nil, end_ref = nil)
Expand All @@ -78,8 +78,8 @@ def generate(start_ref = nil, end_ref = nil)
end

Omnibus::ChangeLogPrinter.new(ChangeLog.new(starting_revision, ending_revision),
diff,
@options[:source_path]).print(new_version)
diff,
@options[:source_path]).print(new_version)
end

private
Expand Down
7 changes: 3 additions & 4 deletions lib/omnibus/compressors/dmg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ def prettify_dmg
pkg_name: packager.package_name,
window_bounds: window_bounds,
pkg_position: pkg_position,
}
)
})

Dir.chdir(staging_dir) do
shellout! <<-EOH.gsub(/^ {10}/, "")
Expand Down Expand Up @@ -316,10 +315,10 @@ def set_dmg_icon
Dir.chdir(staging_dir) do
shellout! <<-EOH.gsub(/^ {10}/, "")
# Convert the png to an icon
sips -i "#{resource_path('icon.png')}"
sips -i "#{resource_path("icon.png")}"
# Extract the icon into its own resource
DeRez -only icns "#{resource_path('icon.png')}" > tmp.rsrc
DeRez -only icns "#{resource_path("icon.png")}" > tmp.rsrc
# Append the icon reosurce to the DMG
Rez -append tmp.rsrc -o "#{package_path}"
Expand Down
1 change: 1 addition & 0 deletions lib/omnibus/fetchers/git_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ def self.revision_from_remote_reference(ref, source)
unless commit_ref
raise UnresolvableGitReference.new(ref)
end

commit_ref
end

Expand Down
5 changes: 2 additions & 3 deletions lib/omnibus/fetchers/net_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NetFetcher < Fetcher
ALL_EXTENSIONS = WIN_7Z_EXTENSIONS + TAR_EXTENSIONS

# Digest types used for verifying file checksums
DIGESTS = [:sha512, :sha256, :sha1, :md5].freeze
DIGESTS = %i{sha512 sha256 sha1 md5}.freeze

#
# A fetch is required if the downloaded_file (such as a tarball) does not
Expand Down Expand Up @@ -314,8 +314,7 @@ def safe_downloaded_file
#
# @return [[String]]
#
def extract_command
end
def extract_command; end

#
# Primitively determine whether we should use gtar or tar to untar a file.
Expand Down
2 changes: 1 addition & 1 deletion lib/omnibus/health_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def health_check_aix
#
def health_check_ldd
regexp_ends = ".*(" + IGNORED_ENDINGS.map { |e| e.gsub(/\./, '\.') }.join("|") + ")$"
regexp_patterns = IGNORED_PATTERNS.map { |e| ".*" + e.gsub(/\//, '\/') + ".*" }.join("|")
regexp_patterns = IGNORED_PATTERNS.map { |e| ".*" + e.gsub(%r{/}, '\/') + ".*" }.join("|")
regexp = regexp_ends + "|" + regexp_patterns

current_library = nil
Expand Down
5 changes: 2 additions & 3 deletions lib/omnibus/licensing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ def prepare
#
# @return [void]
#
def execute_pre_build(software)
end
def execute_pre_build(software); end

# Callback that gets called by Software#build_me after the build is done.
# Invokes license copying for the given software. This ensures that
Expand Down Expand Up @@ -246,7 +245,7 @@ def components_license_summary

out << "This product bundles #{name} #{version},\n"
out << "which is available under a \"#{license}\" License.\n"
if !license_files.empty?
unless license_files.empty?
out << "For details, see:\n"
license_files.each do |license_file|
out << "#{license_package_location(name, license_file)}\n"
Expand Down
3 changes: 2 additions & 1 deletion lib/omnibus/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def live_stream(level = :debug)
#
def add(severity, progname, &block)
return true if io.nil? || severity < level

message = format_message(severity, progname, yield)
MUTEX.synchronize { io.write(message) }
true
Expand Down Expand Up @@ -138,7 +139,7 @@ def format_message(severity, progname, message)
else
left = "#{format_severity(severity)} | "
end
"#{left.rjust(LEFT)}#{Time.now.iso8601()} | #{message}\n"
"#{left.rjust(LEFT)}#{Time.now.iso8601} | #{message}\n"
end

#
Expand Down
2 changes: 1 addition & 1 deletion lib/omnibus/manifest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def entry_for(name)
end

def add(name, entry)
if ! entry.is_a? Omnibus::ManifestEntry
unless entry.is_a? Omnibus::ManifestEntry
raise NotAManifestEntry, "#{entry} is not an Omnibus:ManifestEntry"
end

Expand Down
3 changes: 1 addition & 2 deletions lib/omnibus/packagers/appx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def write_manifest_file
version: windows_package_version,
maintainer: project.maintainer,
certificate_subject: certificate_subject.gsub('"', "&quot;"),
}
)
})
end

#
Expand Down
1 change: 1 addition & 0 deletions lib/omnibus/packagers/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def skip_packager(val = false)
unless val.is_a?(TrueClass) || val.is_a?(FalseClass)
raise InvalidValue.new(:skip_packager, "be TrueClass or FalseClass")
end

@skip_package ||= val
end
expose :skip_packager
Expand Down
14 changes: 6 additions & 8 deletions lib/omnibus/packagers/bff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,11 @@ def write_gen_template
destination: "#{scripts_staging_dir}/config",
variables: {
name: project.name,
}
)
})
end

File.open(File.join(scripts_staging_dir, "config"), "a") do |file|
file.puts "mv '#{alt.gsub(/^#{staging_dir}/, '')}' '#{path.gsub(/^#{staging_dir}/, '')}'"
file.puts "mv '#{alt.gsub(/^#{staging_dir}/, "")}' '#{path.gsub(/^#{staging_dir}/, "")}'"
end

path = alt
Expand Down Expand Up @@ -189,8 +188,7 @@ def write_gen_template
description: project.description,
files: files,
scripts: scripts,
}
)
})

# Print the full contents of the rendered template file for mkinstallp's use
log.debug(log_key) { "Rendered Template:\n" + File.read(File.join(staging_dir, "gen.template")) }
Expand All @@ -214,19 +212,19 @@ def create_bff_file
# we will chown from 'project' on, rather than 'project/dir', which leaves
# project owned by the build user (which is incorrect)
# First - let's find out who we are.
shellout!("sudo chown -Rh 0:0 #{File.join(staging_dir, project.install_dir.match(/^\/?(\w+)/).to_s)}")
shellout!("sudo chown -Rh 0:0 #{File.join(staging_dir, project.install_dir.match(%r{^/?(\w+)}).to_s)}")
log.info(log_key) { "Creating .bff file" }

# Since we want the owner to be root, we need to sudo the mkinstallp
# command, otherwise it will not have access to the previously chowned
# directory.
shellout!("sudo /usr/sbin/mkinstallp -d #{staging_dir} -T #{File.join(staging_dir, 'gen.template')}")
shellout!("sudo /usr/sbin/mkinstallp -d #{staging_dir} -T #{File.join(staging_dir, "gen.template")}")

# Print the full contents of the inventory file generated by mkinstallp
# from within the staging_dir's .info folder (where control files for the
# packaging process are kept.)
log.debug(log_key) do
"With .inventory file of:\n" + File.read("#{File.join( staging_dir, '.info', "#{safe_base_package_name}.inventory" )}")
"With .inventory file of:\n" + File.read("#{File.join( staging_dir, ".info", "#{safe_base_package_name}.inventory" )}")
end

# Copy the resulting package up to the package_dir
Expand Down
Loading

0 comments on commit 57e9459

Please sign in to comment.