1
- source ENV [ 'GEM_SOURCE' ] || 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
2
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 } ]
6
23
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 } ]
11
24
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 ( ', ' ) } "
13
35
end
14
36
end
15
37
@@ -34,14 +56,16 @@ group :development do
34
56
gem "rubocop-performance" , '= 1.16.0' , require : false
35
57
gem "rubocop-rspec" , '= 2.19.0' , require : false
36
58
gem "rb-readline" , '= 0.5.5' , require : false , platforms : [ :mswin , :mingw , :x64_mingw ]
59
+ gem "bigdecimal" , '< 3.2.2' , require : false , platforms : [ :mswin , :mingw , :x64_mingw ]
37
60
end
38
61
group :development , :release_prep do
39
62
gem "puppet-strings" , '~> 4.0' , require : false
40
63
gem "puppetlabs_spec_helper" , '~> 8.0' , require : false
41
64
gem "puppet-blacksmith" , '~> 7.0' , require : false
42
65
end
43
66
group :system_tests do
44
- gem "puppet_litmus" , '~> 1.0' , require : false , platforms : [ :ruby , :x64_mingw ]
67
+ gem "puppet_litmus" , '~> 2.0' , require : false , platforms : [ :ruby , :x64_mingw ] if !ENV [ 'PUPPET_FORGE_TOKEN' ] . to_s . empty?
68
+ gem "puppet_litmus" , '~> 1.0' , require : false , platforms : [ :ruby , :x64_mingw ] if ENV [ 'PUPPET_FORGE_TOKEN' ] . to_s . empty?
45
69
gem "CFPropertyList" , '< 3.0.7' , require : false , platforms : [ :mswin , :mingw , :x64_mingw ]
46
70
gem "serverspec" , '~> 2.41' , require : false
47
71
end
@@ -51,31 +75,27 @@ puppet_version = ENV.fetch('PUPPET_GEM_VERSION', nil)
51
75
facter_version = ENV . fetch ( 'FACTER_GEM_VERSION' , nil )
52
76
hiera_version = ENV . fetch ( 'HIERA_GEM_VERSION' , nil )
53
77
54
- # If PUPPET_FORGE_TOKEN is set then use authenticated source for both puppet and facter, since facter is a transitive dependency of puppet
55
- # Otherwise, do as before and use location_for to fetch gems from the default source
56
- if !ENV [ 'PUPPET_FORGE_TOKEN' ] . to_s . empty?
57
- gems [ 'puppet' ] = [ '~> 8.11' , { require : false , source : 'https://rubygems-puppetcore.puppet.com' } ]
58
- gems [ 'facter' ] = [ '~> 4.11' , { require : false , source : 'https://rubygems-puppetcore.puppet.com' } ]
59
- else
60
- gems [ 'puppet' ] = location_for ( puppet_version )
61
- gems [ 'facter' ] = location_for ( facter_version ) if facter_version
62
- end
63
-
64
- gems [ 'hiera' ] = location_for ( hiera_version ) if hiera_version
78
+ gems [ 'puppet' ] = location_for ( puppet_version , nil , { source : gemsource_puppetcore } )
79
+ gems [ 'facter' ] = location_for ( facter_version , nil , { source : gemsource_puppetcore } )
80
+ gems [ 'hiera' ] = location_for ( hiera_version , nil , { } ) if hiera_version
65
81
82
+ # Generate the gem definitions
83
+ print_gem_statement_for ( gems ) if ENV [ 'DEBUG' ]
66
84
gems . each do |gem_name , gem_params |
67
85
gem gem_name , *gem_params
68
86
end
69
87
70
88
# Evaluate Gemfile.local and ~/.gemfile if they exist
71
89
extra_gemfiles = [
72
90
"#{ __FILE__ } .local" ,
73
- File . join ( Dir . home , '.gemfile' ) ,
91
+ File . join ( Dir . home , '.gemfile' )
74
92
]
75
93
76
94
extra_gemfiles . each do |gemfile |
77
- if File . file? ( gemfile ) && File . readable? ( gemfile )
78
- eval ( File . read ( gemfile ) , binding )
79
- end
95
+ next unless File . file? ( gemfile ) && File . readable? ( gemfile )
96
+
97
+ # rubocop:disable Security/Eval
98
+ eval ( File . read ( gemfile ) , binding )
99
+ # rubocop:enable Security/Eval
80
100
end
81
101
# vim: syntax=ruby
0 commit comments