simp-rake-helpers 4.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2c6299dfaa0a3e75d37916459a30caf994a7622a
4
- data.tar.gz: 2a6f65497e333ea57ca66b0260807159f80844d1
3
+ metadata.gz: 6113186e329690af05d0b8ab80c1f9bcd49dce2d
4
+ data.tar.gz: 5058893b87cabbc46c2644d82a70d1f2f1aecd8c
5
5
  SHA512:
6
- metadata.gz: 4ecb3781be056aa6a557e7189bb7bf2ad6b1cfd87c1cc9b8ad84d7f087d58918df569b7e3a6c5829d7b2970ef4712dc5eeb9d477ba5ef8143b8e6ce6b16495b0
7
- data.tar.gz: c1dff90c15ea782be41a06a927549332092a2f4a49ad220d7bec2d3fd2e462eb60dd78db073f94c54fbf1c376589a2f6b56f7ff0f9b726095cb2ed1b52694590
6
+ metadata.gz: ef33179fc629100aab0347fba56ade32c1546c9b5b259daaaf726cd061b8fd9fab14dfc06f7584c7a4f1d5e53359a6ba1873805b5829040d0ee8c6d4701ea978
7
+ data.tar.gz: a697cc85f44d2150ec67e47b13971cd2d06440c9e3a1b911446f9077a3b8707f66ec5989cf4448aa1910ac2712b2f06bfeceefc2f104f8dfca005870de394ae2
data/.travis.yml CHANGED
@@ -5,8 +5,6 @@ before_install:
5
5
  - sudo apt-get update -qq
6
6
  - sudo apt-get install -y rpm
7
7
  - rm Gemfile.lock || true
8
- - rvm @global do gem uninstall bundler -a -x
9
- - rvm @global do gem install bundler -v '~> 1.14.0'
10
8
  bundler_args: "--without development --path .vendor"
11
9
  notifications:
12
10
  email: false
@@ -26,12 +24,19 @@ before_deploy:
26
24
  - "export GEM_VERSION=`ruby -r ./lib/simp/rake/helpers/version.rb -e 'puts Simp::Rake::Helpers::VERSION'`"
27
25
  - '[[ $TRAVIS_TAG =~ ^${GEM_VERSION}$ ]]'
28
26
  deploy:
29
- provider: rubygems
30
- gemspec: simp-rake-helpers.gemspec
31
- gem: simp-rake-helpers
32
- on:
33
- tags: true
34
- rvm: 2.1.9
35
- condition: '($SKIP_PUBLISH != true)'
36
- api_key:
37
- secure: aoPmOZ3WgjNJ56UXmamKxaRv37iUaxKekAeS8n2fPk78X/nU2qGjdDHFH+SBrfl33PyzsGnS3WAANMKaIkAgssvKoaII/sAC+Sl6q1eyVUprZqloXrG+cHlnHY4GnziWEH3JrkHDChW0xoJq7hhpj7qTRKrEIp6nA25MjozjveoL+HH4kKy/ACJhiEdsYTFaDLYYFY50gGUL9KjIkwN6g9d+dIzG9JqcYoDbneQlO6/23yr4GiAHQ8HM1j5tUoBqJad+CWjWhSY7pbfYBy2ziwVhFy1qoOS4/bhlasRCsLTtz0AjjR0YWOhJap1vJqYhrSxtvhmVuzScmDkueAem/PfWS3XCQvbmjdmFMzPOxo0aRRJMlaeVWRsZ/aVFC7ngpRzokq1duZEKI47xZC27vJSOp3RZMmYl/7GsykoYkqHHsTvzSALEQiVtQq8sIOtN0JOTFI8H4LSMirXuqGq+SgCJiAQ3mQzSgh50TXiZaA2UPPcQaw4AzY36BRKs1cgw3cEWuL38O2cWUTAzEE4SUh499wrU5x+N0PsYL0AvMFONsRaq5epOYrlIL9UPSL/qZRLmzpcEWZRfOX4Ni5N6Aa9ZR8juenR6UmE79S2dupBxQeinkdfXuWznUZH7BcnUDoz8rErABpJGHNVY60dUO/s055WCr7Y95Gi+H75X9/I=
27
+ - provider: rubygems
28
+ gemspec: simp-rake-helpers.gemspec
29
+ gem: simp-rake-helpers
30
+ api_key:
31
+ secure: "aoPmOZ3WgjNJ56UXmamKxaRv37iUaxKekAeS8n2fPk78X/nU2qGjdDHFH+SBrfl33PyzsGnS3WAANMKaIkAgssvKoaII/sAC+Sl6q1eyVUprZqloXrG+cHlnHY4GnziWEH3JrkHDChW0xoJq7hhpj7qTRKrEIp6nA25MjozjveoL+HH4kKy/ACJhiEdsYTFaDLYYFY50gGUL9KjIkwN6g9d+dIzG9JqcYoDbneQlO6/23yr4GiAHQ8HM1j5tUoBqJad+CWjWhSY7pbfYBy2ziwVhFy1qoOS4/bhlasRCsLTtz0AjjR0YWOhJap1vJqYhrSxtvhmVuzScmDkueAem/PfWS3XCQvbmjdmFMzPOxo0aRRJMlaeVWRsZ/aVFC7ngpRzokq1duZEKI47xZC27vJSOp3RZMmYl/7GsykoYkqHHsTvzSALEQiVtQq8sIOtN0JOTFI8H4LSMirXuqGq+SgCJiAQ3mQzSgh50TXiZaA2UPPcQaw4AzY36BRKs1cgw3cEWuL38O2cWUTAzEE4SUh499wrU5x+N0PsYL0AvMFONsRaq5epOYrlIL9UPSL/qZRLmzpcEWZRfOX4Ni5N6Aa9ZR8juenR6UmE79S2dupBxQeinkdfXuWznUZH7BcnUDoz8rErABpJGHNVY60dUO/s055WCr7Y95Gi+H75X9/I="
32
+ on:
33
+ tags: true
34
+ rvm: 2.1.9
35
+ condition: '($SKIP_PUBLISH != true)'
36
+ - provider: releases
37
+ api_key:
38
+ secure: "QKvAL4yAk8u9prJT6dFzKvszJfoo5/R9jIJ/WEUwdH17jij9Q/XhNrUzJZnrdVtqq4yCK6UqGqkRMMn2YLOKthoJycLEXzH+ZeCxBwzyN6uQkLmK5Mx43H+NNCsRkYTmcOdi4wJraWaWVq7XBxz6XdNRUkV99WyIh93wVnTwZuJxvF9koDFq+lRR4qRPh5Xn8HjKEZNPY7QHaecqsyWjgdEILWaQk/32IU20dLCT7U3jDdSuk92p24gWlkvTJ/gP+IYKWEPhgMMpx+WAtGGC+djMyZUrkaKEa/ennkOcFgqJ6UtDEInEtTBFWScGL70dwHORbEVExp9AKcLP3TmMyQ/36ybu7yrgcp6L995tM4Huez3GBM6NJ8xl/hYG3D1QwwoXGnWfUjQW2we7h8gcvl2yUSx59pb2V5QW3nCbD8rAiF/kpAcgwWyBT3iLpMer2j0Ux05NCBGqsltl9J944M+pLtO+YKldUw7uGDWMQQzq8/2m5+MoE4fvTgnaJ0rv0eRLWfNH2RQ565mE95nyJC/wXz/XB2v/KKHrf8FQZRIavH4Nuo4E2+tU8u2APU/n+gP8iQrtd86Nlo5RrBTu+NoDPDrM5OBnVYTT/AUAEUggXTPgZsqwZrSDSBEt0VbExnwQ5QMGIB9ZX+ZunrEZ6NeH8hV5hm67WYZ+qRFOPvI="
39
+ on:
40
+ tags: true
41
+ rvm: 2.1.9
42
+ condition: '($SKIP_PUBLISH != true)'
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 4.1.0 / 2017-08-02
2
+ * Added the ability to read from `simp-core/build/rpm/dependencies.yaml` in a
3
+ checked out repo to add the necessary Obsoletes and Requires statements for
4
+ external RPMs
5
+ * Changed the 'YEAR' part of the RPM release to reflect the current year
6
+ * Ensure that the 'spec/fixtures/modules' directory is no longer added to the
7
+ RPMs
8
+
1
9
  ### 4.0.1 / 2017-08-02
2
10
  * Reverted the bundler pinning since it was causing too many issues on CI
3
11
  systems
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'simp/rake/pkg'
4
4
  require 'simp/rake/build/constants'
5
+ require 'simp/rake/build/rpmdeps'
5
6
 
6
7
  module Simp; end
7
8
  module Simp::Rake; end
@@ -740,8 +741,12 @@ protect=1
740
741
  validate_in_mock_group?
741
742
  _verbose = ENV.fetch('SIMP_PKG_verbose','no') == 'yes'
742
743
 
743
- # Default package metadata for reference
744
- default_metadata = YAML.load(File.read("#{@src_dir}/build/package_metadata_defaults.yaml"))
744
+ rpm_dependency_file = File.join(@base_dir, 'build', 'rpm',
745
+ 'dependencies.yaml')
746
+
747
+ if File.exist?(rpm_dependency_file)
748
+ rpm_dependency_metadata = YAML.load(File.read(rpm_dependency_file))
749
+ end
745
750
 
746
751
  metadata = Parallel.map(
747
752
  # Allow for shell globs
@@ -763,6 +768,12 @@ protect=1
763
768
 
764
769
  # We're building a module, override anything down there
765
770
  if File.exist?('metadata.json')
771
+
772
+ # Generate RPM dependency/obsoletes information from the
773
+ # dependencies.yaml and the module's metadata.json
774
+ Simp::Rake::Build::RpmDeps::generate_rpm_requires_file(dir,
775
+ rpm_dependency_metadata)
776
+
766
777
  unique_namespace = (0...24).map{ (65 + rand(26)).chr }.join.downcase
767
778
 
768
779
  Simp::Rake::Pkg.new(Dir.pwd, nil, unique_namespace, @simp_version)
@@ -0,0 +1,162 @@
1
+ class SIMPRpmDepException < StandardError; end
2
+ class SIMPRpmDepVersionException < StandardError; end
3
+
4
+ module Simp; end
5
+ module Simp::Rake; end
6
+ module Simp::Rake::Build; end
7
+ module Simp::Rake::Build::RpmDeps
8
+
9
+ # returns array of RPM spec file 'Requires' lines derived
10
+ # from a metadata.json dependency version specification.
11
+ def self.get_version_requires(pkg, dep_version)
12
+ requires = []
13
+ if dep_version =~ /^\s*(\d+\.\d+\.\d+)\s*$/
14
+ requires << "Requires: #{pkg} = #{$1}"
15
+ else
16
+ if dep_version.include?('x')
17
+ dep_parts = dep_version.split('.')
18
+
19
+ if dep_parts.count == 3
20
+ dep_version = ">= #{dep_parts[0]}.#{dep_parts[1]}.0 < #{dep_parts[0].to_i + 1}.0.0"
21
+ else
22
+ dep_version = ">= #{dep_parts[0]}.0.0 < #{dep_parts[0].to_i + 1}.0.0"
23
+ end
24
+ end
25
+
26
+ # metadata.json is a LOT more forgiving than the RPM spec file
27
+ if dep_version =~ /^\s*(?:(?:([<>]=?)\s*(\d+\.\d+\.\d+))\s*(?:(<)\s*(\d+\.\d+\.\d+))?)\s*$/
28
+ requires << "Requires: #{pkg} #{$1} #{$2}"
29
+ requires << "Requires: #{pkg} #{$3} #{$4}" if $3
30
+ else
31
+ raise SIMPRpmDepVersionException.new
32
+ end
33
+ end
34
+ requires
35
+ end
36
+
37
+ # Generate 'Obsoletes' and 'Requires' lines, from a combination of
38
+ # the module_dep_info and module_metadata. Only dependencies listed
39
+ # in the module_dep_info hash will be included in the output. The
40
+ # version requirements for each dependency will be pulled from
41
+ # module_metadata.
42
+ #
43
+ # returns array of strings, each of which is an 'Obsoletes' or
44
+ # 'Requires' line for use in an RPM spec file
45
+ def self.generate_custom_rpm_requires(module_dep_info, module_metadata)
46
+ rpm_metadata_content = []
47
+
48
+ if module_dep_info[:obsoletes]
49
+ module_dep_info[:obsoletes].each_pair do |pkg, version|
50
+ module_version = module_metadata['version']
51
+
52
+ # We don't want to add this if we're building an older
53
+ # version or the RPM will be malformed
54
+ if Gem::Version.new(module_version) >
55
+ Gem::Version.new(version.split('-').first)
56
+
57
+ rpm_metadata_content << "Obsoletes: #{pkg} > #{version}"
58
+ else
59
+ puts "Ignoring 'obsoletes' for #{pkg}: module version" +
60
+ " #{module_version} from metadata.json is not >" +
61
+ " obsolete version #{version}"
62
+ end
63
+ end
64
+ end
65
+
66
+ module_dep_info[:requires].each do |pkg|
67
+ pkg_parts = pkg.split(%r(-|/))[-2..-1]
68
+
69
+ # Need to cover all base cases
70
+ short_names = [pkg_parts.join('/'), pkg_parts.join('-')]
71
+
72
+ dep_info = module_metadata['dependencies'].select{ |dep|
73
+ short_names.include?(dep['name'])
74
+ }
75
+
76
+ if dep_info.empty?
77
+ err_msg = "Could not find #{short_names.first} dependency"
78
+ raise SIMPRpmDepException.new(err_msg)
79
+ else
80
+ dep_version = dep_info.first['version_requirement']
81
+ end
82
+
83
+ begin
84
+ rpm_metadata_content << get_version_requires(pkg, dep_version)
85
+ rescue SIMPRpmDepVersionException => e
86
+ err_msg = "Unable to parse #{short_names.first} dependency" +
87
+ " version '#{dep_version}'"
88
+ raise SIMPRpmDepException.new(err_msg)
89
+ end
90
+ end
91
+ rpm_metadata_content.flatten
92
+ end
93
+
94
+ # Generate 'Requires' lines from each dependency specified in the
95
+ # module_metadata hash
96
+ #
97
+ # returns array of strings, each of which is a 'Requires' line for
98
+ # use in an RPM spec file
99
+ def self.generate_module_rpm_requires(module_metadata)
100
+ rpm_metadata_content = []
101
+ module_metadata['dependencies'].each do |dep|
102
+ pkg = "pupmod-#{dep['name'].gsub('/', '-')}"
103
+ dep_version = dep['version_requirement']
104
+
105
+ begin
106
+ rpm_metadata_content << get_version_requires(pkg, dep_version)
107
+ rescue SIMPRpmDepVersionException => e
108
+ err_msg = "Unable to parse #{dep['name']} dependency" +
109
+ " version '#{dep_version}'"
110
+ raise SIMPRpmDepException.new(err_msg)
111
+ end
112
+ end
113
+
114
+ rpm_metadata_content.flatten
115
+ end
116
+
117
+ # Generate 'build/rpm_metadata/requires' file containing
118
+ # 'Obsoletes' and/or 'Requires' lines for use in an RPM spec file
119
+ # from a combination of the 'metadata.json' file in dir and
120
+ # the rpm_dependency_metadata
121
+ # hash.
122
+ #
123
+ # If the rpm_dependency_metadata hash as an entry for the
124
+ # module named in the 'metadata.json' file, the generated
125
+ # 'requires' file will contain
126
+ # * 'Obsoletes' lines for any obsoletes specified in the
127
+ # rpm_dependency_metadata hash
128
+ # * 'Requires' lines for any requires specified in the
129
+ # rpm_dependency_metadata hash, where the versions for those
130
+ # dependencies are pulled from the 'metadata.json' file.
131
+ #
132
+ # Otherwise, the generated 'requires' file will contain
133
+ # "Requires" lines for each dependency specified in the
134
+ # 'metadata.json' file.
135
+ def self.generate_rpm_requires_file(dir, rpm_dependency_metadata)
136
+ require 'json'
137
+
138
+ metadata_json_file = File.join(dir, 'metadata.json')
139
+ module_metadata = JSON.parse(File.read(metadata_json_file))
140
+ module_name = module_metadata['name'].split(%r(-|/)).last
141
+
142
+ module_dep_info = rpm_dependency_metadata[module_name]
143
+ rpm_metadata_content = []
144
+ begin
145
+ if module_dep_info
146
+ rpm_metadata_content = generate_custom_rpm_requires(module_dep_info, module_metadata)
147
+ else
148
+ rpm_metadata_content = generate_module_rpm_requires(module_metadata)
149
+ end
150
+ rescue SIMPRpmDepException => e
151
+ fail "#{e.message} in #{metadata_json_file}"
152
+ end
153
+
154
+ rpm_metadata_file = File.join(dir, 'build', 'rpm_metadata', 'requires')
155
+
156
+ FileUtils.mkdir_p(File.dirname(rpm_metadata_file))
157
+ File.open(rpm_metadata_file, 'w') do |fh|
158
+ fh.puts(rpm_metadata_content.flatten.join("\n"))
159
+ fh.flush
160
+ end
161
+ end
162
+ end
@@ -53,7 +53,7 @@ module Simp::Rake
53
53
  require 'yaml'
54
54
  pwd = File.expand_path(@base_dir)
55
55
  _f = YAML.load_file(File.join(pwd,'.fixtures.yml'))
56
-
56
+
57
57
  unless File.file?(File.join(pwd,'.fixtures.yml.local'))
58
58
  fail "ERROR: Can't diff fixtures without a `.fixtures.yml.local` file"
59
59
  end
@@ -41,11 +41,10 @@ package_version = "UNKNOWN"
41
41
  module_license = "UNKNOWN"
42
42
 
43
43
  --
44
- -- Default to 2016
45
- -- This was done due to the change in naming scheme across all of the modules.
44
+ -- Default to 0
46
45
  --
47
46
 
48
- package_release = '2016'
47
+ package_release = 0
49
48
 
50
49
  }
51
50
 
@@ -338,12 +337,14 @@ curdir=`pwd`
338
337
  dirname=`basename $curdir`
339
338
  cp -r ../$dirname %{buildroot}/%{prefix}/%{module_name}
340
339
  cd %{buildroot}%{prefix}/%{module_name}
340
+
341
+ # Remove unnecessary assets
341
342
  rm -rf %{buildroot}/%{prefix}/%{module_name}/.git
342
- rm -f %{buildroot}/%{prefix}/*.lock
343
- rm -rf %{buildroot}/%{prefix}/spec/fixtures/modules
344
- rm -rf %{buildroot}/%{prefix}/dist
345
- rm -rf %{buildroot}/%{prefix}/junit
346
- rm -rf %{buildroot}/%{prefix}/log
343
+ rm -f %{buildroot}/%{prefix}/%{module_name}/*.lock
344
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/spec/fixtures/modules
345
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/dist
346
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/junit
347
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/log
347
348
 
348
349
  %clean
349
350
  [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
@@ -41,11 +41,10 @@ package_version = "UNKNOWN"
41
41
  module_license = "UNKNOWN"
42
42
 
43
43
  --
44
- -- Default to 2016
45
- -- This was done due to the change in naming scheme across all of the modules.
44
+ -- Default to 0
46
45
  --
47
46
 
48
- package_release = '2016'
47
+ package_release = 0
49
48
 
50
49
  }
51
50
 
@@ -338,12 +337,14 @@ curdir=`pwd`
338
337
  dirname=`basename $curdir`
339
338
  cp -r ../$dirname %{buildroot}/%{prefix}/%{module_name}
340
339
  cd %{buildroot}%{prefix}/%{module_name}
340
+
341
+ # Remove unnecessary assets
341
342
  rm -rf %{buildroot}/%{prefix}/%{module_name}/.git
342
- rm -f %{buildroot}/%{prefix}/*.lock
343
- rm -rf %{buildroot}/%{prefix}/spec/fixtures/modules
344
- rm -rf %{buildroot}/%{prefix}/dist
345
- rm -rf %{buildroot}/%{prefix}/junit
346
- rm -rf %{buildroot}/%{prefix}/log
343
+ rm -f %{buildroot}/%{prefix}/%{module_name}/*.lock
344
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/spec/fixtures/modules
345
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/dist
346
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/junit
347
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/log
347
348
 
348
349
  %clean
349
350
  [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
@@ -0,0 +1,357 @@
1
+ %{lua:
2
+
3
+ --
4
+ -- When you build you must to pass this along so that we know how
5
+ -- to get the preliminary information.
6
+ -- This directory should hold the following items:
7
+ -- * 'build/rpm_metadata/requires' <- optional list of 'Requires', 'Provides',
8
+ -- and 'Obsoletes' to supplement those auto-generated in this spec file
9
+ -- * 'build/rpm_metadata/release' <- optional RPM release number to use in
10
+ -- lieu of number hard-coded in this spec file
11
+ -- * 'CHANGELOG' <- optional RPM formatted Changelog to use in lieu of minimal,
12
+ -- changelog entry auto-generated in this spec file
13
+ -- * 'metadata.json' <- required file that must contain the following metadata:
14
+ -- - 'name' - package name
15
+ -- - 'version' - package version
16
+ -- - 'license' - package license
17
+ -- - 'summary' - package summary
18
+ -- - 'source' - package source
19
+ --
20
+ -- Example:
21
+ -- rpmbuild -D 'pup_module_info_dir /home/user/project/puppet_module' -ba SPECS/specfile.spec
22
+ --
23
+ -- If this is not found, we will look in %{_sourcedir} for the files and fall
24
+ -- back to the current directory
25
+ --
26
+
27
+ src_dir = rpm.expand('%{pup_module_info_dir}')
28
+
29
+ if string.match(src_dir, '^%%') or (posix.stat(src_dir, 'type') ~= 'directory') then
30
+ src_dir = rpm.expand('%{_sourcedir}')
31
+
32
+ if (posix.stat((src_dir .. "/metadata.json"), 'type') ~= 'regular') then
33
+ src_dir = './'
34
+ end
35
+ end
36
+
37
+ -- These UNKNOWN entries should break the build if something bad happens
38
+
39
+ package_name = "UNKNOWN"
40
+ package_version = "UNKNOWN"
41
+ module_license = "UNKNOWN"
42
+
43
+ --
44
+ -- Default to 0
45
+ --
46
+
47
+ package_release = 0
48
+ }
49
+
50
+ %{lua:
51
+ -- Pull the Relevant Metadata out of the Puppet module metadata.json.
52
+
53
+ metadata = ''
54
+ metadata_file = io.open(src_dir .. "/metadata.json","r")
55
+ if metadata_file then
56
+ metadata = metadata_file:read("*all")
57
+
58
+ -- Ignore the first curly brace
59
+ metadata = metadata:gsub("{}?", '|', 1)
60
+
61
+ -- Ignore all keys that are below the first level
62
+ metadata = metadata:gsub("{.-}", '')
63
+ metadata = metadata:gsub("%[.-%]", '')
64
+ else
65
+ error("Could not open 'metadata.json'", 0)
66
+ end
67
+
68
+ -- This starts as an empty string so that we can build it later
69
+ module_requires = ''
70
+
71
+ }
72
+
73
+ %{lua:
74
+
75
+ -- Get the Module Name and put it in the correct format
76
+
77
+ local name_match = string.match(metadata, '"name":%s+"(.-)"%s*,')
78
+
79
+ module_author = ''
80
+ module_name = ''
81
+
82
+ if name_match then
83
+ package_name = ('pupmod-' .. name_match)
84
+
85
+ local i = 0
86
+ for str in string.gmatch(name_match,'[^-]+') do
87
+ if i == 0 then
88
+ module_author = str
89
+ else
90
+ if module_name == '' then
91
+ module_name = str
92
+ else
93
+ module_name = (module_name .. '-' .. str)
94
+ end
95
+ end
96
+
97
+ i = i+1
98
+ end
99
+ else
100
+ error("Could not find valid package name in 'metadata.json'", 0)
101
+ end
102
+
103
+ }
104
+
105
+ %{lua:
106
+
107
+ -- Get the Module Version
108
+
109
+ local version_match = string.match(metadata, '"version":%s+"(.-)"%s*,')
110
+
111
+ if version_match then
112
+ package_version = version_match
113
+ else
114
+ error("Could not find valid package version in 'metadata.json'", 0)
115
+ end
116
+
117
+ }
118
+
119
+ %{lua:
120
+
121
+ -- Get the Module License
122
+
123
+ local license_match = string.match(metadata, '"license":%s+"(.-)"%s*,')
124
+
125
+ if license_match then
126
+ module_license = license_match
127
+ else
128
+ error("Could not find valid package license in 'metadata.json'", 0)
129
+ end
130
+
131
+ }
132
+
133
+ %{lua:
134
+
135
+ -- Get the Module Summary
136
+
137
+ local summary_match = string.match(metadata, '"summary":%s+"(.-)"%s*,')
138
+
139
+ if summary_match then
140
+ module_summary = summary_match
141
+ else
142
+ error("Could not find valid package summary in 'metadata.json'", 0)
143
+ end
144
+
145
+ }
146
+
147
+ %{lua:
148
+
149
+ -- Get the Module Source line for the URL string
150
+
151
+ local source_match = string.match(metadata, '"source":%s+"(.-)"%s*,')
152
+
153
+ if source_match then
154
+ module_source = source_match
155
+ else
156
+ error("Could not find valid package source in 'metadata.json'", 0)
157
+ end
158
+
159
+ }
160
+
161
+ %{lua:
162
+
163
+ -- Snag the RPM-specific items out of the 'build/rpm_metadata' directory
164
+
165
+ -- First, the Release Number
166
+
167
+ rel_file = io.open(src_dir .. "/build/rpm_metadata/release", "r")
168
+
169
+ if not rel_file then
170
+ -- Need this for the SRPM case
171
+ rel_file = io.open(src_dir .. "/release", "r")
172
+ end
173
+
174
+ if rel_file then
175
+ for line in rel_file:lines() do
176
+ is_comment = string.match(line, "^%s*#")
177
+ is_blank = string.match(line, "^%s*$")
178
+
179
+ if not (is_comment or is_blank) then
180
+ package_release = line
181
+ break
182
+ end
183
+ end
184
+ end
185
+
186
+ }
187
+
188
+ %{lua:
189
+
190
+ -- Next, the Requirements
191
+ req_file = io.open(src_dir .. "/build/rpm_metadata/requires", "r")
192
+
193
+ if not req_file then
194
+ -- Need this for the SRPM case
195
+ req_file = io.open(src_dir .. "/requires", "r")
196
+ end
197
+
198
+ if req_file then
199
+ for line in req_file:lines() do
200
+ valid_line = (string.match(line, "^Requires: ") or string.match(line, "^Obsoletes: ") or string.match(line, "^Provides: "))
201
+
202
+ if valid_line then
203
+ module_requires = (module_requires .. "\n" .. line)
204
+ end
205
+ end
206
+ end
207
+ }
208
+
209
+ %global _binaries_in_noarch_packages_terminate_build 0
210
+
211
+ %define module_name %{lua: print(module_name)}
212
+ %define package_name %{lua: print(package_name)}
213
+
214
+ Summary: %{module_name} Puppet Module
215
+ Name: %{package_name}
216
+
217
+ Version: %{lua: print(package_version)}
218
+ Release: %{lua: print(package_release)}
219
+ License: %{lua: print(module_license)}
220
+ Group: Applications/System
221
+ Source0: %{package_name}-%{version}-%{release}.tar.gz
222
+ Source1: %{lua: print("metadata.json")}
223
+ %{lua:
224
+ -- Include our sources as appropriate
225
+ changelog = io.open(src_dir .. "/CHANGELOG","r")
226
+ if changelog then
227
+ print("Source2: " .. "CHANGELOG\n")
228
+ end
229
+
230
+ if rel_file then
231
+ print("Source3: " .. "release\n")
232
+ end
233
+ if req_file then
234
+ print("Source4: " .. "requires\n")
235
+ end
236
+ }
237
+ URL: %{lua: print(module_source)}
238
+ BuildRoot: %{_tmppath}/%{package_name}-%{version}-%{release}-buildroot
239
+ BuildArch: noarch
240
+
241
+ Requires(pre,preun,post,postun): simp-adapter >= 0.0.1
242
+
243
+ %if ("%{package_name}" != "pupmod-simp-simplib") && ("%{package_name}" != "pupmod-puppetlabs-stdlib")
244
+ Requires: pupmod-simp-simplib >= 1.2.6
245
+ %endif
246
+
247
+ %if "%{package_name}" != "pupmod-puppetlabs-stdlib"
248
+ Requires: pupmod-puppetlabs-stdlib >= 4.9.0
249
+ Requires: pupmod-puppetlabs-stdlib < 6.0.0
250
+ %endif
251
+
252
+ %{lua: print(module_requires)}
253
+
254
+ Provides: pupmod-%{lua: print(module_name)} = %{lua: print(package_version .. "-" .. package_release)}
255
+ Obsoletes: pupmod-%{lua: print(module_name)} < %{lua: print(package_version .. "-" .. package_release)}
256
+
257
+ %{lua:
258
+
259
+ -- This is a workaround for the 'simp-rsync' real RPM conflict but is
260
+ -- required by some external modules.
261
+ -- This should be removed when SIMP 6 is stable
262
+
263
+ author_rpm_name = module_author .. "-" .. module_name
264
+
265
+ if author_rpm_name ~= 'simp-rsync' then
266
+ print("Provides: " .. author_rpm_name .. " = " .. package_version .. "-" .. package_release .. "\n")
267
+ print("Obsoletes: " .. author_rpm_name .. " < " .. package_version .. "-" .. package_release .. "\n")
268
+ end
269
+ }
270
+
271
+ Prefix: /usr/share/simp/modules
272
+
273
+ %description
274
+ %{lua: print(module_summary)}
275
+
276
+ %prep
277
+ %setup -q -n %{package_name}-%{version}
278
+
279
+ %build
280
+
281
+ %install
282
+ [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
283
+
284
+ mkdir -p %{buildroot}/%{prefix}
285
+
286
+ curdir=`pwd`
287
+ dirname=`basename $curdir`
288
+ cp -r ../$dirname %{buildroot}/%{prefix}/%{module_name}
289
+
290
+ # Remove unnecessary assets
291
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/.git
292
+ rm -f %{buildroot}/%{prefix}/%{module_name}/*.lock
293
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/spec/fixtures/modules
294
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/dist
295
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/junit
296
+ rm -rf %{buildroot}/%{prefix}/%{module_name}/log
297
+
298
+ %clean
299
+ [ "%{buildroot}" != "/" ] && rm -rf %{buildroot}
300
+
301
+ mkdir -p %{buildroot}/%{prefix}
302
+
303
+ %files
304
+ %defattr(0640,root,root,0750)
305
+ %{prefix}/%{module_name}
306
+
307
+ # when $1 = 1, this is an install
308
+ # when $1 = 2, this is an upgrade
309
+ %pre
310
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=%{prefix}/%{module_name} --rpm_section='pre' --rpm_status=$1
311
+
312
+ # when $1 = 1, this is an install
313
+ # when $1 = 2, this is an upgrade
314
+ %post
315
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=%{prefix}/%{module_name} --rpm_section='post' --rpm_status=$1
316
+
317
+ # when $1 = 1, this is the uninstall of the previous version during an upgrade
318
+ # when $1 = 0, this is the uninstall of the only version during an erase
319
+ %preun
320
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=%{prefix}/%{module_name} --rpm_section='preun' --rpm_status=$1
321
+
322
+ # when $1 = 1, this is the uninstall of the previous version during an upgrade
323
+ # when $1 = 0, this is the uninstall of the only version during an erase
324
+ %postun
325
+ /usr/local/sbin/simp_rpm_helper --rpm_dir=%{prefix}/%{module_name} --rpm_section='postun' --rpm_status=$1
326
+
327
+ %changelog
328
+ %{lua:
329
+ -- Finally, the CHANGELOG
330
+
331
+ -- A default CHANGELOG in case we cannot find a real one
332
+
333
+ default_changelog = [===[
334
+ * $date Auto Changelog <auto@no.body> - $version-$release
335
+ - Latest release of $name
336
+ ]===]
337
+
338
+ default_lookup_table = {
339
+ date = os.date("%a %b %d %Y"),
340
+ version = package_version,
341
+ release = package_release,
342
+ name = package_name
343
+ }
344
+
345
+ changelog = io.open(src_dir .. "/CHANGELOG","r")
346
+ if changelog then
347
+ first_line = changelog:read()
348
+ if string.match(first_line, "^*%s+%a%a%a%s+%a%a%a%s+%d%d?%s+%d%d%d%d%s+.+") then
349
+ changelog:seek("set",0)
350
+ print(changelog:read("*all"))
351
+ else
352
+ print((default_changelog:gsub('$(%w+)', default_lookup_table)))
353
+ end
354
+ else
355
+ print((default_changelog:gsub('$(%w+)', default_lookup_table)))
356
+ end
357
+ }