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
1638group :development do
17- gem "json" , '= 2.1.0' , require : false if Gem ::Requirement . create ( [ '>= 2.5.0' , '< 2.7.0' ] ) . satisfied_by? ( Gem ::Version . new ( RUBY_VERSION . dup ) )
18- gem "json" , '= 2.3.0' , require : false if Gem ::Requirement . create ( [ '>= 2.7.0' , '< 3.0.0' ] ) . satisfied_by? ( Gem ::Version . new ( RUBY_VERSION . dup ) )
19- gem "json" , '= 2.5.1' , require : false if Gem ::Requirement . create ( [ '>= 3.0.0' , '< 3.0.5' ] ) . satisfied_by? ( Gem ::Version . new ( RUBY_VERSION . dup ) )
2039 gem "json" , '= 2.6.1' , require : false if Gem ::Requirement . create ( [ '>= 3.1.0' , '< 3.1.3' ] ) . satisfied_by? ( Gem ::Version . new ( RUBY_VERSION . dup ) )
2140 gem "json" , '= 2.6.3' , require : false if Gem ::Requirement . create ( [ '>= 3.2.0' , '< 4.0.0' ] ) . satisfied_by? ( Gem ::Version . new ( RUBY_VERSION . dup ) )
2241 gem "racc" , '~> 1.4.0' , require : false if Gem ::Requirement . create ( [ '>= 2.7.0' , '< 3.0.0' ] ) . satisfied_by? ( Gem ::Version . new ( RUBY_VERSION . dup ) )
4362group :development , :release_prep do
4463 gem "puppet-strings" , '~> 4.0' , require : false
4564 gem "puppetlabs_spec_helper" , '~> 8.0' , require : false
65+ gem "puppet-blacksmith" , '~> 7.0' , require : false
4666end
4767group :system_tests do
4868 gem "puppet_litmus" , '~> 2.0' , require : false , platforms : [ :ruby , :x64_mingw ] if !ENV [ 'PUPPET_FORGE_TOKEN' ] . to_s . empty?
@@ -51,41 +71,32 @@ group :system_tests do
5171 gem "serverspec" , '~> 2.41' , require : false
5272end
5373
54- puppet_version = ENV [ 'PUPPET_GEM_VERSION' ]
55- facter_version = ENV [ 'FACTER_GEM_VERSION' ]
56- hiera_version = ENV [ 'HIERA_GEM_VERSION' ]
57-
5874gems = { }
59-
6075puppet_version = ENV . fetch ( 'PUPPET_GEM_VERSION' , nil )
6176facter_version = ENV . fetch ( 'FACTER_GEM_VERSION' , nil )
6277hiera_version = ENV . fetch ( 'HIERA_GEM_VERSION' , nil )
6378
64- # If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
65- # Otherwise, do as before and use location_for to fetch gems from the default source
66- if !ENV [ 'PUPPET_FORGE_TOKEN' ] . to_s . empty?
67- gems [ 'puppet' ] = [ '~> 8.11' , { require : false , source : 'https://rubygems-puppetcore.puppet.com' } ]
68- gems [ 'facter' ] = [ '~> 4.11' , { require : false , source : 'https://rubygems-puppetcore.puppet.com' } ]
69- else
70- gems [ 'puppet' ] = location_for ( puppet_version )
71- gems [ 'facter' ] = location_for ( facter_version ) if facter_version
72- end
73-
74- gems [ 'hiera' ] = location_for ( hiera_version ) if hiera_version
79+ gems [ 'puppet' ] = location_for ( puppet_version , nil , { source : gemsource_puppetcore } )
80+ gems [ 'facter' ] = location_for ( facter_version , nil , { source : gemsource_puppetcore } )
81+ gems [ 'hiera' ] = location_for ( hiera_version , nil , { } ) if hiera_version
7582
83+ # Generate the gem definitions
84+ print_gem_statement_for ( gems ) if ENV [ 'DEBUG' ]
7685gems . each do |gem_name , gem_params |
7786 gem gem_name , *gem_params
7887end
7988
8089# Evaluate Gemfile.local and ~/.gemfile if they exist
8190extra_gemfiles = [
8291 "#{ __FILE__ } .local" ,
83- File . join ( Dir . home , '.gemfile' ) ,
92+ File . join ( Dir . home , '.gemfile' )
8493]
8594
8695extra_gemfiles . each do |gemfile |
87- if File . file? ( gemfile ) && File . readable? ( gemfile )
88- eval ( File . read ( gemfile ) , binding )
89- end
96+ next unless File . file? ( gemfile ) && File . readable? ( gemfile )
97+
98+ # rubocop:disable Security/Eval
99+ eval ( File . read ( gemfile ) , binding )
100+ # rubocop:enable Security/Eval
90101end
91102# vim: syntax=ruby
0 commit comments