cartage 2.2 → 2.2.1

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.
data/lib/cartage.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
- require 'json'
3
+ require "pathname"
4
+ require "json"
5
5
 
6
- require 'cartage/core'
7
- require 'cartage/plugin'
8
- require 'cartage/config'
6
+ require "cartage/core"
7
+ require "cartage/plugin"
8
+ require "cartage/config"
9
9
 
10
10
  ##
11
11
  # Cartage, a reliable package builder.
12
12
  class Cartage
13
- VERSION = '2.2' #:nodoc:
13
+ VERSION = "2.2.1" # :nodoc:
14
14
 
15
15
  # Creates a new Cartage instance. If provided a Cartage::Config object in
16
16
  # +config+, sets the configuration and resolves it. If +config+ is not
@@ -30,7 +30,7 @@ class Cartage
30
30
  # The default name of the package to be created, derived from the
31
31
  # repository's Git URL.
32
32
 
33
- attr_accessor_with_default :name, default: -> { File.basename(repo_url, '.git') }
33
+ attr_accessor_with_default :name, default: -> { File.basename(repo_url, ".git") }
34
34
 
35
35
  ##
36
36
  # :attr_accessor: root_path
@@ -44,11 +44,11 @@ class Cartage
44
44
  # repository.
45
45
 
46
46
  attr_reader_with_default :root_path do
47
- Pathname(%x(git rev-parse --show-cdup).chomp).expand_path
47
+ Pathname(`git rev-parse --show-cdup`.chomp).expand_path
48
48
  end
49
49
 
50
50
  ##
51
- def root_path=(v) #:nodoc:
51
+ def root_path=(v) # :nodoc:
52
52
  reset_computed_values
53
53
  @root_path = Pathname(v).expand_path
54
54
  end
@@ -65,7 +65,7 @@ class Cartage
65
65
 
66
66
  attr_accessor_with_default :target,
67
67
  transform: ->(v) { Pathname(v) },
68
- default: -> { Pathname('tmp') }
68
+ default: -> { Pathname("tmp") }
69
69
 
70
70
  ##
71
71
  # :attr_accessor: timestamp
@@ -78,7 +78,7 @@ class Cartage
78
78
  # The default timestamp.
79
79
 
80
80
  attr_accessor_with_default :timestamp, default: -> {
81
- Time.now.utc.strftime('%Y%m%d%H%M%S')
81
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
82
82
  }
83
83
 
84
84
  ##
@@ -97,9 +97,9 @@ class Cartage
97
97
  end
98
98
 
99
99
  ##
100
- def compression=(value) #:nodoc:
100
+ def compression=(value) # :nodoc:
101
101
  case value
102
- when :bzip2, :none, :gzip, 'bzip2', 'none', 'gzip'
102
+ when :bzip2, :none, :gzip, "bzip2", "none", "gzip"
103
103
  @compression = value
104
104
  reset_computed_values
105
105
  else
@@ -142,10 +142,10 @@ class Cartage
142
142
  end
143
143
 
144
144
  ##
145
- def dependency_cache_path=(path) #:nodoc:
145
+ def dependency_cache_path=(path) # :nodoc:
146
146
  @dependency_cache_path = Pathname(path || tmp_path).expand_path
147
- @dependency_cache = @dependency_cache_path.
148
- join("dependency-cache.tar#{tar_compression_extension}")
147
+ @dependency_cache = @dependency_cache_path
148
+ .join("dependency-cache.tar#{tar_compression_extension}")
149
149
  end
150
150
 
151
151
  # Commands that normally output data will have that output suppressed.
@@ -159,7 +159,7 @@ class Cartage
159
159
  # by providing the +for_plugin+ or +for_command+ parameters.
160
160
  def config(for_plugin: nil, for_command: nil)
161
161
  if for_plugin && for_command
162
- fail ArgumentError, 'Cannot get config for plug-in and command together'
162
+ fail ArgumentError, "Cannot get config for plug-in and command together"
163
163
  elsif for_plugin
164
164
  @config.dig(:plugins, for_plugin.to_sym) || OpenStruct.new
165
165
  elsif for_command
@@ -171,7 +171,7 @@ class Cartage
171
171
 
172
172
  # The config file. This should not be used by clients.
173
173
  def config=(cfg) # :nodoc:
174
- fail ArgumentError, 'No config provided' unless cfg
174
+ fail ArgumentError, "No config provided" unless cfg
175
175
  @plugins = Plugins.new
176
176
  @config = cfg
177
177
  resolve_config!
@@ -183,7 +183,7 @@ class Cartage
183
183
  package: {
184
184
  name: name,
185
185
  repo: {
186
- type: 'git', # Hardcoded until we have other support
186
+ type: "git", # Hardcoded until we have other support
187
187
  url: repo_url
188
188
  },
189
189
  hashref: release_hashref,
@@ -194,21 +194,21 @@ class Cartage
194
194
 
195
195
  # Return the release hashref.
196
196
  def release_hashref
197
- @release_hashref ||= %x(git rev-parse HEAD).chomp
197
+ @release_hashref ||= `git rev-parse HEAD`.chomp
198
198
  end
199
199
 
200
200
  # The repository URL.
201
201
  def repo_url
202
202
  unless defined? @repo_url
203
- @repo_url = %x(git remote show -n origin).
204
- match(/\n\s+Fetch URL: (?<fetch>[^\n]+)/)[:fetch]
203
+ @repo_url = `git remote show -n origin`
204
+ .match(/\n\s+Fetch URL: (?<fetch>[^\n]+)/)[:fetch]
205
205
  end
206
206
  @repo_url
207
207
  end
208
208
 
209
209
  # The temporary path.
210
210
  def tmp_path
211
- @tmp_path ||= root_path.join('tmp')
211
+ @tmp_path ||= root_path.join("tmp")
212
212
  end
213
213
 
214
214
  # The working path for the job, in #tmp_path.
@@ -236,13 +236,13 @@ class Cartage
236
236
  # A utility method for Cartage plug-ins to run a +command+ in the shell. Uses
237
237
  # IO.popen.
238
238
  def run(command)
239
- display command.join(' ')
239
+ display command.join(" ")
240
240
 
241
- IO.popen(command + [ err: %i(child out) ]) do |io|
241
+ IO.popen(command + [err: %i[child out]]) do |io|
242
242
  __display(io.read(128), partial: true, verbose: true) until io.eof?
243
243
  end
244
244
 
245
- fail StandardError, "Error running '#{command.join(' ')}'" unless $?.success?
245
+ fail StandardError, "Error running '#{command.join(" ")}'" unless $?.success?
246
246
  end
247
247
 
248
248
  # Returns the registered plug-ins, once configuration has been resolved.
@@ -276,13 +276,13 @@ class Cartage
276
276
 
277
277
  # Just save the release metadata.
278
278
  def save_release_metadata(local: false)
279
- display 'Saving release metadata...'
279
+ display "Saving release metadata..."
280
280
  json = JSON.generate(release_metadata)
281
281
 
282
282
  if local
283
- Pathname('.').join('release-metadata.json').write(json)
283
+ Pathname(".").join("release-metadata.json").write(json)
284
284
  else
285
- work_path.join('release-metadata.json').write(json)
285
+ work_path.join("release-metadata.json").write(json)
286
286
  final_release_metadata_json.write(json)
287
287
  end
288
288
  end
@@ -290,24 +290,24 @@ class Cartage
290
290
  # Returns the flag to use with +tar+ given the value of +compression+.
291
291
  def tar_compression_flag
292
292
  case compression
293
- when :bzip2, 'bzip2', nil
294
- 'j'
295
- when :gzip, 'gzip'
296
- 'z'
297
- when :none, 'none'
298
- ''
293
+ when :bzip2, "bzip2", nil
294
+ "j"
295
+ when :gzip, "gzip"
296
+ "z"
297
+ when :none, "none"
298
+ ""
299
299
  end
300
300
  end
301
301
 
302
302
  # Returns the extension to use with +tar+ given the value of +compression+.
303
303
  def tar_compression_extension
304
304
  case compression
305
- when :bzip2, 'bzip2', nil
306
- '.bz2'
307
- when :gzip, 'gzip'
308
- '.gz'
309
- when :none, 'none'
310
- ''
305
+ when :bzip2, "bzip2", nil
306
+ ".bz2"
307
+ when :gzip, "gzip"
308
+ ".gz"
309
+ when :none, "none"
310
+ ""
311
311
  end
312
312
  end
313
313
 
@@ -356,18 +356,18 @@ class Cartage
356
356
  target = work_path
357
357
  target /= to if to
358
358
 
359
- tar_cf_cmd = [ 'tar', 'cf', '-', '-h', '-C', parent, path ].map(&:to_s)
360
- tar_xf_cmd = [ 'tar', 'xf', '-', '-C', target ].map(&:to_s)
359
+ tar_cf_cmd = ["tar", "cf", "-", "-h", "-C", parent, path].map(&:to_s)
360
+ tar_xf_cmd = ["tar", "xf", "-", "-C", target].map(&:to_s)
361
361
 
362
362
  IO.popen(tar_cf_cmd) do |cf|
363
- IO.popen(tar_xf_cmd, 'w') do |xf|
363
+ IO.popen(tar_xf_cmd, "w") do |xf|
364
364
  xf.write cf.read
365
365
  end
366
366
 
367
- fail StandardError, "Error running #{tar_xf_cmd.join(' ')}" unless $?.success?
367
+ fail StandardError, "Error running #{tar_xf_cmd.join(" ")}" unless $?.success?
368
368
  end
369
369
 
370
- fail StandardError, "Error running #{tar_cf_cmd.join(' ')}" unless $?.success?
370
+ fail StandardError, "Error running #{tar_cf_cmd.join(" ")}" unless $?.success?
371
371
  end
372
372
 
373
373
  private
@@ -375,7 +375,7 @@ class Cartage
375
375
  attr_writer :release_hashref
376
376
 
377
377
  def resolve_config!
378
- fail 'No configuration' unless config
378
+ fail "No configuration" unless config
379
379
 
380
380
  self.disable_dependency_cache = config.disable_dependency_cache
381
381
  self.quiet = config.quiet
@@ -388,7 +388,7 @@ class Cartage
388
388
  maybe_assign :dependency_cache_path, config.dependency_cache_path
389
389
  maybe_assign :release_hashref, config.release_hashref
390
390
 
391
- lib = root_path.join('lib').to_s
391
+ lib = root_path.join("lib").to_s
392
392
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.any? { |l| l == lib }
393
393
  Cartage::Plugin.load(rescan: true)
394
394
 
@@ -407,7 +407,7 @@ class Cartage
407
407
 
408
408
  def maybe_assign(name, value)
409
409
  return if value.nil? || (value.respond_to?(:empty?) && value.empty?) ||
410
- instance_variable_defined?(:"@#{name}")
410
+ instance_variable_defined?(:"@#{name}")
411
411
  send(:"#{name}=", value)
412
412
  end
413
413
 
@@ -431,39 +431,39 @@ class Cartage
431
431
  end
432
432
 
433
433
  def prepare_work_area
434
- display 'Preparing cartage work area...'
434
+ display "Preparing cartage work area..."
435
435
 
436
436
  work_path.rmtree if work_path.exist?
437
437
  work_path.mkpath
438
438
 
439
439
  manifest.resolve(root_path) do |file_list|
440
440
  tar_cf_cmd = [
441
- 'tar', 'cf', '-', '-C', parent, '-h', '-T', file_list
441
+ "tar", "cf", "-", "-C", parent, "-h", "-T", file_list
442
442
  ].map(&:to_s)
443
443
 
444
444
  tar_xf_cmd = [
445
- 'tar', 'xf', '-', '-C', work_path, '--strip-components=1'
445
+ "tar", "xf", "-", "-C", work_path, "--strip-components=1"
446
446
  ].map(&:to_s)
447
447
 
448
448
  IO.popen(tar_cf_cmd) do |cf|
449
- IO.popen(tar_xf_cmd, 'w') do |xf|
449
+ IO.popen(tar_xf_cmd, "w") do |xf|
450
450
  xf.write cf.read
451
451
  end
452
452
 
453
- fail StandardError, "Error running #{tar_xf_cmd.join(' ')}" unless $?.success?
453
+ fail StandardError, "Error running #{tar_xf_cmd.join(" ")}" unless $?.success?
454
454
  end
455
455
 
456
- fail StandardError, "Error running #{tar_cf_cmd.join(' ')}" unless $?.success?
456
+ fail StandardError, "Error running #{tar_cf_cmd.join(" ")}" unless $?.success?
457
457
  end
458
458
  end
459
459
 
460
460
  def restore_modified_files
461
- %x(git status -s).
462
- split($/).
463
- map(&:split).
464
- select { |s, _f| s !~ /\?/ }.
465
- map(&:last).
466
- each { |file|
461
+ `git status -s`
462
+ .split($/)
463
+ .map(&:split)
464
+ .select { |s, _f| s !~ /\?/ }
465
+ .map(&:last)
466
+ .each { |file|
467
467
  restore_modified_file file
468
468
  }
469
469
  end
@@ -472,11 +472,11 @@ class Cartage
472
472
  return unless work_path.join(filename).exist?
473
473
 
474
474
  command = [
475
- 'git', 'show', "#{release_hashref}:#{filename}"
475
+ "git", "show", "#{release_hashref}:#{filename}"
476
476
  ]
477
477
 
478
478
  IO.popen(command) do |show|
479
- work_path.join(filename).open('w') { |f|
479
+ work_path.join(filename).open("w") { |f|
480
480
  f.puts show.read
481
481
  }
482
482
  end
@@ -494,16 +494,16 @@ class Cartage
494
494
 
495
495
  def extract_dependency_cache
496
496
  return if disable_dependency_cache || !dependency_cache.exist?
497
- run %W(tar xf#{tar_compression_flag} #{dependency_cache} -C #{work_path})
497
+ run %W[tar xf#{tar_compression_flag} #{dependency_cache} -C #{work_path}]
498
498
  end
499
499
 
500
500
  def create_dependency_cache(paths = [])
501
501
  return if disable_dependency_cache || paths.empty?
502
502
  run [
503
- 'tar',
503
+ "tar",
504
504
  "cf#{tar_compression_flag}",
505
505
  dependency_cache,
506
- '-C',
506
+ "-C",
507
507
  work_path,
508
508
  *paths
509
509
  ].map(&:to_s)
@@ -527,4 +527,4 @@ class Cartage
527
527
  end
528
528
  end
529
529
 
530
- require_relative 'cartage/config'
530
+ require_relative "cartage/config"
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- gem 'minitest'
4
- require 'minitest/autorun'
5
- require 'minitest/pretty_diff'
6
- require 'minitest/focus'
7
- require 'minitest/moar'
8
- require 'minitest/bisect'
9
- require 'minitest-bonus-assertions'
3
+ gem "minitest"
4
+ require "minitest/autorun"
5
+ require "minitest/pretty_diff"
6
+ require "minitest/focus"
7
+ require "minitest/moar"
8
+ require "minitest/bisect"
9
+ require "minitest-bonus-assertions"
10
10
 
11
- require 'cartage/minitest'
11
+ require "cartage/minitest"