Skip to content

Commit

Permalink
Merge pull request #8 from chef/tm/chefstyle
Browse files Browse the repository at this point in the history
Enable ChefStyle and Travis testing
  • Loading branch information
thommay authored Sep 7, 2016
2 parents 1f8a177 + 374fc13 commit 44794bd
Show file tree
Hide file tree
Showing 21 changed files with 292 additions and 279 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
branches:
only:
master

language: ruby
rvm:
- 2.1
- 2.2
- 2.3.1
before_install: gem install bundler -v 1.11.2
script: bundle exec rake ci
7 changes: 4 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

group :test do
gem 'minitar'
group :development, :test do
gem "minitar"
gem "chefstyle"
end
17 changes: 17 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,19 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec

desc "Run tests for Travis CI"
task ci: [:style, :spec]

begin
require "chefstyle"
require "rubocop/rake_task"
RuboCop::RakeTask.new(:style) do |task|
task.options += ["--display-cop-names", "--no-color"]
end
rescue LoadError
puts "chefstyle/rubocop is not available. gem install chefstyle to do style checking."
end
32 changes: 16 additions & 16 deletions cookbook-omnifetch.gemspec
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cookbook-omnifetch/version'
require "cookbook-omnifetch/version"

Gem::Specification.new do |spec|
spec.name = "cookbook-omnifetch"
spec.version = CookbookOmnifetch::VERSION
spec.authors = [
'Jamie Winsor',
'Josiah Kiehl',
'Michael Ivey',
'Justin Campbell',
'Seth Vargo',
'Daniel DeLeo'
"Jamie Winsor",
"Josiah Kiehl",
"Michael Ivey",
"Justin Campbell",
"Seth Vargo",
"Daniel DeLeo",
]
spec.email = [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]'
spec.email = [
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
"[email protected]",
]
spec.summary = %q{Library code to fetch Chef cookbooks from a variety of sources to a local cache}
spec.homepage = "http://www.getchef.com/"
Expand All @@ -34,6 +34,6 @@ Gem::Specification.new do |spec|
spec.add_dependency "mixlib-archive", "~> 0.2"

spec.add_development_dependency "rake", "~> 10.3"
spec.add_development_dependency 'rspec','~> 3.0'
spec.add_development_dependency "rspec", "~> 3.0"

end
5 changes: 2 additions & 3 deletions lib/cookbook-omnifetch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
require "cookbook-omnifetch/path"
require "cookbook-omnifetch/artifactserver"


module CookbookOmnifetch

# Create a new instance of a Location class given dependency and options.
Expand Down Expand Up @@ -42,8 +41,8 @@ def self.init(dependency, options = {})
def self.which(executable)
if File.file?(executable) && File.executable?(executable)
executable
elsif ENV['PATH']
path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p|
elsif ENV["PATH"]
path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |p|
File.executable?(File.join(p, executable))
end
path && File.expand_path(executable, path)
Expand Down
27 changes: 8 additions & 19 deletions lib/cookbook-omnifetch/artifactserver.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'cookbook-omnifetch/base'
require "cookbook-omnifetch/base"

require 'mixlib/archive'
require 'tmpdir'
require "mixlib/archive"
require "tmpdir"

module CookbookOmnifetch

Expand Down Expand Up @@ -47,7 +47,7 @@ def install
FileUtils.mkdir_p(staging_root) unless staging_root.exist?
Dir.mktmpdir(nil, staging_root) do |staging_dir|
Mixlib::Archive.new(cache_path).extract(staging_dir, perms: false,
ignore: /^\./)
ignore: /^\./)
staged_cookbook_path = File.join(staging_dir, cookbook_name)
validate_cached!(staged_cookbook_path)
FileUtils.mv(staged_cookbook_path, install_path)
Expand Down Expand Up @@ -85,8 +85,8 @@ def cached_cookbook

def lock_data
out = {}
out['artifactserver'] = uri
out['version'] = cookbook_version
out["artifactserver"] = uri
out["version"] = cookbook_version
out
end

Expand All @@ -98,24 +98,13 @@ def to_lock
"#to_lock must be implemented on #{self.class.name}!"
end


def ==(other)
raise 'TODO'
other.is_a?(GitLocation) &&
other.uri == uri &&
other.branch == branch &&
other.tag == tag &&
other.shortref == shortref &&
other.rel == rel
end

# The path where all pristine tarballs from an artifactserver are held.
# Tarballs are moved/swapped into this location once they have been staged
# in a co-located staging directory.
#
# @return [Pathname]
def cache_root
Pathname.new(CookbookOmnifetch.cache_path).join('.cache', 'artifactserver')
Pathname.new(CookbookOmnifetch.cache_path).join(".cache", "artifactserver")
end

# The path where tarballs are downloaded to and unzipped. On certain platforms
Expand All @@ -129,7 +118,7 @@ def cache_root
#
# @return [Pathname]
def staging_root
Pathname.new(CookbookOmnifetch.cache_path).join('.cache_tmp', 'artifactserver')
Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactserver")
end

# The path where the pristine tarball is cached
Expand Down
2 changes: 1 addition & 1 deletion lib/cookbook-omnifetch/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cookbook-omnifetch/exceptions'
require "cookbook-omnifetch/exceptions"

module CookbookOmnifetch
class BaseLocation
Expand Down
6 changes: 3 additions & 3 deletions lib/cookbook-omnifetch/chef_server.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cookbook-omnifetch/base'
require "cookbook-omnifetch/base"

module CookbookOmnifetch
class CookbookMetadata
Expand All @@ -12,7 +12,7 @@ class CookbookMetadata
:attributes,
:files,
:templates,
:root_files
:root_files,
].freeze

def initialize(metadata)
Expand Down Expand Up @@ -98,7 +98,7 @@ def cache_key
#
# @return [Pathname]
def staging_root
Pathname.new(CookbookOmnifetch.cache_path).join('.cache_tmp', 'artifactserver')
Pathname.new(CookbookOmnifetch.cache_path).join(".cache_tmp", "artifactserver")
end

def staging_path
Expand Down
6 changes: 3 additions & 3 deletions lib/cookbook-omnifetch/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ class GitError < OmnifetchError

class GitNotInstalled < GitError
def initialize
super 'You need to install Git before you can download ' \
'cookbooks from git repositories. For more information, please ' \
'see the Git docs: http://git-scm.org.'
super "You need to install Git before you can download " \
"cookbooks from git repositories. For more information, please " \
"see the Git docs: http://git-scm.org."
end
end

Expand Down
42 changes: 21 additions & 21 deletions lib/cookbook-omnifetch/git.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'tmpdir'
require 'cookbook-omnifetch'
require 'cookbook-omnifetch/base'
require 'cookbook-omnifetch/exceptions'
require "tmpdir"
require "cookbook-omnifetch"
require "cookbook-omnifetch/base"
require "cookbook-omnifetch/exceptions"

module CookbookOmnifetch
class GitLocation < BaseLocation
Expand All @@ -23,7 +23,7 @@ def initialize(dependency, options = {})
@rel = options[:rel]

# The revision to parse
@rev_parse = options[:ref] || options[:branch] || options[:tag] || 'master'
@rev_parse = options[:ref] || options[:branch] || options[:tag] || "master"
end

# @see BaseLoation#installed?
Expand All @@ -41,26 +41,26 @@ def install

if cached?
Dir.chdir(cache_path) do
git %|fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"|
git %{fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"}
end
else
git %|clone #{uri} "#{cache_path}" --bare --no-hardlinks|
git %{clone #{uri} "#{cache_path}" --bare --no-hardlinks}
end

Dir.chdir(cache_path) do
@revision ||= git %|rev-parse #{@rev_parse}|
@revision ||= git %{rev-parse #{@rev_parse}}
end

# Clone into a scratch directory for validations
git %|clone --no-checkout "#{cache_path}" "#{scratch_path}"|
git %{clone --no-checkout "#{cache_path}" "#{scratch_path}"}

# Make sure the scratch directory is up-to-date and account for rel paths
Dir.chdir(scratch_path) do
git %|fetch --force --tags "#{cache_path}"|
git %|reset --hard #{@revision}|
git %{fetch --force --tags "#{cache_path}"}
git %{reset --hard #{@revision}}

if rel
git %|filter-branch --subdirectory-filter "#{rel}" --force|
git %{filter-branch --subdirectory-filter "#{rel}" --force}
end
end

Expand All @@ -72,7 +72,7 @@ def install
FileUtils.cp_r(scratch_path, install_path)

# Remove the git history
FileUtils.rm_rf(File.join(install_path, '.git'))
FileUtils.rm_rf(File.join(install_path, ".git"))

install_path.chmod(0777 & ~File.umask)
ensure
Expand All @@ -91,11 +91,11 @@ def cached_cookbook

def ==(other)
other.is_a?(GitLocation) &&
other.uri == uri &&
other.branch == branch &&
other.tag == tag &&
other.shortref == shortref &&
other.rel == rel
other.uri == uri &&
other.branch == branch &&
other.tag == tag &&
other.shortref == shortref &&
other.rel == rel
end

def to_s
Expand Down Expand Up @@ -163,11 +163,11 @@ def shortref
# @raise [String]
# the +$stdout+ from the command
def git(command, error = true)
unless CookbookOmnifetch.which('git') || CookbookOmnifetch.which('git.exe') || CookbookOmnifetch.which('git.bat')
unless CookbookOmnifetch.which("git") || CookbookOmnifetch.which("git.exe") || CookbookOmnifetch.which("git.bat")
raise GitNotInstalled.new
end

response = CookbookOmnifetch.shell_out_class.shell_out(%|git #{command}|)
response = CookbookOmnifetch.shell_out_class.shell_out(%{git #{command}})

if error && !response.success?
raise GitCommandError.new(command, cache_path, response.stderr)
Expand All @@ -188,7 +188,7 @@ def cached?
# @return [Pathname]
def cache_path
Pathname.new(CookbookOmnifetch.cache_path)
.join('.cache', 'git', Digest::SHA1.hexdigest(uri))
.join(".cache", "git", Digest::SHA1.hexdigest(uri))
end
end
end
3 changes: 1 addition & 2 deletions lib/cookbook-omnifetch/integration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cookbook-omnifetch/exceptions'
require "cookbook-omnifetch/exceptions"

module CookbookOmnifetch

Expand Down Expand Up @@ -28,7 +28,6 @@ def self.configurable(name)
value
end
end

end

configurable :cache_path
Expand Down
6 changes: 3 additions & 3 deletions lib/cookbook-omnifetch/path.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'cookbook-omnifetch/base'
require "cookbook-omnifetch/base"

module CookbookOmnifetch
class PathLocation < BaseLocation
Expand Down Expand Up @@ -65,8 +65,8 @@ def expanded_path

def ==(other)
other.is_a?(PathLocation) &&
other.metadata? == metadata? &&
other.relative_path == relative_path
other.metadata? == metadata? &&
other.relative_path == relative_path
end

def lock_data
Expand Down
6 changes: 3 additions & 3 deletions spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name 'example_cookbook'
maintainer 'Berkshelf Core'
version '0.5.0'
name "example_cookbook"
maintainer "Berkshelf Core"
version "0.5.0"
6 changes: 3 additions & 3 deletions spec/fixtures/cookbooks/example_cookbook/metadata.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
name 'example_cookbook'
maintainer 'Berkshelf Core'
version '0.5.0'
name "example_cookbook"
maintainer "Berkshelf Core"
version "0.5.0"
9 changes: 4 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'cookbook-omnifetch'
require "cookbook-omnifetch"

module Fixtures

def fixtures_path
spec_root.join('fixtures')
spec_root.join("fixtures")
end

def spec_root
Expand Down Expand Up @@ -34,11 +34,10 @@ module MockCachedCookbook; end

config.before(:suite) do
CookbookOmnifetch.configure do |c|
c.cache_path = File.expand_path('~/.berkshelf')
c.storage_path = Pathname.new(File.expand_path('~/.berkshelf/cookbooks'))
c.cache_path = File.expand_path("~/.berkshelf")
c.storage_path = Pathname.new(File.expand_path("~/.berkshelf/cookbooks"))
c.shell_out_class = MockShellOut
c.cached_cookbook_class = MockCachedCookbook
end
end
end

Loading

0 comments on commit 44794bd

Please sign in to comment.