Sha256: f565771df6cd591a7ac1f060a835ac66bef412159bdc73f1a585f57bd37c07db

Contents?: true

Size: 1.85 KB

Versions: 6

Compression:

Stored size: 1.85 KB

Contents

#
# Copyright:: Copyright (c) 2016 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.
#

# Putting this method in a module so it is easier to test
module RakeDependenciesTaskHelpers
  def update_gemfile_from_stable(gemfile, product_name, gemfile_name, version_prefix = "")
    version = get_latest_version_for(product_name)
    version = "#{version_prefix}#{version}"
    found = gemfile.sub!(/^(\s*gem "#{gemfile_name}", github: "chef\/#{gemfile_name}", branch: ")([^"]*)(")$/m) do
      if $2 != "#{version}"
        puts "Setting #{product_name} version in Gemfile to #{version} (was #{$2})"
      else
        puts "#{product_name} version in Gemfile already at latest stable (#{$2})"
      end
      "#{$1}#{version}#{$3}"
    end
    unless found
      raise "Gemfile does not have a line of the form 'gem \"#{gemfile_name}\", github: \"chef/#{gemfile_name}\", branch: \"<version>\"', so we didn't update it to latest stable (#{version})."
    end
    gemfile
  end

  def get_latest_version_for(product_name, channel_name = :stable)
    require "mixlib/install"
    puts "Getting latest '#{channel_name}' channel #{product_name} version ..."
    options = {
      channel: channel_name.to_sym,
      product_version: :latest,
      product_name: product_name,
    }
    Mixlib::Install.new(options).artifact_info.first.version
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
chef-dk-1.6.11 tasks/helpers.rb
chef-dk-1.6.1 tasks/helpers.rb
chef-dk-1.5.0 tasks/helpers.rb
chef-dk-1.4.3 tasks/helpers.rb
chef-dk-1.3.43 tasks/helpers.rb
chef-dk-1.3.40 tasks/helpers.rb