packaging 0.108.2 → 0.109.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -2
  3. data/lib/packaging/artifactory.rb +15 -10
  4. data/lib/packaging/config/validations.rb +1 -1
  5. data/lib/packaging/config.rb +5 -5
  6. data/lib/packaging/deb/repo.rb +4 -4
  7. data/lib/packaging/nuget.rb +1 -1
  8. data/lib/packaging/paths.rb +4 -3
  9. data/lib/packaging/sign/msi.rb +6 -8
  10. data/lib/packaging/util/execution.rb +1 -1
  11. data/lib/packaging/util/ezbake.rb +1 -1
  12. data/lib/packaging/util/file.rb +4 -6
  13. data/lib/packaging/util/net.rb +8 -12
  14. data/lib/packaging/util/ship.rb +17 -7
  15. data/lib/packaging/util/tool.rb +1 -1
  16. data/lib/packaging/util/version.rb +7 -5
  17. data/spec/lib/packaging/config_spec.rb +300 -279
  18. data/spec/lib/packaging/deb/repo_spec.rb +138 -76
  19. data/spec/lib/packaging/deb_spec.rb +28 -25
  20. data/spec/lib/packaging/repo_spec.rb +52 -31
  21. data/spec/lib/packaging/rpm/repo_spec.rb +18 -37
  22. data/spec/lib/packaging/sign_spec.rb +22 -43
  23. data/spec/lib/packaging/tar_spec.rb +48 -44
  24. data/spec/lib/packaging/util/execution_spec.rb +32 -32
  25. data/spec/lib/packaging/util/file_spec.rb +112 -75
  26. data/spec/lib/packaging/util/gpg_spec.rb +24 -19
  27. data/spec/lib/packaging/util/jenkins_spec.rb +79 -48
  28. data/spec/lib/packaging/util/misc_spec.rb +13 -8
  29. data/spec/lib/packaging/util/net_spec.rb +193 -152
  30. data/spec/lib/packaging/util/rake_utils_spec.rb +24 -18
  31. data/spec/lib/packaging_spec.rb +7 -9
  32. data/tasks/apple.rake +7 -8
  33. data/tasks/deb.rake +1 -1
  34. data/tasks/fetch.rake +2 -2
  35. data/tasks/mock.rake +3 -3
  36. data/tasks/nightly_repos.rake +11 -9
  37. data/tasks/rpm.rake +2 -3
  38. data/tasks/ship.rake +4 -2
  39. data/tasks/sign.rake +8 -10
  40. data/tasks/z_data_dump.rake +3 -3
  41. metadata +46 -33
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3fd1a48b6b204c719549f2d857edefc600eb504da996e5ec68c0298a11734c0
4
- data.tar.gz: 2ccdf98e53f9cea5aaa92346517679e5c468bcc32f6ed6f81c22144906f8b1fe
3
+ metadata.gz: 11bd7673d3f37ddab90b44202787f13882b390ffb4acbb858b3161166f0d2d0e
4
+ data.tar.gz: 4623cd4dd183c885ac2984fcb31d403629b2a8e1b294fade1ee918862a978f04
5
5
  SHA512:
6
- metadata.gz: ef6517a8347b83b2adbe306302a4a6274a8854731b582f3ec0a1d1a7f6066e7655ad7bf953c40db9cdf359346068a4ebe4e0ebd9cb1cfac733533a1a7c27fe5f
7
- data.tar.gz: e359e1e2c06be60e2cb668c2dd478cad89321e8bde6718968d697829dd6987d7800dde683c17325eb1c3be21470d8de497711da9f0610995ac7ea1aecde12697
6
+ metadata.gz: b495a1512b62e06c39405daaa6a89c09dcea8350006ef6321af2084f01e04b6c97dd41f80bb8ec8592d7b4fe875b1491ae5deee1b45b4bdb99b6888a586dfbee
7
+ data.tar.gz: f448461101f22184101346cddba0650932796d4dff63fc7ce716f13592c29ff1c417f5908226c3184095067c6aecb32dff6cf069d9274d701c5e559aa0e73079
data/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # Packaging
2
2
 
3
- [![Build Status](https://travis-ci.org/puppetlabs/packaging.png?branch=master)](https://travis-ci.org/puppetlabs/packaging)
4
-
5
3
  This is a repository for packaging automation for Puppet software.
6
4
  The goal is to abstract and automate packaging processes beyond individual
7
5
  software projects to a level where this repo can be cloned inside any project
@@ -192,18 +192,23 @@ module Pkg
192
192
  properties_hash
193
193
  end
194
194
 
195
- # Basic method to check if a package exists on artifactory
195
+ # Return a list of artifact paths for package. Returns empty array if none.
196
+ def artifact_paths(package)
197
+ check_authorization
198
+ Artifactory::Resource::Artifact.search(
199
+ name: File.basename(package),
200
+ artifactory_uri: @artifactory_uri
201
+ )
202
+ end
203
+
204
+ # Check if a package exists on artifactory
196
205
  # @param package [String] The full relative path to the package to be
197
206
  # checked, relative from the current working directory
198
- # Return true if package already exists on artifactory
207
+ # Return true if package already exists on artifactory.
208
+ # #artifact_paths, above, is more useful since it will inform where they are.
209
+ # This is kept for backward compatibility.
199
210
  def package_exists_on_artifactory?(package)
200
- check_authorization
201
- artifact = Artifactory::Resource::Artifact.search(name: File.basename(package), :artifactory_uri => @artifactory_uri)
202
- if artifact.empty?
203
- return false
204
- else
205
- return true
206
- end
211
+ artifact_paths(package).any?
207
212
  end
208
213
 
209
214
  # @param package [String] The full relative path to the package to be
@@ -231,7 +236,7 @@ module Pkg
231
236
  # @return [String] The contents of the YAML file
232
237
  def retrieve_yaml_data(pkg, ref)
233
238
  yaml_url = "#{@artifactory_uri}/#{DEFAULT_REPO_TYPE}/#{DEFAULT_REPO_BASE}/#{pkg}/#{ref}/#{ref}.yaml"
234
- URI.open(yaml_url, &:read)
239
+ URI.parse(yaml_url).read
235
240
  rescue StandardError
236
241
  raise "Failed to load YAML data for #{pkg} at #{ref} from #{yaml_url}!"
237
242
  end
@@ -4,7 +4,7 @@ module Pkg
4
4
  # As a validation, this one is kindof lame but is intended as a seed pattern for possibly
5
5
  # more robust ones.
6
6
  def not_empty?(value)
7
- value.to_s.empty? ? false : true
7
+ !value.to_s.empty?
8
8
  end
9
9
  end
10
10
  end
@@ -5,8 +5,8 @@ module Pkg
5
5
  # have it set via accessors, and serialize it back to yaml for easy transport.
6
6
  #
7
7
  class Config
8
- require 'packaging/config/params.rb'
9
- require 'packaging/config/validations.rb'
8
+ require 'packaging/config/params'
9
+ require 'packaging/config/validations'
10
10
  require 'yaml'
11
11
 
12
12
  class << self
@@ -79,7 +79,7 @@ module Pkg
79
79
  Pkg::Util::Net.check_host_ssh([self.builds_server]).empty?
80
80
 
81
81
  dir = "/opt/jenkins-builds/#{self.project}/#{self.ref}"
82
- cmd = "if [ -s \"#{dir}/artifacts\" ]; then cd #{dir};"\
82
+ cmd = "if [ -s \"#{dir}/artifacts\" ]; then cd #{dir};" \
83
83
  "find ./artifacts -mindepth 2 -type f; fi"
84
84
  artifacts, = Pkg::Util::Net.remote_execute(
85
85
  self.builds_server,
@@ -132,12 +132,12 @@ module Pkg
132
132
 
133
133
  case package_format
134
134
  when 'deb'
135
- repo_config = "../repo_configs/deb/pl-#{self.project}-#{self.ref}-"\
135
+ repo_config = "../repo_configs/deb/pl-#{self.project}-#{self.ref}-" \
136
136
  "#{Pkg::Platforms.get_attribute(tag, :codename)}.list"
137
137
  when 'rpm'
138
138
  # Using original_tag here to not break legacy fedora repo targets
139
139
  unless tag.include? 'aix'
140
- repo_config = "../repo_configs/rpm/pl-#{self.project}-"\
140
+ repo_config = "../repo_configs/rpm/pl-#{self.project}-" \
141
141
  "#{self.ref}-#{original_tag}.repo"
142
142
  end
143
143
  when 'swix', 'svr4', 'ips', 'dmg', 'msi'
@@ -93,7 +93,7 @@ module Pkg::Deb::Repo
93
93
 
94
94
  artifact_paths.each do |path|
95
95
  platform_tag = Pkg::Paths.tag_from_artifact_path(path)
96
- platform, version, = Pkg::Platforms. parse_platform_tag(platform_tag)
96
+ platform, version, = Pkg::Platforms.parse_platform_tag(platform_tag)
97
97
  codename = Pkg::Platforms.codename_for_platform_version(platform, version)
98
98
  arches = Pkg::Platforms.arches_for_codename(codename)
99
99
 
@@ -224,10 +224,10 @@ SignWith: #{Pkg::Config.gpg_key}"
224
224
 
225
225
  options << '--dry-run' if dryrun
226
226
  options << path
227
- if !destination.nil?
228
- options << "#{destination}:#{dest_path.parent}"
229
- else
227
+ if destination.nil?
230
228
  options << dest_path.parent.to_s
229
+ else
230
+ options << "#{destination}:#{dest_path.parent}"
231
231
  end
232
232
  options.join("\s")
233
233
  end
@@ -23,7 +23,7 @@ module Pkg::Nuget
23
23
  form_data = ["-H 'Authorization: Basic #{authentication}'", "-f"]
24
24
  packages.each do |pkg|
25
25
  puts "Working on package #{pkg}"
26
- projname, version = File.basename(pkg).match(/^(.*)-([\d+\.]+)\.nupkg$/).captures
26
+ projname, version = File.basename(pkg).match(/^(.*)-([\d+.]+)\.nupkg$/).captures
27
27
  package_form_data = ["--upload-file #{pkg}"]
28
28
  package_path = "#{projname}/#{version}/#{File.basename(pkg)}"
29
29
  stdout = ''
@@ -23,7 +23,7 @@ module Pkg::Paths
23
23
  # Given a path to an artifact, divine the appropriate platform tag associated
24
24
  # with the artifact and path
25
25
  def tag_from_artifact_path(path)
26
- platform = Pkg::Platforms.supported_platforms.find { |p| path =~ /(\/|\.)#{p}[^\.]/ }
26
+ platform = Pkg::Platforms.supported_platforms.find { |p| path =~ /(\/|\.)#{p}[^.]/ }
27
27
  platform = 'windowsfips' if path =~ /windowsfips/
28
28
 
29
29
  codename = Pkg::Platforms.codenames.find { |c| path =~ /\/#{c}/ }
@@ -318,7 +318,8 @@ module Pkg::Paths
318
318
 
319
319
  # For repos prior to puppet7, the puppet version was part of the repository
320
320
  # For example: /opt/repository/apt/pool/bionic/puppet6/p/puppet-agent
321
- if %w[puppet7 puppet7-nightly
321
+ if %w[puppet8 puppet8-nightly
322
+ puppet7 puppet7-nightly
322
323
  puppet6 puppet6-nightly
323
324
  puppet5 puppet5-nightly
324
325
  puppet puppet-nightly
@@ -349,7 +350,7 @@ module Pkg::Paths
349
350
  def debian_component_from_path(path)
350
351
  # substitute '.' and '/' since those aren't valid characters for debian components
351
352
  matches = path.match(/(\d+\.\d+|master|main)\/(\w+)/)
352
- regex_for_substitution = /[\.\/]/
353
+ regex_for_substitution = /[.\/]/
353
354
  fail "Error: Could not determine Debian Component from path #{path}" if matches.nil?
354
355
  base_component = matches[1]
355
356
  component_qualifier = matches[2]
@@ -66,14 +66,12 @@ module Pkg::Sign::Msi
66
66
 
67
67
  # Download the signed msis
68
68
  msis.each do |msi|
69
- begin
70
- signed_msi = signed_bucket.file(signed_msis[msi])
71
- signed_msi.download(msi)
72
- rescue StandardError => e
73
- delete_tosign_msis(tosign_bucket, msis)
74
- delete_signed_msis(signed_bucket, signed_msis)
75
- fail "There was an error retrieving the signed msi:#{msi}.\n#{e}"
76
- end
69
+ signed_msi = signed_bucket.file(signed_msis[msi])
70
+ signed_msi.download(msi)
71
+ rescue StandardError => e
72
+ delete_tosign_msis(tosign_bucket, msis)
73
+ delete_signed_msis(signed_bucket, signed_msis)
74
+ fail "There was an error retrieving the signed msi:#{msi}.\n#{e}"
77
75
  end
78
76
 
79
77
  # Cleanup buckets
@@ -71,7 +71,7 @@ module Pkg::Util::Execution
71
71
  break
72
72
  rescue StandardError => err
73
73
  puts "An error was encountered evaluating block. Retrying.."
74
- exception = err.to_s + "\n" + err.backtrace.join("\n")
74
+ exception = "#{err.to_s}\n#{err.backtrace.join("\n")}"
75
75
  end
76
76
  end
77
77
  else
@@ -15,7 +15,7 @@ module Pkg::Util::EZbake
15
15
  )
16
16
  end
17
17
 
18
- if File.exists?(ezbake_yaml)
18
+ if File.exist?(ezbake_yaml)
19
19
  FileUtils.cp(
20
20
  ezbake_yaml,
21
21
  File.join(target_directory, "#{Pkg::Config.ref}.ezbake.manifest.yaml")
@@ -58,7 +58,7 @@ module Pkg::Util::File
58
58
 
59
59
  def erb_string(erbfile, b = binding)
60
60
  template = File.read(erbfile)
61
- message = ERB.new(template, nil, "-")
61
+ message = ERB.new(template, trim_mode: "-")
62
62
  message.result(b)
63
63
  end
64
64
 
@@ -98,7 +98,7 @@ module Pkg::Util::File
98
98
  Dir.chdir(Pkg::Config.project_root) do
99
99
  file_patterns.each do |pattern|
100
100
  if File.directory?(pattern) and !Pkg::Util::File.empty_dir?(pattern)
101
- install << Dir[pattern + "/**/*"]
101
+ install << Dir["#{pattern}/**/*"]
102
102
  else
103
103
  install << Dir[pattern]
104
104
  end
@@ -146,8 +146,8 @@ module Pkg::Util::File
146
146
  team_data_branch = Pkg::Config.team
147
147
 
148
148
  if Pkg::Config.build_pe
149
- project_data_branch = 'pe-' + project_data_branch unless project_data_branch =~ /^pe-/
150
- team_data_branch = 'pe-' + team_data_branch unless team_data_branch =~ /^pe-/
149
+ project_data_branch = "pe-#{project_data_branch}" unless project_data_branch =~ /^pe-/
150
+ team_data_branch = "pe-#{team_data_branch}" unless team_data_branch =~ /^pe-/
151
151
  end
152
152
 
153
153
  # Remove .packaging directory from old-style extras loading
@@ -189,7 +189,6 @@ module Pkg::Util::File
189
189
  # PL Release team
190
190
  def load_extras(temp_directory)
191
191
  unless ENV['PARAMS_FILE'] && ENV['PARAMS_FILE'] != ''
192
- temp_directory = temp_directory
193
192
  raise "load_extras requires a directory containing extras data" if temp_directory.nil?
194
193
  Pkg::Config.config_from_yaml("#{temp_directory}/#{Pkg::Config.builder_data_file}")
195
194
 
@@ -200,4 +199,3 @@ module Pkg::Util::File
200
199
  end
201
200
  end
202
201
  end
203
-
@@ -7,7 +7,7 @@ module Pkg::Util::Net
7
7
  def fetch_uri(uri, target)
8
8
  require 'open-uri'
9
9
  if Pkg::Util::File.file_writable?(File.dirname(target))
10
- File.open(target, 'w') { |f| f.puts(URI.open(uri).read) }
10
+ File.open(target, 'w') { |f| f.puts(URI.parse(uri).read) }
11
11
  end
12
12
  end
13
13
 
@@ -33,11 +33,9 @@ module Pkg::Util::Net
33
33
  def check_host_ssh(hosts)
34
34
  errs = []
35
35
  Array(hosts).flatten.each do |host|
36
- begin
37
- remote_execute(host, 'exit', { extra_options: '-oBatchMode=yes' })
38
- rescue StandardError
39
- errs << host
40
- end
36
+ remote_execute(host, 'exit', { extra_options: '-oBatchMode=yes' })
37
+ rescue StandardError
38
+ errs << host
41
39
  end
42
40
  return errs
43
41
  end
@@ -51,12 +49,10 @@ module Pkg::Util::Net
51
49
  def check_host_gpg(hosts, gpg)
52
50
  errs = []
53
51
  Array(hosts).flatten.each do |host|
54
- begin
55
- remote_execute(host, "gpg --list-secret-keys #{gpg} > /dev/null 2&>1",
56
- { extra_options: '-oBatchMode=yes' })
57
- rescue StandardError
58
- errs << host
59
- end
52
+ remote_execute(host, "gpg --list-secret-keys #{gpg} > /dev/null 2&>1",
53
+ { extra_options: '-oBatchMode=yes' })
54
+ rescue StandardError
55
+ errs << host
60
56
  end
61
57
  return errs
62
58
  end
@@ -377,7 +377,7 @@ module Pkg::Util::Ship
377
377
  FileUtils.cp(ezbake_manifest, File.join(local_directory, "#{Pkg::Config.ref}.ezbake.manifest"))
378
378
  end
379
379
  ezbake_yaml = File.join("ext", "ezbake.manifest.yaml")
380
- if File.exists?(ezbake_yaml)
380
+ if File.exist?(ezbake_yaml)
381
381
  FileUtils.cp(ezbake_yaml, File.join(local_directory, "#{Pkg::Config.ref}.ezbake.manifest.yaml"))
382
382
  end
383
383
 
@@ -478,7 +478,8 @@ module Pkg::Util::Ship
478
478
  def ship_to_artifactory(local_directory = 'pkg')
479
479
  Pkg::Util::File.fetch
480
480
  unless Pkg::Config.project
481
- fail "You must set the 'project' in build_defaults.yaml or with the 'PROJECT_OVERRIDE' environment variable."
481
+ fail 'Project missing. Set it with the "project" key in build_defaults.yaml or ' \
482
+ 'with the "PROJECT_OVERRIDE" environment variable.'
482
483
  end
483
484
  artifactory = Pkg::ManageArtifactory.new(Pkg::Config.project, Pkg::Config.ref)
484
485
 
@@ -492,14 +493,23 @@ module Pkg::Util::Ship
492
493
  a <=> b
493
494
  end
494
495
  end
496
+
495
497
  artifacts.each do |artifact|
496
- if File.extname(artifact) == ".yaml" || File.extname(artifact) == ".json"
497
- artifactory.deploy_package(artifact)
498
- elsif artifactory.package_exists_on_artifactory?(artifact)
499
- warn "Attempt to upload '#{artifact}' failed. Package already exists!"
500
- else
498
+ # Always ship .yaml and .jsons even if they already exist
499
+ if %w[.yaml .json].include? File.extname(artifact)
501
500
  artifactory.deploy_package(artifact)
501
+ next
502
502
  end
503
+
504
+ # Warn against anything that already exists
505
+ existing = artifactory.artifact_paths(artifact)
506
+ if existing.any?
507
+ warn "Uploading '#{artifact}' to Artifactory refused. " \
508
+ "Package already exists here: #{existing.join(', ')}"
509
+ next
510
+ end
511
+
512
+ artifactory.deploy_package(artifact)
503
513
  end
504
514
  end
505
515
  end
@@ -18,7 +18,7 @@ module Pkg::Util::Tool
18
18
  exts.each do |ext|
19
19
  locationext = File.expand_path(location + ext)
20
20
 
21
- return '"' + locationext + '"' if FileTest.executable?(locationext)
21
+ return "\"#{locationext}\"" if FileTest.executable?(locationext)
22
22
  end
23
23
  end
24
24
 
@@ -93,7 +93,7 @@ module Pkg::Util::Version
93
93
  end
94
94
 
95
95
  if new_version.include?('dirty')
96
- new_version = new_version.sub(/\.?dirty/, '') + 'dirty'
96
+ new_version = "#{new_version.sub(/\.?dirty/, '')}dirty"
97
97
  end
98
98
 
99
99
  new_version.split('-')
@@ -143,9 +143,11 @@ module Pkg::Util::Version
143
143
  #
144
144
  def versionbump(workdir = nil)
145
145
  version = ENV['VERSION'] || Pkg::Config.version.to_s.strip
146
- new_version = '"' + version + '"'
146
+ new_version = "\"#{version}\""
147
147
 
148
+ # rubocop:disable Style/StringConcatenation
148
149
  version_file = "#{workdir ? workdir + '/' : ''}#{Pkg::Config.version_file}"
150
+ # rubocop:enable Style/StringConcatenation
149
151
 
150
152
  # Read the previous version file in...
151
153
  contents = IO.read(version_file)
@@ -160,7 +162,7 @@ module Pkg::Util::Version
160
162
  puts "Updating #{old_version} to #{new_version} in #{version_file}"
161
163
  if contents =~ /@DEVELOPMENT_VERSION@/
162
164
  contents.gsub!('@DEVELOPMENT_VERSION@', version)
163
- elsif contents =~ /version\s*=\s*[\'"]DEVELOPMENT[\'"]/
165
+ elsif contents =~ /version\s*=\s*['"]DEVELOPMENT['"]/
164
166
  contents.gsub!(/version\s*=\s*['"]DEVELOPMENT['"]/, "version = '#{version}'")
165
167
  elsif contents =~ /VERSION = #{old_version}/
166
168
  contents.gsub!("VERSION = #{old_version}", "VERSION = #{new_version}")
@@ -179,8 +181,8 @@ module Pkg::Util::Version
179
181
  #
180
182
  # @param json_data [hash] json data hash containing the ref to check
181
183
  def report_json_tags(json_data)
182
- puts 'component: ' + File.basename(json_data['url'])
183
- puts 'ref: ' + json_data['ref'].to_s
184
+ puts "component: #{File.basename(json_data['url'])}"
185
+ puts "ref: #{json_data['ref'].to_s}"
184
186
  if Pkg::Util::Git.remote_tagged?(json_data['url'], json_data['ref'].to_s)
185
187
  tagged = 'Tagged? [ Yes ]'
186
188
  else