1- source ENV [ 'GEM_SOURCE' ] || 'https://rubygems.org'
1+ # frozen_string_literal: true
22
3- def location_for ( place_or_version , fake_version = nil )
4- git_url_regex = %r{\A (?<url>(https?|git)[:@][^#]*)(#(?<branch>.*))?}
5- file_url_regex = %r{\A file:\/ \/ (?<path>.*)}
3+ # For puppetcore, set GEM_SOURCE_PUPPETCORE = 'https://rubygems-puppetcore.puppet.com'
4+ gemsource_default = ENV [ 'GEM_SOURCE' ] || 'https://rubygems.org'
5+ gemsource_puppetcore = if ENV [ 'PUPPET_FORGE_TOKEN' ]
6+ 'https://rubygems-puppetcore.puppet.com'
7+ else
8+ ENV [ 'GEM_SOURCE_PUPPETCORE' ] || gemsource_default
9+ end
10+ source gemsource_default
11+
12+ def location_for ( place_or_constraint , fake_constraint = nil , opts = { } )
13+ git_url_regex = /\A (?<url>(?:https?|git)[:@][^#]*)(?:#(?<branch>.*))?/
14+ file_url_regex = %r{\A file://(?<path>.*)}
15+
16+ if place_or_constraint && ( git_url = place_or_constraint . match ( git_url_regex ) )
17+ # Git source → ignore :source, keep fake_constraint
18+ [ fake_constraint , { git : git_url [ :url ] , branch : git_url [ :branch ] , require : false } ] . compact
19+
20+ elsif place_or_constraint && ( file_url = place_or_constraint . match ( file_url_regex ) )
21+ # File source → ignore :source, keep fake_constraint or default >= 0
22+ [ fake_constraint || '>= 0' , { path : File . expand_path ( file_url [ :path ] ) , require : false } ]
623
7- if place_or_version && ( git_url = place_or_version . match ( git_url_regex ) )
8- [ fake_version , { git : git_url [ :url ] , branch : git_url [ :branch ] , require : false } ] . compact
9- elsif place_or_version && ( file_url = place_or_version . match ( file_url_regex ) )
10- [ '>= 0' , { path : File . expand_path ( file_url [ :path ] ) , require : false } ]
1124 else
12- [ place_or_version , { require : false } ]
25+ # Plain version constraint → merge opts (including :source if provided)
26+ [ place_or_constraint , { require : false } . merge ( opts ) ]
27+ end
28+ end
29+
30+ # Print debug information if DEBUG_GEMS or VERBOSE is set
31+ def print_gem_statement_for ( gems )
32+ puts 'DEBUG: Gem definitions that will be generated:'
33+ gems . each do |gem_name , gem_params |
34+ puts "DEBUG: gem #{ ( [ gem_name . inspect ] + gem_params . map ( &:inspect ) ) . join ( ', ' ) } "
1335 end
1436end
1537
@@ -30,9 +52,12 @@ group :development do
3052 gem "pry" , '~> 0.10' , require : false
3153 gem "simplecov-console" , '~> 0.9' , require : false
3254 gem "puppet-debugger" , '~> 1.6' , require : false
33- gem "rubocop" , '~> 1.50.0' , require : false
34- gem "rubocop-performance" , '= 1.16.0' , require : false
35- gem "rubocop-rspec" , '= 2.19.0' , require : false
55+ gem "rubocop" , '~> 1.73.0' , require : false
56+ gem "rubocop-performance" , '~> 1.24.0' , require : false
57+ gem "rubocop-rspec" , '~> 3.5.0' , require : false
58+ gem "rubocop-rspec_rails" , '~> 2.31.0' , require : false
59+ gem "rubocop-factory_bot" , '~> 2.27.0' , require : false
60+ gem "rubocop-capybara" , '~> 2.22.0' , require : false
3661 gem "rb-readline" , '= 0.5.5' , require : false , platforms : [ :mswin , :mingw , :x64_mingw ]
3762 gem "bigdecimal" , '< 3.2.2' , require : false , platforms : [ :mswin , :mingw , :x64_mingw ]
3863end
@@ -53,31 +78,27 @@ puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil)
5378facter_version = ENV . fetch ( 'FACTER_GEM_VERSION' , nil )
5479hiera_version = ENV . fetch ( 'HIERA_GEM_VERSION' , nil )
5580
56- # If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
57- # Otherwise, do as before and use location_for to fetch gems from the default source
58- if !ENV [ 'PUPPET_FORGE_TOKEN' ] . to_s . empty?
59- gems [ 'puppet' ] = [ '~> 8.11' , { require : false , source : 'https://rubygems-puppetcore.puppet.com' } ]
60- gems [ 'facter' ] = [ '~> 4.11' , { require : false , source : 'https://rubygems-puppetcore.puppet.com' } ]
61- else
62- gems [ 'puppet' ] = location_for ( puppet_version )
63- gems [ 'facter' ] = location_for ( facter_version ) if facter_version
64- end
65-
66- gems [ 'hiera' ] = location_for ( hiera_version ) if hiera_version
81+ gems [ 'puppet' ] = location_for ( puppet_version , nil , { source : gemsource_puppetcore } )
82+ gems [ 'facter' ] = location_for ( facter_version , nil , { source : gemsource_puppetcore } )
83+ gems [ 'hiera' ] = location_for ( hiera_version , nil , { } ) if hiera_version
6784
85+ # Generate the gem definitions
86+ print_gem_statement_for ( gems ) if ENV [ 'DEBUG' ]
6887gems . each do |gem_name , gem_params |
6988 gem gem_name , *gem_params
7089end
7190
7291# Evaluate Gemfile.local and ~/.gemfile if they exist
7392extra_gemfiles = [
7493 "#{ __FILE__ } .local" ,
75- File . join ( Dir . home , '.gemfile' ) ,
94+ File . join ( Dir . home , '.gemfile' )
7695]
7796
7897extra_gemfiles . each do |gemfile |
79- if File . file? ( gemfile ) && File . readable? ( gemfile )
80- eval ( File . read ( gemfile ) , binding )
81- end
98+ next unless File . file? ( gemfile ) && File . readable? ( gemfile )
99+
100+ # rubocop:disable Security/Eval
101+ eval ( File . read ( gemfile ) , binding )
102+ # rubocop:enable Security/Eval
82103end
83104# vim: syntax=ruby
0 commit comments