Class: ChefConfig::PackageTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- ChefConfig::PackageTask
- Defined in:
- lib/chef-config/package_task.rb
Instance Attribute Summary collapse
-
#component_paths ⇒ Object
Paths to the roots of any components that also support ChefPackageTask.
-
#gem_name ⇒ Object
Name of the gem being built.
-
#generate_version_class ⇒ Object
Should the generated version.rb be in a class or module? Default is false (module).
-
#git_remote ⇒ Object
Name of git remote used to push tags during a release.
-
#module_name ⇒ Object
Name of the top-level module/library build built.
- #module_path ⇒ Object
-
#package_dir ⇒ Object
Directory used to store package files and output that is generated.
-
#root_path ⇒ Object
Full path to root of top-level repository.
-
#use_versionstring ⇒ Object
True if should use Chef::VersionString.
Instance Method Summary collapse
- #chef_root_path ⇒ Object
- #class_or_module ⇒ Object
- #component_full_paths ⇒ Object
- #define ⇒ Object
- #full_package_dir ⇒ Object
- #gemfile_lock_path ⇒ Object
- #init(root_path, module_name, gem_name) ⇒ Object
-
#initialize(root_path = nil, module_name = nil, gem_name = nil) {|_self| ... } ⇒ PackageTask
constructor
A new instance of PackageTask.
- #version ⇒ Object
- #version_file_path ⇒ Object
- #version_rb_path ⇒ Object
- #with_clean_env(&block) ⇒ Object
Constructor Details
#initialize(root_path = nil, module_name = nil, gem_name = nil) {|_self| ... } ⇒ PackageTask
Returns a new instance of PackageTask.
65 66 67 68 69 |
# File 'lib/chef-config/package_task.rb', line 65 def initialize(root_path = nil, module_name = nil, gem_name = nil) init(root_path, module_name, gem_name) yield self if block_given? define unless root_path.nil? || module_name.nil? end |
Instance Attribute Details
#component_paths ⇒ Object
Paths to the roots of any components that also support ChefPackageTask. If relative paths are provided, they are rooted against root_path.
43 44 45 |
# File 'lib/chef-config/package_task.rb', line 43 def component_paths @component_paths end |
#gem_name ⇒ Object
Name of the gem being built. This is used to find the lines to fix in Gemfile.lock.
36 37 38 |
# File 'lib/chef-config/package_task.rb', line 36 def gem_name @gem_name end |
#generate_version_class ⇒ Object
Should the generated version.rb be in a class or module? Default is false (module).
39 40 41 |
# File 'lib/chef-config/package_task.rb', line 39 def generate_version_class @generate_version_class end |
#git_remote ⇒ Object
Name of git remote used to push tags during a release. Default is origin.
60 61 62 |
# File 'lib/chef-config/package_task.rb', line 60 def git_remote @git_remote end |
#module_name ⇒ Object
Name of the top-level module/library build built. This is used to define the top level module which contains VERSION and MODULE_ROOT.
32 33 34 |
# File 'lib/chef-config/package_task.rb', line 32 def module_name @module_name end |
#module_path ⇒ Object
50 51 52 |
# File 'lib/chef-config/package_task.rb', line 50 def module_path @module_path || module_name.downcase end |
#package_dir ⇒ Object
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.
57 58 59 |
# File 'lib/chef-config/package_task.rb', line 57 def package_dir @package_dir end |
#root_path ⇒ Object
Full path to root of top-level repository. All other files (like VERSION or lib/<module_path>/version.rb are rooted at this path).
28 29 30 |
# File 'lib/chef-config/package_task.rb', line 28 def root_path @root_path end |
#use_versionstring ⇒ Object
True if should use Chef::VersionString.
63 64 65 |
# File 'lib/chef-config/package_task.rb', line 63 def use_versionstring @use_versionstring end |
Instance Method Details
#chef_root_path ⇒ Object
90 91 92 |
# File 'lib/chef-config/package_task.rb', line 90 def chef_root_path module_name == "Chef" ? root_path : File.dirname(root_path) end |
#class_or_module ⇒ Object
110 111 112 |
# File 'lib/chef-config/package_task.rb', line 110 def class_or_module generate_version_class ? "class" : "module" end |
#component_full_paths ⇒ Object
82 83 84 |
# File 'lib/chef-config/package_task.rb', line 82 def component_full_paths component_paths.map { |path| File.(path, root_path) } end |
#define ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/chef-config/package_task.rb', line 122 def define raise "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 namespace :version do desc "Regenerate lib/#{module_path}/version.rb from VERSION file" task :update => :update_components_versions do update_version_rb update_gemfile_lock end task :bump => %w{version:bump_patch version:update} task :show do puts version end # Add 1 to the current patch version in the VERSION file, and write it back out. task :bump_patch do current_version = version new_version = current_version.sub(/^(\d+\.\d+\.)(\d+)/) { "#{$1}#{$2.to_i + 1}" } puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}" IO.write(version_file_path, new_version) end task :bump_minor do current_version = version new_version = current_version.sub(/^(\d+)\.(\d+)\.(\d+)/) { "#{$1}.#{$2.to_i + 1}.0" } puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}" IO.write(version_file_path, new_version) end task :bump_major do current_version = version new_version = current_version.sub(/^(\d+)\.(\d+\.\d+)/) { "#{$1.to_i + 1}.0.0" } puts "Updating version in #{version_rb_path} from #{current_version.chomp} to #{new_version.chomp}" IO.write(version_file_path, new_version) end def update_version_rb # rubocop:disable Lint/NestedMethodDefinition puts "Updating #{version_rb_path} to include version #{version} ..." contents = "# Copyright:: Copyright 2010-2016, Chef Software, Inc.\n# License:: Apache License, Version 2.0\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n# http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n# NOTE: This file is generated by running `rake version` in the top level of\n# this repo. Do not edit this manually. Edit the VERSION file and run the rake\n# task instead.\n#!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n\#{\"\\nrequire \\\"chef/version_string\\\"\\n\" if use_versionstring}\n\#{class_or_module} \#{module_name}\n \#{module_name.upcase}_ROOT = File.expand_path(\"../..\", __FILE__)\n VERSION = \#{use_versionstring ? \"Chef::VersionString.new(\\\"\#{version}\\\")\" : \"\\\"\#{version}\\\"\"}\nend\n\n#\n# NOTE: the Chef::Version class is defined in version_class.rb\n#\n# NOTE: DO NOT Use the Chef::Version class on \#{module_name}::VERSIONs. The\n# Chef::Version class is for _cookbooks_ only, and cannot handle\n# pre-release versions like \"10.14.0.rc.2\". Please use Rubygem's\n# Gem::Version class instead.\n#\n VERSION_RB\n IO.write(version_rb_path, contents)\n end\n\n def update_gemfile_lock # rubocop:disable Lint/NestedMethodDefinition\n if File.exist?(gemfile_lock_path)\n puts \"Updating \#{gemfile_lock_path} to include version \#{version} ...\"\n contents = IO.read(gemfile_lock_path)\n contents.gsub!(/^\\s*(chef|chef-config)\\s*\\((= )?\\S+\\)\\s*$/) do |line|\n line.gsub(/\\((= )?\\d+(\\.\\d+)+/) { \"(\#{$1}\#{version}\" }\n end\n IO.write(gemfile_lock_path, contents)\n end\n end\n end\n\n task :version => \"version:update\"\n\n gemspec_platform_to_install = \"\"\n Dir[File.expand_path(\"*.gemspec\", root_path)].reverse_each do |gemspec_path|\n gemspec = eval(IO.read(gemspec_path))\n Gem::PackageTask.new(gemspec) do |task|\n task.package_dir = full_package_dir\n end\n gemspec_platform_to_install = \"-\#{gemspec.platform}\" if gemspec.platform != Gem::Platform::RUBY && Gem::Platform.match(gemspec.platform)\n end\n\n desc \"Build and install a \#{module_path} gem\"\n task :install => [:package] do\n with_clean_env do\n full_module_path = File.join(full_package_dir, module_path)\n sh %{gem install \#{full_module_path}-\#{version}\#{gemspec_platform_to_install}.gem --no-rdoc --no-ri}\n end\n end\n\n task :uninstall do\n sh %{gem uninstall \#{module_path} -x -v \#{version} }\n end\n\n desc \"Build it, tag it and ship it\"\n task :ship => [:clobber_package, :gem] do\n sh(\"git tag \#{version}\")\n sh(\"git push \#{git_remote} --tags\")\n Dir[File.expand_path(\"*.gem\", full_package_dir)].reverse_each do |built_gem|\n sh(\"gem push \#{built_gem}\")\n end\n end\nend\n" |
#full_package_dir ⇒ Object
106 107 108 |
# File 'lib/chef-config/package_task.rb', line 106 def full_package_dir File.(package_dir, root_path) end |
#gemfile_lock_path ⇒ Object
98 99 100 |
# File 'lib/chef-config/package_task.rb', line 98 def gemfile_lock_path File.join(root_path, "Gemfile.lock") end |
#init(root_path, module_name, gem_name) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/chef-config/package_task.rb', line 71 def init(root_path, module_name, gem_name) @root_path = root_path @module_name = module_name @gem_name = gem_name @component_paths = [] @module_path = nil @package_dir = "pkg" @git_remote = "origin" @generate_version_class = false end |
#version ⇒ Object
102 103 104 |
# File 'lib/chef-config/package_task.rb', line 102 def version IO.read(version_file_path).strip end |
#version_file_path ⇒ Object
94 95 96 |
# File 'lib/chef-config/package_task.rb', line 94 def version_file_path File.join(chef_root_path, "VERSION") end |
#version_rb_path ⇒ Object
86 87 88 |
# File 'lib/chef-config/package_task.rb', line 86 def version_rb_path File.("lib/#{module_path}/version.rb", root_path) end |
#with_clean_env(&block) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/chef-config/package_task.rb', line 114 def with_clean_env(&block) if defined?(Bundler) Bundler.with_clean_env(&block) else yield end end |