cartage 2.2 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +99 -80
- data/README.rdoc +13 -7
- data/Rakefile +52 -38
- data/lib/cartage/backport.rb +3 -3
- data/lib/cartage/cli.rb +76 -76
- data/lib/cartage/commands/echo.rb +6 -6
- data/lib/cartage/commands/info.rb +17 -17
- data/lib/cartage/commands/manifest.rb +46 -46
- data/lib/cartage/commands/metadata.rb +2 -2
- data/lib/cartage/commands/pack.rb +6 -6
- data/lib/cartage/config.rb +27 -25
- data/lib/cartage/core.rb +18 -18
- data/lib/cartage/gli_ext.rb +10 -10
- data/lib/cartage/minitest.rb +7 -7
- data/lib/cartage/plugin.rb +10 -9
- data/lib/cartage/plugins/build_tarball.rb +2 -2
- data/lib/cartage/plugins/manifest.rb +85 -85
- data/lib/cartage.rb +67 -67
- data/test/minitest_config.rb +8 -8
- data/test/test_cartage.rb +130 -130
- data/test/test_cartage_build_tarball.rb +22 -22
- data/test/test_cartage_config.rb +27 -27
- data/test/test_cartage_core.rb +36 -36
- data/test/test_cartage_manifest.rb +51 -53
- data/test/test_cartage_plugin.rb +21 -21
- metadata +37 -20
data/lib/cartage.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "pathname"
|
4
|
+
require "json"
|
5
5
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
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 =
|
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,
|
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(
|
47
|
+
Pathname(`git rev-parse --show-cdup`.chomp).expand_path
|
48
48
|
end
|
49
49
|
|
50
50
|
##
|
51
|
-
def root_path=(v)
|
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(
|
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(
|
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)
|
100
|
+
def compression=(value) # :nodoc:
|
101
101
|
case value
|
102
|
-
when :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)
|
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,
|
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,
|
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:
|
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 ||=
|
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 =
|
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(
|
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 + [
|
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(
|
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
|
279
|
+
display "Saving release metadata..."
|
280
280
|
json = JSON.generate(release_metadata)
|
281
281
|
|
282
282
|
if local
|
283
|
-
Pathname(
|
283
|
+
Pathname(".").join("release-metadata.json").write(json)
|
284
284
|
else
|
285
|
-
work_path.join(
|
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,
|
294
|
-
|
295
|
-
when :gzip,
|
296
|
-
|
297
|
-
when :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,
|
306
|
-
|
307
|
-
when :gzip,
|
308
|
-
|
309
|
-
when :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 = [
|
360
|
-
tar_xf_cmd = [
|
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,
|
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(
|
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(
|
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
|
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(
|
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
|
-
|
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
|
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
|
-
|
441
|
+
"tar", "cf", "-", "-C", parent, "-h", "-T", file_list
|
442
442
|
].map(&:to_s)
|
443
443
|
|
444
444
|
tar_xf_cmd = [
|
445
|
-
|
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,
|
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(
|
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(
|
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
|
-
|
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
|
-
|
475
|
+
"git", "show", "#{release_hashref}:#{filename}"
|
476
476
|
]
|
477
477
|
|
478
478
|
IO.popen(command) do |show|
|
479
|
-
work_path.join(filename).open(
|
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
|
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
|
-
|
503
|
+
"tar",
|
504
504
|
"cf#{tar_compression_flag}",
|
505
505
|
dependency_cache,
|
506
|
-
|
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
|
530
|
+
require_relative "cartage/config"
|
data/test/minitest_config.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
gem
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
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
|
11
|
+
require "cartage/minitest"
|