Sha256: fd4c618de075b682247ae6adc7e72a622e5851419609713c7116ab0bcd6b96b4

Contents?: true

Size: 1.85 KB

Versions: 13

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

13 entries across 13 versions & 1 rubygems

Version Path
chef-dk-1.2.22 tasks/helpers.rb
chef-dk-1.2.20 tasks/helpers.rb
chef-dk-1.1.16 tasks/helpers.rb
chef-dk-1.0.3 tasks/helpers.rb
chef-dk-0.19.6 tasks/helpers.rb
chef-dk-0.18.30 tasks/helpers.rb
chef-dk-0.18.26 tasks/helpers.rb
chef-dk-0.17.17 tasks/helpers.rb
chef-dk-0.16.28 tasks/helpers.rb
chef-dk-0.15.16 tasks/helpers.rb
chef-dk-0.15.15 tasks/helpers.rb
chef-dk-0.15.9 tasks/helpers.rb
chef-dk-0.14.25 tasks/helpers.rb