simp-rake-helpers 5.25.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +26 -0
  3. data/Gemfile +13 -6
  4. data/lib/simp/command_utils.rb +6 -3
  5. data/lib/simp/componentinfo.rb +47 -33
  6. data/lib/simp/local_gpg_signing_key.rb +302 -303
  7. data/lib/simp/packer/iso_vars_json.rb +17 -15
  8. data/lib/simp/rake/build/auto.rb +415 -432
  9. data/lib/simp/rake/build/build.rb +119 -124
  10. data/lib/simp/rake/build/clean.rb +39 -39
  11. data/lib/simp/rake/build/code.rb +125 -128
  12. data/lib/simp/rake/build/constants.rb +7 -4
  13. data/lib/simp/rake/build/deps.rb +196 -207
  14. data/lib/simp/rake/build/helpers.rb +17 -13
  15. data/lib/simp/rake/build/iso.rb +404 -411
  16. data/lib/simp/rake/build/pkg.rb +752 -759
  17. data/lib/simp/rake/build/rpmdeps.rb +70 -70
  18. data/lib/simp/rake/build/spec.rb +44 -46
  19. data/lib/simp/rake/build/tar.rb +169 -173
  20. data/lib/simp/rake/build/unpack.rb +105 -107
  21. data/lib/simp/rake/build/upload.rb +93 -102
  22. data/lib/simp/rake/fixtures.rb +69 -66
  23. data/lib/simp/rake/helpers/rpm_spec.rb +10 -7
  24. data/lib/simp/rake/helpers/version.rb +3 -1
  25. data/lib/simp/rake/helpers.rb +12 -10
  26. data/lib/simp/rake/pkg.rb +417 -440
  27. data/lib/simp/rake/pupmod/helpers.rb +100 -87
  28. data/lib/simp/rake/pupmod/module_build.rb +39 -0
  29. data/lib/simp/rake/rubygem.rb +57 -56
  30. data/lib/simp/rake.rb +34 -29
  31. data/lib/simp/relchecks.rb +52 -43
  32. data/lib/simp/rpm.rb +123 -127
  33. data/lib/simp/rpm_signer.rb +57 -55
  34. data/lib/simp/yum.rb +54 -53
  35. data/spec/acceptance/nodesets/{default_ruby3_1.yml → almalinux10.yml} +4 -4
  36. data/spec/acceptance/nodesets/{default.yml → almalinux8.yml} +2 -2
  37. data/spec/acceptance/nodesets/almalinux9.yml +25 -0
  38. data/spec/acceptance/suites/default/00_pkg_rpm_custom_scriptlets_spec.rb +23 -28
  39. data/spec/acceptance/suites/default/10_pkg_rpm_spec.rb +54 -56
  40. data/spec/acceptance/suites/default/30_pkg_misc_spec.rb +17 -19
  41. data/spec/acceptance/suites/default/50_local_gpg_signing_key_spec.rb +5 -5
  42. data/spec/acceptance/suites/default/55_build_pkg_signing_spec.rb +109 -101
  43. data/spec/acceptance/suites/default/files/testpackage/spec/classes/init_spec.rb +1 -0
  44. data/spec/acceptance/suites/default/files/testpackage/spec/files/mock_something.rb +3 -1
  45. data/spec/acceptance/suites/default/files/testpackage/utils/convert_v1_to_v2.rb +2 -0
  46. data/spec/acceptance/suites/default/support/build_project_helpers.rb +20 -17
  47. data/spec/acceptance/suites/default/support/build_user_helpers.rb +4 -2
  48. data/spec/acceptance/suites/default/support/pkg_rpm_helpers.rb +30 -31
  49. data/spec/acceptance/support/simp_rake_helpers.rb +3 -1
  50. data/spec/lib/simp/command_utils_spec.rb +13 -10
  51. data/spec/lib/simp/componentinfo_changelog_regex_spec.rb +33 -33
  52. data/spec/lib/simp/componentinfo_spec.rb +99 -86
  53. data/spec/lib/simp/packer/iso_vars_json_spec.rb +16 -14
  54. data/spec/lib/simp/rake/build/helpers_spec.rb +7 -7
  55. data/spec/lib/simp/rake/build/rpmdeps_spec.rb +48 -46
  56. data/spec/lib/simp/rake/helpers_spec.rb +6 -5
  57. data/spec/lib/simp/rake/pkg_spec.rb +7 -5
  58. data/spec/lib/simp/rake/pupmod/fixtures/othermod/spec/classes/init_spec.rb +3 -1
  59. data/spec/lib/simp/rake/pupmod/fixtures/othermod/spec/spec_helper.rb +2 -0
  60. data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/acceptance/suites/default/class_spec.rb +6 -5
  61. data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/classes/init_spec.rb +51 -33
  62. data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/spec_helper.rb +15 -16
  63. data/spec/lib/simp/rake/pupmod/fixtures/simpmod/spec/spec_helper_acceptance.rb +9 -9
  64. data/spec/lib/simp/rake/pupmod/helpers_spec.rb +20 -19
  65. data/spec/lib/simp/rake/pupmod/module_build_spec.rb +87 -0
  66. data/spec/lib/simp/rake_spec.rb +7 -6
  67. data/spec/lib/simp/relchecks_check_rpm_changelog_spec.rb +26 -31
  68. data/spec/lib/simp/relchecks_compare_latest_tag_spec.rb +32 -26
  69. data/spec/lib/simp/relchecks_create_tag_changelog_spec.rb +27 -19
  70. data/spec/lib/simp/rpm_signer_spec.rb +45 -39
  71. data/spec/lib/simp/rpm_spec.rb +190 -194
  72. data/spec/spec_helper.rb +4 -2
  73. data/spec/spec_helper_acceptance.rb +3 -5
  74. metadata +37 -72
  75. data/bin/simp_rake_helpers +0 -3
  76. data/lib/simp/ci/gitlab.rb +0 -226
  77. data/lib/simp/rake/ci.rb +0 -31
  78. data/spec/lib/simp/ci/files/global_nodesets_only/spec/acceptance/nodesets/default.yml +0 -41
  79. data/spec/lib/simp/ci/files/global_nodesets_only/spec/acceptance/nodesets/oel.yml +0 -41
  80. data/spec/lib/simp/ci/files/job_broken_link_nodeset/spec/acceptance/nodesets/centos.yml +0 -41
  81. data/spec/lib/simp/ci/files/job_broken_link_nodeset/spec/acceptance/nodesets/oel.yml +0 -41
  82. data/spec/lib/simp/ci/files/job_broken_link_nodeset/spec/acceptance/suites/default/class_spec.rb +0 -0
  83. data/spec/lib/simp/ci/files/job_invalid_nodeset/spec/acceptance/nodesets/default.yml +0 -41
  84. data/spec/lib/simp/ci/files/job_invalid_nodeset/spec/acceptance/nodesets/oel.yml +0 -41
  85. data/spec/lib/simp/ci/files/job_invalid_nodeset/spec/acceptance/suites/default/class_spec.rb +0 -0
  86. data/spec/lib/simp/ci/files/job_invalid_suite/spec/acceptance/nodesets/default.yml +0 -41
  87. data/spec/lib/simp/ci/files/job_invalid_suite/spec/acceptance/nodesets/oel.yml +0 -41
  88. data/spec/lib/simp/ci/files/job_invalid_suite/spec/acceptance/suites/default/class_spec.rb +0 -0
  89. data/spec/lib/simp/ci/files/job_missing_nodeset/spec/acceptance/nodesets/default.yml +0 -41
  90. data/spec/lib/simp/ci/files/job_missing_nodeset/spec/acceptance/nodesets/oel.yml +0 -41
  91. data/spec/lib/simp/ci/files/job_missing_nodeset/spec/acceptance/suites/default/class_spec.rb +0 -0
  92. data/spec/lib/simp/ci/files/job_missing_suite_and_nodeset/spec/acceptance/nodesets/default.yml +0 -41
  93. data/spec/lib/simp/ci/files/job_missing_suite_and_nodeset/spec/acceptance/nodesets/oel.yml +0 -41
  94. data/spec/lib/simp/ci/files/job_missing_suite_and_nodeset/spec/acceptance/suites/default/class_spec.rb +0 -0
  95. data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/nodesets/default.yml +0 -41
  96. data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/nodesets/oel.yml +0 -41
  97. data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/suites/default/class_spec.rb +0 -0
  98. data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/suites/feature-1/feature-1_spec.rb +0 -0
  99. data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/suites/feature_2/feature_2_spec.rb +0 -0
  100. data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/suites/feature_2/nodesets/default.yml +0 -35
  101. data/spec/lib/simp/ci/files/multiple_invalid_jobs/spec/acceptance/suites/feature_2/nodesets/oel.yml +0 -35
  102. data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/nodesets/default.yml +0 -41
  103. data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/nodesets/oel.yml +0 -41
  104. data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/suites/default/class_spec.rb +0 -0
  105. data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/suites/feature-1/feature-1_spec.rb +0 -0
  106. data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/suites/feature_2/feature_2_spec.rb +0 -0
  107. data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/suites/feature_2/nodesets/default.yml +0 -35
  108. data/spec/lib/simp/ci/files/multiple_valid_jobs/spec/acceptance/suites/feature_2/nodesets/oel.yml +0 -35
  109. data/spec/lib/simp/ci/files/no_acceptance_tests/spec/spec_helper.rb +0 -0
  110. data/spec/lib/simp/ci/files/no_gitlab_config_with_tests/spec/acceptance/nodesets/default.yml +0 -41
  111. data/spec/lib/simp/ci/files/no_gitlab_config_with_tests/spec/acceptance/nodesets/oel.yml +0 -41
  112. data/spec/lib/simp/ci/files/no_gitlab_config_with_tests/spec/acceptance/suites/default/class_spec.rb +0 -0
  113. data/spec/lib/simp/ci/files/no_gitlab_config_without_tests/spec/acceptance/nodesets/default.yml +0 -41
  114. data/spec/lib/simp/ci/files/no_gitlab_config_without_tests/spec/acceptance/nodesets/oel.yml +0 -41
  115. data/spec/lib/simp/ci/files/suite_skeleton_only/spec/acceptance/nodesets/centos.yml +0 -41
  116. data/spec/lib/simp/ci/files/suite_skeleton_only/spec/acceptance/nodesets/oel.yml +0 -41
  117. data/spec/lib/simp/ci/files/valid_job_global_nodeset/spec/acceptance/nodesets/default.yml +0 -41
  118. data/spec/lib/simp/ci/files/valid_job_global_nodeset/spec/acceptance/nodesets/oel.yml +0 -41
  119. data/spec/lib/simp/ci/files/valid_job_global_nodeset/spec/acceptance/suites/default/class_spec.rb +0 -0
  120. data/spec/lib/simp/ci/files/valid_job_nodeset_dir_link/spec/acceptance/nodesets/default.yml +0 -41
  121. data/spec/lib/simp/ci/files/valid_job_nodeset_dir_link/spec/acceptance/nodesets/oel.yml +0 -41
  122. data/spec/lib/simp/ci/files/valid_job_nodeset_dir_link/spec/acceptance/suites/default/class_spec.rb +0 -0
  123. data/spec/lib/simp/ci/files/valid_job_nodeset_link/spec/acceptance/suites/default/class_spec.rb +0 -0
  124. data/spec/lib/simp/ci/files/valid_job_nodeset_link/spec/acceptance/suites/default/nodesets/centos.yml +0 -41
  125. data/spec/lib/simp/ci/files/valid_job_nodeset_link/spec/acceptance/suites/default/nodesets/oel.yml +0 -41
  126. data/spec/lib/simp/ci/files/valid_job_suite_nodeset/spec/acceptance/suites/default/class_spec.rb +0 -0
  127. data/spec/lib/simp/ci/files/valid_job_suite_nodeset/spec/acceptance/suites/default/nodesets/default.yml +0 -41
  128. data/spec/lib/simp/ci/files/valid_job_suite_nodeset/spec/acceptance/suites/default/nodesets/oel.yml +0 -41
  129. data/spec/lib/simp/ci/gitlab_spec.rb +0 -245
data/lib/simp/rake/pkg.rb CHANGED
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file provided many common build-related tasks and helper methods from
2
4
  # the SIMP Rakefile ecosystem.
3
5
 
6
+ require 'English'
4
7
  require 'rake'
5
8
  require 'rake/clean'
6
9
  require 'rake/tasklib'
@@ -12,519 +15,502 @@ require 'simp/rake/helpers/rpm_spec'
12
15
  require 'simp/rake/build/rpmdeps'
13
16
 
14
17
  module Simp; end
15
- module Simp::Rake
16
- class Pkg < ::Rake::TaskLib
17
-
18
- include Simp::Rake::Helpers::RPMSpec
19
-
20
- # path to the project's directory. Usually `File.dirname(__FILE__)`
21
- attr_accessor :base_dir
22
-
23
- # the name of the package. Usually `File.basename(@base_dir)`
24
- attr_accessor :pkg_name
25
-
26
- # path to the project's RPM specfile
27
- attr_accessor :spec_file
28
-
29
- # path to the directory to place generated assets (e.g., rpm, tar.gz)
30
- attr_accessor :pkg_dir
31
-
32
- # array of items to exclude from the tarball
33
- attr_accessor :exclude_list
34
-
35
- # array of items to additionally clean
36
- attr_accessor :clean_list
37
-
38
- # array of items to ignore when checking if the tarball needs to be rebuilt
39
- attr_accessor :ignore_changes_list
40
-
41
- attr_reader :spec_info
42
-
43
- def initialize( base_dir, unique_namespace = nil, simp_version=nil )
44
- @base_dir = base_dir
45
- @pkg_name = File.basename(@base_dir)
46
- @pkg_dir = File.join(@base_dir, 'dist')
47
- @pkg_tmp_dir = File.join(@pkg_dir, 'tmp')
48
- @exclude_list = [ File.basename(@pkg_dir) ]
49
- @clean_list = []
50
- @ignore_changes_list = [
51
- 'Gemfile.lock',
52
- 'dist/logs',
53
- 'dist/tmp',
54
- 'dist/*.rpm',
55
- 'dist/rpmbuild',
56
- 'spec/fixtures/modules'
57
- ]
58
- @verbose = ENV.fetch('SIMP_RAKE_PKG_verbose','no') == 'yes'
59
-
60
- # This is only meant to be used to work around the case where particular
61
- # packages need to ignore some set of artifacts that get updated out of
62
- # band. This should not be set as a regular environment variable and
63
- # should be fixed properly at some time in the future.
64
- #
65
- # Presently, this is used by simp-doc
66
- if ENV['SIMP_INTERNAL_pkg_ignore']
67
- @ignore_changes_list += ENV['SIMP_INTERNAL_pkg_ignore'].split(',')
68
- end
69
18
 
70
- FileUtils.mkdir_p(@pkg_tmp_dir, verbose: @verbose)
19
+ class Simp::Rake::Pkg < Rake::TaskLib
20
+ include Simp::Rake::Helpers::RPMSpec
21
+
22
+ # path to the project's directory. Usually `File.dirname(__FILE__)`
23
+ attr_accessor :base_dir
24
+
25
+ # the name of the package. Usually `File.basename(@base_dir)`
26
+ attr_accessor :pkg_name
27
+
28
+ # path to the project's RPM specfile
29
+ attr_accessor :spec_file
30
+
31
+ # path to the directory to place generated assets (e.g., rpm, tar.gz)
32
+ attr_accessor :pkg_dir
33
+
34
+ # array of items to exclude from the tarball
35
+ attr_accessor :exclude_list
36
+
37
+ # array of items to additionally clean
38
+ attr_accessor :clean_list
39
+
40
+ # array of items to ignore when checking if the tarball needs to be rebuilt
41
+ attr_accessor :ignore_changes_list
42
+
43
+ attr_reader :spec_info
44
+
45
+ def initialize(base_dir, unique_namespace = nil, simp_version = nil)
46
+ @base_dir = base_dir
47
+ @pkg_name = File.basename(@base_dir)
48
+ @pkg_dir = File.join(@base_dir, 'dist')
49
+ @pkg_tmp_dir = File.join(@pkg_dir, 'tmp')
50
+ @exclude_list = [File.basename(@pkg_dir)]
51
+ @clean_list = []
52
+ @ignore_changes_list = [
53
+ 'Gemfile.lock',
54
+ 'dist/logs',
55
+ 'dist/tmp',
56
+ 'dist/*.rpm',
57
+ 'dist/rpmbuild',
58
+ 'spec/fixtures/modules',
59
+ ]
60
+ @verbose = ENV.fetch('SIMP_RAKE_PKG_verbose', 'no') == 'yes'
61
+
62
+ # This is only meant to be used to work around the case where particular
63
+ # packages need to ignore some set of artifacts that get updated out of
64
+ # band. This should not be set as a regular environment variable and
65
+ # should be fixed properly at some time in the future.
66
+ #
67
+ # Presently, this is used by simp-doc
68
+ if ENV['SIMP_INTERNAL_pkg_ignore']
69
+ @ignore_changes_list += ENV['SIMP_INTERNAL_pkg_ignore'].split(',')
70
+ end
71
71
 
72
- local_spec = Dir.glob(File.join(@base_dir, 'build', '*.spec'))
73
- unless local_spec.empty?
74
- @spec_file = local_spec.first
75
- else
76
- @spec_tempfile = File.open(File.join(@pkg_tmp_dir, "#{@pkg_name}.spec"), 'w')
77
- @spec_tempfile.write(rpm_template(simp_version))
72
+ FileUtils.mkdir_p(@pkg_tmp_dir, verbose: @verbose)
78
73
 
79
- @spec_file = @spec_tempfile.path
74
+ local_spec = Dir.glob(File.join(@base_dir, 'build', '*.spec'))
75
+ if local_spec.empty?
76
+ @spec_tempfile = File.open(File.join(@pkg_tmp_dir, "#{@pkg_name}.spec"), 'w')
77
+ @spec_tempfile.write(rpm_template(simp_version))
80
78
 
81
- @spec_tempfile.flush
82
- @spec_tempfile.close
79
+ @spec_file = @spec_tempfile.path
83
80
 
84
- FileUtils.chmod(0640, @spec_file, verbose: @verbose)
85
- end
81
+ @spec_tempfile.flush
82
+ @spec_tempfile.close
86
83
 
87
- ::CLEAN.include( @pkg_dir )
84
+ FileUtils.chmod(0o640, @spec_file, verbose: @verbose)
85
+ else
86
+ @spec_file = local_spec.first
87
+ end
88
88
 
89
- yield self if block_given?
89
+ ::CLEAN.include(@pkg_dir)
90
90
 
91
- ::CLEAN.include( @clean_list )
91
+ yield self if block_given?
92
92
 
93
- if unique_namespace
94
- namespace unique_namespace.to_sym do
95
- define
96
- end
97
- else
93
+ ::CLEAN.include(@clean_list)
94
+
95
+ if unique_namespace
96
+ namespace unique_namespace.to_sym do
98
97
  define
99
98
  end
99
+ else
100
+ define
100
101
  end
102
+ end
101
103
 
102
- def define
103
- # For the most part, we don't want to hear Rake's noise, unless it's an error
104
- # TODO: Make this configurable
105
- verbose(false)
106
-
107
- define_clean
108
- define_clobber
109
- define_pkg_tar
110
- define_pkg_rpm
111
- define_pkg_check_rpm_changelog
112
- define_pkg_check_version
113
- define_pkg_compare_latest_tag
114
- define_pkg_create_tag_changelog
115
- task :default => 'pkg:tar'
116
-
117
- Rake::Task['pkg:tar']
118
- Rake::Task['pkg:rpm']
119
-
120
- self
121
- end
104
+ def define
105
+ # For the most part, we don't want to hear Rake's noise, unless it's an error
106
+ # TODO: Make this configurable
107
+ verbose(false)
108
+
109
+ define_clean
110
+ define_clobber
111
+ define_pkg_tar
112
+ define_pkg_rpm
113
+ define_pkg_check_rpm_changelog
114
+ define_pkg_check_version
115
+ define_pkg_compare_latest_tag
116
+ define_pkg_create_tag_changelog
117
+ task :default => 'pkg:tar'
118
+
119
+ Rake::Task['pkg:tar']
120
+ Rake::Task['pkg:rpm']
121
+
122
+ self
123
+ end
122
124
 
123
- # Ensures that the correct file names are used across the board.
124
- def initialize_spec_info
125
- unless @spec_info
126
- # This gets the resting spec file and allows us to pull out the name
127
- @spec_info ||= Simp::RPM.new(@spec_file)
128
- @spec_info_dir ||= @base_dir
125
+ # Ensures that the correct file names are used across the board.
126
+ def initialize_spec_info
127
+ return if @spec_info
129
128
 
130
- @dir_name ||= "#{@spec_info.basename}-#{@spec_info.version}"
131
- @full_pkg_name ||= "#{@dir_name}-#{@spec_info.release}"
129
+ # This gets the resting spec file and allows us to pull out the name
130
+ @spec_info ||= Simp::RPM.new(@spec_file)
131
+ @spec_info_dir ||= @base_dir
132
132
 
133
- _rpmbuild_srcdir = `rpm -E '%{_sourcedir}'`.strip
133
+ @dir_name ||= "#{@spec_info.basename}-#{@spec_info.version}"
134
+ @full_pkg_name ||= "#{@dir_name}-#{@spec_info.release}"
134
135
 
135
- unless File.exist?(_rpmbuild_srcdir)
136
- sh 'rpmdev-setuptree'
137
- end
136
+ _rpmbuild_srcdir = `rpm -E '%{_sourcedir}'`.strip
138
137
 
139
- @rpm_srcdir ||= "#{@pkg_dir}/rpmbuild/SOURCES"
140
- FileUtils.mkdir_p(@rpm_srcdir, verbose: @verbose)
138
+ unless File.exist?(_rpmbuild_srcdir)
139
+ sh 'rpmdev-setuptree'
140
+ end
141
141
 
142
- @tar_dest ||= "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"
142
+ @rpm_srcdir ||= "#{@pkg_dir}/rpmbuild/SOURCES"
143
+ FileUtils.mkdir_p(@rpm_srcdir, verbose: @verbose)
143
144
 
144
- if @full_pkg_name =~ /UNKNOWN/
145
- fail("Error: Could not determine package information from 'metadata.json'. Got '#{@full_pkg_name}'")
146
- end
147
- end
148
- end
145
+ @tar_dest ||= "#{@pkg_dir}/#{@full_pkg_name}.tar.gz"
149
146
 
150
- def define_clean
151
- desc <<-EOM
147
+ return unless @full_pkg_name.include?('UNKNOWN')
148
+
149
+ raise("Error: Could not determine package information from 'metadata.json'. Got '#{@full_pkg_name}'")
150
+ end
151
+
152
+ def define_clean
153
+ desc <<-EOM
152
154
  Clean build artifacts for #{@pkg_name}
153
- EOM
154
- task :clean do |t,args|
155
- # this is provided by 'rake/clean' and the ::CLEAN constant
156
- end
155
+ EOM
156
+ task :clean do |t, args|
157
+ # this is provided by 'rake/clean' and the ::CLEAN constant
157
158
  end
159
+ end
158
160
 
159
- def define_clobber
160
- desc <<-EOM
161
+ def define_clobber
162
+ desc <<-EOM
161
163
  Clobber build artifacts for #{@pkg_name}
162
- EOM
163
- task :clobber do |t,args|
164
- end
164
+ EOM
165
+ task :clobber do |_t, _args|
166
+ # no-op placeholder
165
167
  end
168
+ end
166
169
 
167
- def define_pkg_tar
168
- namespace :pkg do
169
- directory @pkg_dir
170
+ def define_pkg_tar
171
+ namespace :pkg do
172
+ directory @pkg_dir
170
173
 
171
- task :initialize_spec_info => [@pkg_dir] do |t,args|
172
- initialize_spec_info
173
- end
174
+ task :initialize_spec_info => [@pkg_dir] do |_t, _args|
175
+ initialize_spec_info
176
+ end
174
177
 
175
- # :pkg:tar
176
- # -----------------------------
177
- desc <<-EOM
178
+ # :pkg:tar
179
+ # -----------------------------
180
+ desc <<-EOM
178
181
  Build the #{@pkg_name} tar package.
179
- EOM
180
- task :tar => [:initialize_spec_info] do |t,args|
181
- target_dir = File.basename(@base_dir)
182
+ EOM
183
+ task :tar => [:initialize_spec_info] do |_t, _args|
184
+ target_dir = File.basename(@base_dir)
182
185
 
183
- Dir.chdir(%(#{@base_dir}/..)) do
184
- require_rebuild = false
186
+ Dir.chdir(%(#{@base_dir}/..)) do
187
+ require_rebuild = false
185
188
 
186
- if File.exist?(@tar_dest)
187
- Find.find(target_dir) do |path|
188
- filename = File.basename(path)
189
+ if File.exist?(@tar_dest)
190
+ Find.find(target_dir) do |path|
191
+ filename = File.basename(path)
189
192
 
190
- Find.prune if filename =~ /^\./
191
- Find.prune if ((filename == File.basename(@pkg_dir)) && File.directory?(path))
193
+ Find.prune if %r{^\.}.match?(filename)
194
+ Find.prune if (filename == File.basename(@pkg_dir)) && File.directory?(path)
192
195
 
193
- to_ignore = @ignore_changes_list.map{|x| x = Dir.glob(File.join(@base_dir, x))}.flatten
194
- Find.prune if to_ignore.include?(File.expand_path(path))
196
+ to_ignore = @ignore_changes_list.map { |x| Dir.glob(File.join(@base_dir, x)) }.flatten
197
+ Find.prune if to_ignore.include?(File.expand_path(path))
195
198
 
196
- next if File.directory?(path)
199
+ next if File.directory?(path)
197
200
 
198
- if require_rebuild?(@tar_dest, path)
199
- require_rebuild = true
200
- break
201
- end
201
+ if require_rebuild?(@tar_dest, path)
202
+ require_rebuild = true
203
+ break
202
204
  end
203
- else
204
- require_rebuild = true
205
205
  end
206
+ else
207
+ require_rebuild = true
208
+ end
206
209
 
207
- if require_rebuild
208
- sh %Q(tar --owner 0 --group 0 --exclude-vcs --exclude=#{@exclude_list.join(' --exclude=')} --transform='s/^#{@pkg_name}/#{@dir_name}/' -cpzf "#{@tar_dest}" #{@pkg_name})
209
- end
210
+ if require_rebuild
211
+ sh %(tar --owner 0 --group 0 --exclude-vcs --exclude=#{@exclude_list.join(' --exclude=')} --transform='s/^#{@pkg_name}/#{@dir_name}/' -cpzf "#{@tar_dest}" #{@pkg_name})
210
212
  end
211
213
  end
212
214
  end
213
215
  end
216
+ end
214
217
 
215
- def define_pkg_rpm
216
-
217
- # :pkg:rpm
218
- # -----------------------------
219
- namespace :pkg do
220
- =begin
221
- WARNING: THIS DOES NOT PULL FROM THE simp-core RPM DEPENDENCIES FILE
222
- WARNING: YOU WILL PROBABLY NOT GET PROPER FULL SIMP RPMS FROM THIS TASK
223
-
224
- desc <<-EOM
225
- Build the #{@pkg_name} RPM.
226
-
227
- By default, the package will be built to support a SIMP-6.X file structure.
228
- To build the package for a different version of SIMP, export SIMP_BUILD_version=<5.X,4.X>
229
- EOM
230
- =end
231
- task :rpm => [:tar] do |t,args|
232
- rpm_opts = [
233
- %(-D 'buildroot #{@pkg_dir}/rpmbuild/BUILDROOT'),
234
- %(-D 'builddir #{@pkg_dir}/rpmbuild/BUILD'),
235
- %(-D '_sourcedir #{@rpm_srcdir}'),
236
- %(-D '_rpmdir #{@pkg_dir}'),
237
- %(-D '_srcrpmdir #{@pkg_dir}'),
238
- %(-D '_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm'),
239
-
240
- # needed on EL8 to disable the aggressive brp_mangle_shebangs script
241
- # that results in invalid script shebangs; does nothing in EL7
242
- %(-D '__brp_mangle_shebangs /usr/bin/true')
243
- ]
244
- rpm_opts << '-v' if @verbose
245
- rpm_opts << "-D 'lua_debug 1'" if (ENV.fetch('SIMP_RAKE_PKG_LUA_verbose','no') =='yes')
246
- rpm_opts << "-D 'pup_module_info_dir #{@base_dir}'"
247
- Dir.chdir(@pkg_dir) do
248
-
249
- # Copy in the materials required for the module builds
250
- # The following are required to build successful RPMs using
251
- # the new LUA-based RPM template
252
- puppet_module_info_files = [
253
- Dir.glob(%(#{@base_dir}/build/rpm_metadata/**)),
254
- %(#{@base_dir}/CHANGELOG),
255
- %(#{@base_dir}/metadata.json)
256
- ].flatten
257
-
258
- if @verbose
259
- puts "==== pkg:rpm: @base_dir: #{@base_dir}"
260
- puts "==== pkg:rpm: rpm_opts:\n #{rpm_opts.map{|x| "\n #{x}"}.join}"
261
- puts "==== pkg:rpm: puppet_module_info_files: #{puppet_module_info_files.map{|x| "\n #{x}"}.join}"
262
- end
218
+ def define_pkg_rpm
219
+ # :pkg:rpm
220
+ # -----------------------------
221
+ namespace :pkg do
222
+ # WARNING: THIS DOES NOT PULL FROM THE simp-core RPM DEPENDENCIES FILE
223
+ # WARNING: YOU WILL PROBABLY NOT GET PROPER FULL SIMP RPMS FROM THIS TASK
224
+ #
225
+ # desc <<-EOM
226
+ # Build the #{@pkg_name} RPM.
227
+ #
228
+ # By default, the package will be built to support a SIMP-6.X file structure.
229
+ # To build the package for a different version of SIMP, export SIMP_BUILD_version=<5.X,4.X>
230
+ # EOM
231
+ task :rpm => [:tar] do |_t, _args|
232
+ rpm_opts = [
233
+ %(-D 'buildroot #{@pkg_dir}/rpmbuild/BUILDROOT'),
234
+ %(-D 'builddir #{@pkg_dir}/rpmbuild/BUILD'),
235
+ %(-D '_sourcedir #{@rpm_srcdir}'),
236
+ %(-D '_rpmdir #{@pkg_dir}'),
237
+ %(-D '_srcrpmdir #{@pkg_dir}'),
238
+ %(-D '_build_name_fmt %%{NAME}-%%{VERSION}-%%{RELEASE}.%%{ARCH}.rpm'),
239
+
240
+ # needed on EL8 to disable the aggressive brp_mangle_shebangs script
241
+ # that results in invalid script shebangs; does nothing in EL7
242
+ %(-D '__brp_mangle_shebangs /usr/bin/true'),
243
+ ]
244
+ rpm_opts << '-v' if @verbose
245
+ rpm_opts << "-D 'lua_debug 1'" if ENV.fetch('SIMP_RAKE_PKG_LUA_verbose', 'no') == 'yes'
246
+ rpm_opts << "-D 'pup_module_info_dir #{@base_dir}'"
247
+ Dir.chdir(@pkg_dir) do
248
+ # Copy in the materials required for the module builds
249
+ # The following are required to build successful RPMs using
250
+ # the new LUA-based RPM template
251
+ puppet_module_info_files = [
252
+ Dir.glob(%(#{@base_dir}/build/rpm_metadata/**)),
253
+ %(#{@base_dir}/CHANGELOG),
254
+ %(#{@base_dir}/metadata.json),
255
+ ].flatten
256
+
257
+ if @verbose
258
+ puts "==== pkg:rpm: @base_dir: #{@base_dir}"
259
+ puts "==== pkg:rpm: rpm_opts:\n #{rpm_opts.map { |x| "\n #{x}" }.join}"
260
+ puts "==== pkg:rpm: puppet_module_info_files: #{puppet_module_info_files.map { |x| "\n #{x}" }.join}"
261
+ end
263
262
 
264
- puppet_module_info_files.each do |f|
265
- if File.exist?(f)
266
- FileUtils.cp_r(f, @rpm_srcdir, verbose: @verbose)
267
- end
263
+ puppet_module_info_files.each do |f|
264
+ if File.exist?(f)
265
+ FileUtils.cp_r(f, @rpm_srcdir, verbose: @verbose)
268
266
  end
267
+ end
269
268
 
270
- # Link in any misc artifacts that got dumped into 'dist' by other code
271
- extra_deps = Dir.glob("*")
272
- extra_deps.delete_if{|x| x =~ /(\.rpm$|(^(rpmbuild|logs|tmp$)))/}
269
+ # Link in any misc artifacts that got dumped into 'dist' by other code
270
+ extra_deps = Dir.glob('*')
271
+ extra_deps.delete_if { |x| x =~ %r{(\.rpm$|(^(rpmbuild|logs|tmp$)))} }
273
272
 
274
- Dir.chdir(@rpm_srcdir) do
275
- extra_deps.each do |dep|
276
- unless File.exist?(dep)
277
- FileUtils.cp_r("../../#{dep}", dep, verbose: @verbose)
278
- end
273
+ Dir.chdir(@rpm_srcdir) do
274
+ extra_deps.each do |dep|
275
+ unless File.exist?(dep)
276
+ FileUtils.cp_r("../../#{dep}", dep, verbose: @verbose)
279
277
  end
280
278
  end
279
+ end
281
280
 
282
- FileUtils.mkdir_p('logs', verbose: @verbose)
283
- FileUtils.mkdir_p('rpmbuild/BUILDROOT', verbose: @verbose)
284
- FileUtils.mkdir_p('rpmbuild/BUILD', verbose: @verbose)
281
+ FileUtils.mkdir_p('logs', verbose: @verbose)
282
+ FileUtils.mkdir_p('rpmbuild/BUILDROOT', verbose: @verbose)
283
+ FileUtils.mkdir_p('rpmbuild/BUILD', verbose: @verbose)
285
284
 
286
- srpms = [@full_pkg_name + '.src.rpm']
287
- if require_rebuild?(srpms.first, @tar_dest)
288
- # TODO: Uncomment this after revamping the tests to use a dependencies.yaml file
289
- # Simp::Rake::Build::RpmDeps.generate_rpm_meta_files(@base_dir, {})
285
+ srpms = ["#{@full_pkg_name}.src.rpm"]
286
+ if require_rebuild?(srpms.first, @tar_dest)
287
+ # TODO: Uncomment this after revamping the tests to use a dependencies.yaml file
288
+ # Simp::Rake::Build::RpmDeps.generate_rpm_meta_files(@base_dir, {})
290
289
 
291
- # Need to build the SRPM so that we can get the build dependencies
292
- cmd = %(rpmbuild #{rpm_opts.join(' ')} -bs #{@spec_file} > logs/build.srpm.out 2> logs/build.srpm.err)
293
- puts "==== pkg:rpm SRPM BUILD: #{cmd}" if @verbose
294
- %x(#{cmd})
290
+ # Need to build the SRPM so that we can get the build dependencies
291
+ cmd = %(rpmbuild #{rpm_opts.join(' ')} -bs #{@spec_file} > logs/build.srpm.out 2> logs/build.srpm.err)
292
+ puts "==== pkg:rpm SRPM BUILD: #{cmd}" if @verbose
293
+ `#{cmd}`
295
294
 
296
- srpms = File.read('logs/build.srpm.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten
295
+ srpms = File.read('logs/build.srpm.out').scan(%r{Wrote:\s+(.*\.rpm)}).flatten
297
296
 
298
- if srpms.empty?
299
- raise <<-EOM
297
+ if srpms.empty?
298
+ raise <<-EOM
300
299
  Could not create SRPM for '#{@spec_info.basename}
301
300
  Error: #{File.read('logs/build.srpm.err')}
302
- EOM
303
- end
301
+ EOM
302
+ end
303
+ end
304
+
305
+ # Collect the built, or downloaded, RPMs
306
+ rpms = []
307
+
308
+ @spec_info.packages
309
+ expected_rpms = @spec_info.packages.map do |f|
310
+ latest_rpm = Dir.glob("#{f}-#{@spec_info.version}*.rpm").grep_v(%r{\.src\.rpm$}).map { |x|
311
+ # Convert them to objects
312
+ Simp::RPM.new(x)
313
+ }.max_by do |x|
314
+ # Sort by the full version of the package and return the one
315
+ # with the highest version
316
+ Gem::Version.new(x.full_version)
304
317
  end
305
318
 
306
- # Collect the built, or downloaded, RPMs
307
- rpms = []
308
-
309
- @spec_info.packages
310
- expected_rpms = @spec_info.packages.map{|f|
311
- latest_rpm = Dir.glob("#{f}-#{@spec_info.version}*.rpm").select{|x|
312
- # Get all local RPMs that are not SRPMs
313
- x !~ /\.src\.rpm$/
314
- }.map{|x|
315
- # Convert them to objects
316
- x = Simp::RPM.new(x)
317
- }.sort_by{|x|
318
- # Sort by the full version of the package and return the one
319
- # with the highest version
320
- Gem::Version.new(x.full_version)
321
- }.last
322
-
323
- if latest_rpm && (
324
- Gem::Version.new(latest_rpm.full_version) >=
325
- Gem::Version.new(@spec_info.full_version)
319
+ if latest_rpm && (
320
+ Gem::Version.new(latest_rpm.full_version) >=
321
+ Gem::Version.new(@spec_info.full_version)
326
322
  )
327
- f = latest_rpm.rpm_name
328
- else
329
- f = "#{f}-#{@spec_info.full_version}-#{@spec_info.arch}.rpm"
330
- end
331
- }
323
+ latest_rpm.rpm_name
324
+ else
325
+ "#{f}-#{@spec_info.full_version}-#{@spec_info.arch}.rpm"
326
+ end
327
+ end
332
328
 
333
- if expected_rpms.empty? || require_rebuild?(expected_rpms, srpms)
329
+ if expected_rpms.empty? || require_rebuild?(expected_rpms, srpms)
334
330
 
335
- expected_rpms_data = expected_rpms.map{ |f|
336
- if File.exist?(f)
337
- f = Simp::RPM.new(f)
338
- else
339
- f = nil
340
- end
341
- }
331
+ expected_rpms_data = expected_rpms.map do |f|
332
+ if File.exist?(f)
333
+ Simp::RPM.new(f)
334
+ else
335
+ nil
336
+ end
337
+ end
342
338
 
343
- require_rebuild = true
339
+ require_rebuild = true
344
340
 
345
- # We need to rebuild if not *all* of the expected RPMs are present
346
- unless expected_rpms_data.include?(nil)
347
- # If all of the RPMs are signed, we do not need a rebuild
348
- require_rebuild = !expected_rpms_data.compact.select{|x| !x.signature}.empty?
349
- end
341
+ # We need to rebuild if not *all* of the expected RPMs are present
342
+ unless expected_rpms_data.include?(nil)
343
+ # If all of the RPMs are signed, we do not need a rebuild
344
+ require_rebuild = !expected_rpms_data.compact.reject { |x| x.signature }.empty?
345
+ end
350
346
 
351
- if !require_rebuild
352
- # We found all expected RPMs and they all had valid signatures
353
- #
354
- # Record the existing RPM metadata in the output file
355
- rpms = expected_rpms
356
- else
357
- # Try a build
358
- cmd = %(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)
359
- puts "==== pkg:rpm: #{cmd}" if @verbose
360
- _result = %x(#{cmd})
361
- puts _result if @verbose
362
-
363
- # If the build failed, it was probably due to missing dependencies
364
- unless $?.success?
365
- # Find the RPM build dependencies
366
- rpm_build_deps = %x(rpm -q -R -p #{srpms.first}).strip.split("\n")
367
-
368
- # RPM stuffs this in every time
369
- rpm_build_deps.delete_if {|x| x =~ /^rpmlib/}
370
-
371
- # See if we have the ability to install things
372
- unless Process.uid == 0
373
- unless %x(sudo -ln) =~ %r(NOPASSWD:\s+(ALL|yum( install)?))
374
- raise <<-EOM
347
+ if require_rebuild
348
+ # Try a build
349
+ cmd = %(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)
350
+ puts "==== pkg:rpm: #{cmd}" if @verbose
351
+ _result = `#{cmd}`
352
+ puts _result if @verbose
353
+
354
+ # If the build failed, it was probably due to missing dependencies
355
+ unless $CHILD_STATUS.success?
356
+ # Find the RPM build dependencies
357
+ rpm_build_deps = `rpm -q -R -p #{srpms.first}`.strip.split("\n")
358
+
359
+ # RPM stuffs this in every time
360
+ rpm_build_deps.delete_if { |x| x =~ %r{^rpmlib} }
361
+
362
+ # See if we have the ability to install things
363
+ if Process.uid != 0 && `sudo -ln` !~ %r{NOPASSWD:\s+(ALL|yum( install)?)}
364
+ raise <<-EOM
375
365
  Please install the following dependencies and try again:
376
- #{rpm_build_deps.map{|x| x = " * #{x}"}.join("\n")}
377
- EOM
378
- end
379
- end
380
-
381
- rpm_build_deps.map! do |rpm|
382
- if rpm =~ %r((.*)\s+(?:<=|=|==)\s+(.+))
383
- rpm = "#{$1}-#{$2}"
384
- end
366
+ #{rpm_build_deps.map { |x| " * #{x}" }.join("\n")}
367
+ EOM
368
+ end
385
369
 
386
- rpm.strip
370
+ rpm_build_deps.map! do |rpm|
371
+ if rpm =~ %r{(.*)\s+(?:<=|=|==)\s+(.+)}
372
+ rpm = "#{::Regexp.last_match(1)}-#{::Regexp.last_match(2)}"
387
373
  end
388
374
 
389
- yum_install_cmd = %(yum -y install '#{rpm_build_deps.join("' '")}')
390
- unless Process.uid == 0
391
- yum_install_cmd = 'sudo ' + yum_install_cmd
392
- end
393
- puts "==== pkg:rpm: #{yum_install_cmd}" if @verbose
375
+ rpm.strip
376
+ end
377
+
378
+ yum_install_cmd = %(yum -y install '#{rpm_build_deps.join("' '")}')
379
+ unless Process.uid.zero?
380
+ yum_install_cmd = "sudo #{yum_install_cmd}"
381
+ end
382
+ puts "==== pkg:rpm: #{yum_install_cmd}" if @verbose
394
383
 
395
- install_output = %x(#{yum_install_cmd} 2>&1)
384
+ install_output = `#{yum_install_cmd} 2>&1`
396
385
 
397
- if !$?.success? || (install_output =~ %r((N|n)o package))
398
- raise <<-EOM
386
+ if !$CHILD_STATUS.success? || (install_output =~ %r{(N|n)o package})
387
+ raise <<-EOM
399
388
  Could not run #{yum_install_cmd}
400
389
  Error: #{install_output}
401
- EOM
402
- end
390
+ EOM
403
391
  end
392
+ end
404
393
 
405
- # Try it again!
406
- #
407
- # If this doesn't work, something we can't fix automatically is wrong
408
- cmd = %(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)
409
- puts "==== pkg:rpm: #{cmd}" if @verbose
410
- %x(#{cmd})
394
+ # Try it again!
395
+ #
396
+ # If this doesn't work, something we can't fix automatically is wrong
397
+ cmd = %(rpmbuild #{rpm_opts.join(' ')} --rebuild #{srpms.first} > logs/build.rpm.out 2> logs/build.rpm.err)
398
+ puts "==== pkg:rpm: #{cmd}" if @verbose
399
+ `#{cmd}`
411
400
 
412
- rpms = File.read('logs/build.rpm.out').scan(%r(Wrote:\s+(.*\.rpm))).flatten - srpms
401
+ rpms = File.read('logs/build.rpm.out').scan(%r{Wrote:\s+(.*\.rpm)}).flatten - srpms
413
402
 
414
- if rpms.empty?
415
- raise <<-EOM
403
+ if rpms.empty?
404
+ raise <<-EOM
416
405
  Could not create RPM for '#{@spec_info.basename}
417
406
  Error: #{File.read('logs/build.rpm.err')}
418
- EOM
419
- end
407
+ EOM
420
408
  end
409
+ else
410
+ # We found all expected RPMs and they all had valid signatures
411
+ #
412
+ # Record the existing RPM metadata in the output file
413
+ rpms = expected_rpms
414
+ end
421
415
 
422
- # Prevent overwriting the last good metadata file
423
- raise %(Could not find any valid RPMs for '#{@spec_info.basename}') if rpms.empty?
416
+ # Prevent overwriting the last good metadata file
417
+ raise %(Could not find any valid RPMs for '#{@spec_info.basename}') if rpms.empty?
424
418
 
425
- Simp::RPM.create_rpm_build_metadata(File.expand_path(@base_dir), srpms, rpms)
426
- end
419
+ Simp::RPM.create_rpm_build_metadata(File.expand_path(@base_dir), srpms, rpms)
427
420
  end
428
421
  end
429
422
  end
430
423
  end
424
+ end
431
425
 
432
- def define_pkg_check_rpm_changelog
433
- # :pkg:check_rpm_changelog
434
- # -----------------------------
435
- namespace :pkg do
436
- desc <<-EOM
426
+ def define_pkg_check_rpm_changelog
427
+ # :pkg:check_rpm_changelog
428
+ # -----------------------------
429
+ namespace :pkg do
430
+ desc <<-EOM
437
431
  Check the #{@pkg_name} RPM changelog using the 'rpm' command.
438
432
 
439
433
  This task will fail if 'rpm' detects any changelog problems,
440
434
  such as changelog entries not being in reverse chronological
441
435
  order.
442
- EOM
443
- task :check_rpm_changelog, [:verbose] do |t,args|
444
- if args[:verbose].to_s == 'true'
445
- verbose = true
446
- else
447
- verbose = false
448
- end
449
- Simp::RelChecks::check_rpm_changelog(@base_dir, @spec_file, verbose)
450
- end
436
+ EOM
437
+ task :check_rpm_changelog, [:verbose] do |_t, args|
438
+ verbose = args[:verbose].to_s == 'true'
439
+ Simp::RelChecks.check_rpm_changelog(@base_dir, @spec_file, verbose)
451
440
  end
452
441
  end
442
+ end
453
443
 
454
- def define_pkg_check_version
455
- namespace :pkg do
456
- # :pkg:check_version
457
- # -----------------------------
458
- desc <<-EOM
444
+ def define_pkg_check_version
445
+ namespace :pkg do
446
+ # :pkg:check_version
447
+ # -----------------------------
448
+ desc <<-EOM
459
449
  Ensure that #{@pkg_name} has a properly updated version number.
460
- EOM
461
- task :check_version do |t,args|
462
- require 'json'
463
-
464
- # Get the current version
465
- if File.exist?('metadata.json')
466
- mod_version = JSON.load(File.read('metadata.json'))['version'].strip
467
- success_msg = "#{@pkg_name}: Version #{mod_version} up to date"
468
-
469
- # If we have no tags, we need a new version
470
- if %x(git tag).strip.empty?
471
- puts "#{@pkg_name}: New Version Required"
472
- else
473
- # See if the module is newer than all tags
474
- matching_tag = %x(git tag --points-at HEAD).strip.split("\n").first
450
+ EOM
451
+ task :check_version do |_t, _args|
452
+ require 'json'
475
453
 
476
- if matching_tag.nil? || matching_tag.empty?
477
- # We don't have a matching release
478
- # Get the closest tag
479
- nearest_tag = %x(git describe --abbrev=0 --tags).strip
454
+ # Get the current version
455
+ if File.exist?('metadata.json')
456
+ mod_version = JSON.parse(File.read('metadata.json'))['version'].strip
457
+ success_msg = "#{@pkg_name}: Version #{mod_version} up to date"
480
458
 
481
- if mod_version == nearest_tag
482
- puts "#{@pkg_name}: Error: metadata.json needs to be updated past #{mod_version}"
483
- else
484
- # Check the CHANGELOG Version
485
- if File.exist?('CHANGELOG')
486
- changelog = File.read('CHANGELOG')
487
- changelog_version = nil
488
-
489
- # Find the first date line
490
- changelog.each_line do |line|
491
- if line =~ /\*.*(\d+\.\d+\.\d+)(-\d+)?\s*$/
492
- changelog_version = $1
493
- break
494
- end
495
- end
496
-
497
- if changelog_version
498
- if changelog_version == mod_version
499
- puts success_msg
500
- else
501
- puts "#{@pkg_name}: Error: CHANGELOG version #{changelog_version} out of date for version #{mod_version}"
502
- end
503
- else
504
- puts "#{@pkg_name}: Error: No CHANGELOG version found"
505
- end
506
- else
507
- puts "#{@pkg_name}: Warning: No CHANGELOG found"
459
+ # If we have no tags, we need a new version
460
+ if `git tag`.strip.empty?
461
+ puts "#{@pkg_name}: New Version Required"
462
+ else
463
+ # See if the module is newer than all tags
464
+ matching_tag = `git tag --points-at HEAD`.strip.split("\n").first
465
+
466
+ if matching_tag.nil? || matching_tag.empty?
467
+ # We don't have a matching release
468
+ # Get the closest tag
469
+ nearest_tag = `git describe --abbrev=0 --tags`.strip
470
+
471
+ if mod_version == nearest_tag
472
+ puts "#{@pkg_name}: Error: metadata.json needs to be updated past #{mod_version}"
473
+ elsif File.exist?('CHANGELOG')
474
+ # Check the CHANGELOG Version
475
+ changelog = File.read('CHANGELOG')
476
+ changelog_version = nil
477
+
478
+ # Find the first date line
479
+ changelog.each_line do |line|
480
+ if line =~ %r{\*.*(\d+\.\d+\.\d+)(-\d+)?\s*$}
481
+ changelog_version = ::Regexp.last_match(1)
482
+ break
508
483
  end
509
484
  end
510
- else
511
- if mod_version != matching_tag
512
- puts "#{@pkg_name}: Error: Tag #{matching_tag} does not match version #{mod_version}"
485
+
486
+ if changelog_version
487
+ if changelog_version == mod_version
488
+ puts success_msg
489
+ else
490
+ puts "#{@pkg_name}: Error: CHANGELOG version #{changelog_version} out of date for version #{mod_version}"
491
+ end
513
492
  else
514
- puts success_msg
493
+ puts "#{@pkg_name}: Error: No CHANGELOG version found"
515
494
  end
495
+ else
496
+ puts "#{@pkg_name}: Warning: No CHANGELOG found"
516
497
  end
498
+ elsif mod_version != matching_tag
499
+ puts "#{@pkg_name}: Error: Tag #{matching_tag} does not match version #{mod_version}"
500
+ else
501
+ puts success_msg
517
502
  end
518
- else
519
- puts "#{@pkg_name}: No metadata.json found"
520
503
  end
504
+ else
505
+ puts "#{@pkg_name}: No metadata.json found"
521
506
  end
522
507
  end
523
508
  end
509
+ end
524
510
 
525
- def define_pkg_compare_latest_tag
526
- namespace :pkg do
527
- desc <<-EOM
511
+ def define_pkg_compare_latest_tag
512
+ namespace :pkg do
513
+ desc <<-EOM
528
514
  Compare to latest tag.
529
515
  ARGS:
530
516
  * :tags_source => Set to the remote from which the tags for this
@@ -552,24 +538,20 @@ module Simp::Rake
552
538
  - rakelib directory
553
539
  - spec directory
554
540
  - doc directory
555
- EOM
556
- task :compare_latest_tag, [:tags_source, :verbose] do |t,args|
557
- tags_source = args[:tags_source].nil? ? 'origin' : args[:tags_source]
558
- if args[:verbose].to_s == 'true'
559
- verbose = true
560
- else
561
- verbose = false
562
- end
563
- Simp::RelChecks::compare_latest_tag(@base_dir, tags_source, verbose)
564
- end
541
+ EOM
542
+ task :compare_latest_tag, [:tags_source, :verbose] do |_t, args|
543
+ tags_source = args[:tags_source].nil? ? 'origin' : args[:tags_source]
544
+ verbose = args[:verbose].to_s == 'true'
545
+ Simp::RelChecks.compare_latest_tag(@base_dir, tags_source, verbose)
565
546
  end
566
547
  end
548
+ end
567
549
 
568
- def define_pkg_create_tag_changelog
569
- namespace :pkg do
570
- # :pkg:create_tag_changelog
571
- # -----------------------------
572
- desc <<-EOM
550
+ def define_pkg_create_tag_changelog
551
+ namespace :pkg do
552
+ # :pkg:create_tag_changelog
553
+ # -----------------------------
554
+ desc <<-EOM
573
555
  Generate an appropriate changelog for an annotated tag from a
574
556
  component's CHANGELOG or RPM spec file.
575
557
 
@@ -623,32 +605,27 @@ module Simp::Rake
623
605
  - The weekday for a changelog entry for the latest version
624
606
  does not match the date specified.
625
607
 
626
- EOM
627
- task :create_tag_changelog, [:verbose] => [:check_rpm_changelog] do |t,args|
628
- if args[:verbose].to_s == 'true'
629
- verbose = true
630
- else
631
- verbose = false
632
- end
633
- puts Simp::RelChecks::create_tag_changelog(@base_dir, verbose)
634
- end
608
+ EOM
609
+ task :create_tag_changelog, [:verbose] => [:check_rpm_changelog] do |_t, args|
610
+ verbose = args[:verbose].to_s == 'true'
611
+ puts Simp::RelChecks.create_tag_changelog(@base_dir, verbose)
635
612
  end
636
613
  end
614
+ end
637
615
 
638
- # ------------------------------------------------------------------------------
639
- # helper methods
640
- # ------------------------------------------------------------------------------
641
- # Return True if any of the 'old' Array are newer than the 'new' Array
642
- def require_rebuild?(new, old)
643
- return true if ( Array(old).empty? || Array(new).empty?)
644
-
645
- Array(new).each do |new_file|
646
- return true unless File.exist?(new_file)
616
+ # ------------------------------------------------------------------------------
617
+ # helper methods
618
+ # ------------------------------------------------------------------------------
619
+ # Return True if any of the 'old' Array are newer than the 'new' Array
620
+ def require_rebuild?(new, old)
621
+ return true if Array(old).empty? || Array(new).empty?
647
622
 
648
- return true unless uptodate?(new_file, Array(old))
649
- end
623
+ Array(new).each do |new_file|
624
+ return true unless File.exist?(new_file)
650
625
 
651
- return false
626
+ return true unless uptodate?(new_file, Array(old))
652
627
  end
628
+
629
+ false
653
630
  end
654
631
  end