summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKartik Null Cating-Subramanian <ksubramanian@chef.io>2015-08-26 15:56:41 -0400
committerKartik Null Cating-Subramanian <ksubramanian@chef.io>2015-08-26 15:56:41 -0400
commit08e6744f7e64a4f43512a0ed7ec91d36ed9d19e3 (patch)
treec93f7befd1365692f8d5c4ffe04451f5eb20c95d
parent4ce6a8923f98ed0ddb9ff531891166397750c46c (diff)
parent6cc7320dac05d4c085cbaba83cf3b25f7685eecd (diff)
downloadchef-08e6744f7e64a4f43512a0ed7ec91d36ed9d19e3.tar.gz
Merge pull request #3760 from chef/ksubrama/rake_task
Refactor all the gem building logic into a custom rake task.
-rw-r--r--Rakefile114
-rw-r--r--chef-config/Rakefile57
-rw-r--r--chef-config/VERSION1
-rw-r--r--chef-config/lib/chef-config/package_task.rb223
-rw-r--r--chef-config/lib/chef-config/version.rb9
-rw-r--r--lib/chef/version.rb4
6 files changed, 242 insertions, 166 deletions
diff --git a/Rakefile b/Rakefile
index 628e0e1d45..6b9a52f68d 100644
--- a/Rakefile
+++ b/Rakefile
@@ -20,121 +20,15 @@
VERSION = IO.read(File.expand_path("../VERSION", __FILE__)).strip
require 'rubygems'
-require 'rubygems/package_task'
+require 'chef-config/package_task'
require 'rdoc/task'
require_relative 'tasks/rspec'
require_relative 'tasks/external_tests'
require_relative 'tasks/maintainers'
-GEM_NAME = "chef"
-
-desc "build Gems of Chef's components"
-task :package_components do
- Dir.chdir("chef-config") do
- sh "rake package"
- end
-end
-
-task :package => :package_components
-
-desc "build and install chef's components"
-task :install_components => :package_components do
- Dir.chdir("chef-config") do
- sh "rake install"
- end
-end
-
-task :install => :install_components
-
-desc "clean up builds of Chef's components"
-task :clobber_component_packages do
- Dir.chdir("chef-config") do
- sh "rake clobber_package"
- end
-end
-
-task :clobber_package => :clobber_component_packages
-
-desc "Update the version number for Chef's components"
-task :update_components_versions do
- Dir.chdir("chef-config") do
- sh "rake version"
- end
-end
-
-desc "Regenerate lib/chef/version.rb from VERSION file"
-task :version => :update_components_versions do
- contents = <<-VERSION_RB
-# Copyright:: Copyright (c) 2010-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.
-
-#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-# NOTE: This file is generated by running `rake version` in the top level of
-# this repo. Do not edit this manually. Edit the VERSION file and run the rake
-# task instead.
-#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-class Chef
- CHEF_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
- VERSION = '#{VERSION}'
-end
-
-#
-# NOTE: the Chef::Version class is defined in version_class.rb
-#
-# NOTE: DO NOT Use the Chef::Version class on Chef::VERSIONs. The
-# Chef::Version class is for _cookbooks_ only, and cannot handle
-# pre-release chef-client versions like "10.14.0.rc.2". Please
-# use Rubygem's Gem::Version class instead.
-#
-VERSION_RB
- version_rb_path = File.expand_path("../lib/chef/version.rb", __FILE__)
- IO.write(version_rb_path, contents)
-end
-
-Dir[File.expand_path("../*gemspec", __FILE__)].reverse.each do |gemspec_path|
- gemspec = eval(IO.read(gemspec_path))
- Gem::PackageTask.new(gemspec).define
-end
-
-def with_clean_env(&block)
- if defined?(Bundler)
- Bundler.with_clean_env(&block)
- else
- block.call
- end
-end
-
-desc "Build and install a chef gem"
-task :install => [:package] do
- with_clean_env do
- sh %{gem install pkg/#{GEM_NAME}-#{VERSION}.gem --no-rdoc --no-ri}
- end
-end
-
-task :uninstall do
- sh %{gem uninstall #{GEM_NAME} -x -v #{VERSION} }
-end
-
-desc "Build it, tag it and ship it"
-task :ship => [:clobber_package, :gem] do
- sh("git tag #{VERSION}")
- sh("git push opscode --tags")
- Dir[File.expand_path("../pkg/*.gem", __FILE__)].reverse.each do |built_gem|
- sh("gem push #{built_gem}")
- end
+ChefConfig::PackageTask.new(File.expand_path('..', __FILE__), 'Chef') do |package|
+ package.component_paths = ['chef-config']
+ package.generate_version_class = true
end
task :pedant do
diff --git a/chef-config/Rakefile b/chef-config/Rakefile
index 10b6010de3..36e7e2572d 100644
--- a/chef-config/Rakefile
+++ b/chef-config/Rakefile
@@ -1,26 +1,8 @@
require 'rspec/core/rake_task'
-require 'rubygems/package_task'
+require 'chef-config/package_task'
-VERSION = IO.read(File.expand_path("../../VERSION", __FILE__)).strip
-
-Dir[File.expand_path("../*gemspec", __FILE__)].reverse.each do |gemspec_path|
- gemspec = eval(IO.read(gemspec_path))
- Gem::PackageTask.new(gemspec).define
-end
-
-def with_clean_env(&block)
- if defined?(Bundler)
- Bundler.with_clean_env(&block)
- else
- block.call
- end
-end
-
-desc "Build and install a chef-config gem"
-task :install => [:package] do
- with_clean_env do
- sh(%{gem install pkg/chef-config-#{ChefConfig::VERSION}.gem --no-rdoc --no-ri}, verbose: true)
- end
+ChefConfig::PackageTask.new(File.expand_path('..', __FILE__), 'ChefConfig') do |package|
+ package.module_path = 'chef-config'
end
task :default => :spec
@@ -30,36 +12,3 @@ RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = FileList['spec/**/*_spec.rb']
end
-desc "Regenerate lib/chef/version.rb from VERSION file"
-task :version do
- contents = <<-VERSION_RB
-# Copyright:: Copyright (c) 2010-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.
-
-#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-# NOTE: This file is generated by running `rake version` in the top level of
-# this repo. Do not edit this manually. Edit the VERSION file and run the rake
-# task instead.
-#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-
-module ChefConfig
- VERSION = '#{VERSION}'
-end
-
-VERSION_RB
- version_rb_path = File.expand_path("../lib/chef-config/version.rb", __FILE__)
- IO.write(version_rb_path, contents)
-end
-
diff --git a/chef-config/VERSION b/chef-config/VERSION
new file mode 100644
index 0000000000..9a03cd310d
--- /dev/null
+++ b/chef-config/VERSION
@@ -0,0 +1 @@
+12.5.0.current.0
diff --git a/chef-config/lib/chef-config/package_task.rb b/chef-config/lib/chef-config/package_task.rb
new file mode 100644
index 0000000000..0aa063a2ff
--- /dev/null
+++ b/chef-config/lib/chef-config/package_task.rb
@@ -0,0 +1,223 @@
+#
+# Author:: Kartik Null Cating-Subramanian (<ksubramanian@chef.io>)
+# Copyright:: Copyright (c) 2015 Chef, 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 'rake'
+require 'rubygems'
+require 'rubygems/package_task'
+
+module ChefConfig
+ class PackageTask < Rake::TaskLib
+
+ # Full path to root of top-level repository. All other files (like VERSION or
+ # lib/<module_path>/version.rb are rooted at this path).
+ attr_accessor :root_path
+
+ # Name of the top-level module/library build built. This is used to define
+ # the top level module which contains VERSION and MODULE_ROOT.
+ attr_accessor :module_name
+
+ # Should the generated version.rb be in a class or module? Default is false (module).
+ attr_accessor :generate_version_class
+
+ # Paths to the roots of any components that also support ChefPackageTask.
+ # If relative paths are provided, they are rooted against root_path.
+ attr_accessor :component_paths
+
+ # This is the module name as it appears on the path "lib/module/".
+ # e.g. for module_name "ChefDK", you'd want module_path to be "chef-dk".
+ # The default is module_name but lower-cased.
+ attr_writer :module_path
+
+ def module_path
+ @module_path || module_name.downcase
+ end
+
+ # Path to a VERSION file with a single string that contains the package version.
+ # By default, this is root_path/VERSION
+ attr_accessor :version_file_path
+
+ # Directory used to store package files and output that is generated.
+ # This has the same meaning (or lack thereof) as package_dir in
+ # rake/packagetask.
+ attr_accessor :package_dir
+
+ # Name of git remote used to push tags during a release. Default is origin.
+ attr_accessor :git_remote
+
+ def initialize(root_path=nil, module_name=nil)
+ init(root_path, module_name)
+ yield self if block_given?
+ define unless root_path.nil? || module_name.nil?
+ end
+
+ def init(root_path, module_name)
+ @root_path = root_path
+ @module_name = module_name
+ @component_paths = []
+ @module_path = nil
+ @version_file_path = 'VERSION'
+ @package_dir = 'pkg'
+ @git_remote = 'origin'
+ @generate_version_class = false
+ end
+
+ def component_full_paths
+ component_paths.map { |path| File.expand_path(path, root_path)}
+ end
+
+ def version_rb_path
+ File.expand_path("lib/#{module_path}/version.rb", root_path)
+ end
+
+ def version
+ IO.read(File.expand_path(version_file_path, root_path)).strip
+ end
+
+ def full_package_dir
+ File.expand_path(package_dir, root_path)
+ end
+
+ def class_or_module
+ generate_version_class ? 'class' : 'module'
+ end
+
+ def with_clean_env(&block)
+ if defined?(Bundler)
+ Bundler.with_clean_env(&block)
+ else
+ block.call
+ end
+ end
+
+ def define
+ fail 'Need to provide package root and module name' if root_path.nil? || module_name.nil?
+
+ desc 'Build Gems of component dependencies'
+ task :package_components do
+ component_full_paths.each do |component_path|
+ Dir.chdir(component_path) do
+ sh 'rake package'
+ end
+ end
+ end
+
+ task :package => :package_components
+
+ desc 'Build and install component dependencies'
+ task :install_components => :package_components do
+ component_full_paths.each do |component_path|
+ Dir.chdir(component_path) do
+ sh 'rake install'
+ end
+ end
+ end
+
+ task :install => :install_components
+
+ desc 'Clean up builds of component dependencies'
+ task :clobber_component_packages do
+ component_full_paths.each do |component_path|
+ Dir.chdir(component_path) do
+ sh 'rake clobber_package'
+ end
+ end
+ end
+
+ task :clobber_package => :clobber_component_packages
+
+ desc 'Update the version number for component dependencies'
+ task :update_components_versions do
+ component_full_paths.each do |component_path|
+ Dir.chdir(component_path) do
+ sh 'rake version'
+ end
+ end
+ end
+
+ desc 'Regenerate lib/#{@module_path}/version.rb from VERSION file'
+ task :version => :update_components_versions do
+ contents = <<-VERSION_RB
+# Copyright:: Copyright (c) 2010-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.
+
+#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+# NOTE: This file is generated by running `rake version` in the top level of
+# this repo. Do not edit this manually. Edit the VERSION file and run the rake
+# task instead.
+#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+#{class_or_module} #{module_name}
+ #{module_name.upcase}_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
+ VERSION = '#{version}'
+end
+
+#
+# NOTE: the Chef::Version class is defined in version_class.rb
+#
+# NOTE: DO NOT Use the Chef::Version class on #{module_name}::VERSIONs. The
+# Chef::Version class is for _cookbooks_ only, and cannot handle
+# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
+# Gem::Version class instead.
+#
+ VERSION_RB
+ IO.write(version_rb_path, contents)
+ end
+
+ Dir[File.expand_path("*gemspec", root_path)].reverse.each do |gemspec_path|
+ gemspec = eval(IO.read(gemspec_path))
+ Gem::PackageTask.new(gemspec) do |task|
+ task.package_dir = full_package_dir
+ end
+ end
+
+ desc "Build and install a #{module_path} gem"
+ task :install => [:package] do
+ with_clean_env do
+ full_module_path = File.join(full_package_dir, module_path)
+ sh %{gem install #{full_module_path}-#{version}.gem --no-rdoc --no-ri}
+ end
+ end
+
+ task :uninstall do
+ sh %{gem uninstall #{module_path} -x -v #{version} }
+ end
+
+ desc 'Build it, tag it and ship it'
+ task :ship => [:clobber_package, :gem] do
+ sh("git tag #{version}")
+ sh("git push #{git_remote} --tags")
+ Dir[File.expand_path('*.gem', full_package_dir)].reverse.each do |built_gem|
+ sh("gem push #{built_gem}")
+ end
+ end
+ end
+ end
+
+end
diff --git a/chef-config/lib/chef-config/version.rb b/chef-config/lib/chef-config/version.rb
index aee626f240..9579f0638d 100644
--- a/chef-config/lib/chef-config/version.rb
+++ b/chef-config/lib/chef-config/version.rb
@@ -20,6 +20,15 @@
#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
module ChefConfig
+ CHEFCONFIG_ROOT = File.dirname(File.expand_path(File.dirname(__FILE__)))
VERSION = '12.5.0.current.0'
end
+#
+# NOTE: the Chef::Version class is defined in version_class.rb
+#
+# NOTE: DO NOT Use the Chef::Version class on ChefConfig::VERSIONs. The
+# Chef::Version class is for _cookbooks_ only, and cannot handle
+# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
+# Gem::Version class instead.
+#
diff --git a/lib/chef/version.rb b/lib/chef/version.rb
index 743a99824d..faa61aee54 100644
--- a/lib/chef/version.rb
+++ b/lib/chef/version.rb
@@ -29,6 +29,6 @@ end
#
# NOTE: DO NOT Use the Chef::Version class on Chef::VERSIONs. The
# Chef::Version class is for _cookbooks_ only, and cannot handle
-# pre-release chef-client versions like "10.14.0.rc.2". Please
-# use Rubygem's Gem::Version class instead.
+# pre-release versions like "10.14.0.rc.2". Please use Rubygem's
+# Gem::Version class instead.
#