omnibus 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/.travis.yml +3 -11
- data/CHANGELOG.md +50 -0
- data/MAINTAINERS.md +26 -0
- data/README.md +61 -4
- data/appveyor.yml +35 -0
- data/docs/Build Cache.md +28 -3
- data/docs/Building on RHEL.md +1 -1
- data/features/commands/publish.feature +4 -9
- data/features/step_definitions/generator_steps.rb +14 -1
- data/features/support/env.rb +5 -3
- data/lib/omnibus.rb +10 -0
- data/lib/omnibus/build_version.rb +34 -25
- data/lib/omnibus/build_version_dsl.rb +43 -4
- data/lib/omnibus/builder.rb +30 -11
- data/lib/omnibus/changelog.rb +52 -0
- data/lib/omnibus/changelog_printer.rb +77 -0
- data/lib/omnibus/cli.rb +37 -2
- data/lib/omnibus/cli/changelog.rb +149 -0
- data/lib/omnibus/cli/publish.rb +30 -10
- data/lib/omnibus/config.rb +41 -2
- data/lib/omnibus/digestable.rb +6 -1
- data/lib/omnibus/exceptions.rb +15 -1
- data/lib/omnibus/fetcher.rb +78 -34
- data/lib/omnibus/fetchers/git_fetcher.rb +84 -42
- data/lib/omnibus/fetchers/net_fetcher.rb +64 -13
- data/lib/omnibus/fetchers/null_fetcher.rb +8 -1
- data/lib/omnibus/fetchers/path_fetcher.rb +24 -1
- data/lib/omnibus/file_syncer.rb +52 -1
- data/lib/omnibus/generator.rb +22 -21
- data/lib/omnibus/generator_files/.kitchen.yml.erb +8 -12
- data/lib/omnibus/generator_files/Berksfile.erb +4 -4
- data/lib/omnibus/generator_files/Gemfile.erb +3 -3
- data/lib/omnibus/generator_files/README.md.erb +17 -0
- data/lib/omnibus/generator_files/omnibus.rb.erb +6 -0
- data/lib/omnibus/git_repository.rb +43 -0
- data/lib/omnibus/health_check.rb +5 -1
- data/lib/omnibus/manifest.rb +134 -0
- data/lib/omnibus/manifest_diff.rb +88 -0
- data/lib/omnibus/manifest_entry.rb +43 -0
- data/lib/omnibus/metadata.rb +19 -1
- data/lib/omnibus/package.rb +9 -0
- data/lib/omnibus/packagers/base.rb +1 -1
- data/lib/omnibus/packagers/bff.rb +5 -5
- data/lib/omnibus/packagers/deb.rb +11 -4
- data/lib/omnibus/packagers/msi.rb +243 -2
- data/lib/omnibus/packagers/rpm.rb +68 -14
- data/lib/omnibus/packagers/solaris.rb +17 -23
- data/lib/omnibus/project.rb +129 -16
- data/lib/omnibus/publisher.rb +62 -49
- data/lib/omnibus/publishers/artifactory_publisher.rb +96 -5
- data/lib/omnibus/publishers/s3_publisher.rb +20 -25
- data/lib/omnibus/s3_cache.rb +13 -34
- data/lib/omnibus/s3_helpers.rb +119 -0
- data/lib/omnibus/semantic_version.rb +57 -0
- data/lib/omnibus/software.rb +87 -28
- data/lib/omnibus/sugarable.rb +18 -0
- data/lib/omnibus/templating.rb +8 -1
- data/lib/omnibus/version.rb +1 -1
- data/omnibus.gemspec +10 -7
- data/resources/bff/gen.template.erb +1 -1
- data/resources/msi/bundle.wxs.erb +17 -0
- data/resources/msi/localization-en-us.wxl.erb +1 -1
- data/resources/rpm/spec.erb +1 -1
- data/spec/functional/builder_spec.rb +15 -7
- data/spec/functional/fetchers/git_fetcher_spec.rb +44 -12
- data/spec/functional/fetchers/net_fetcher_spec.rb +171 -20
- data/spec/functional/fetchers/path_fetcher_spec.rb +16 -1
- data/spec/functional/file_syncer_spec.rb +58 -5
- data/spec/functional/templating_spec.rb +17 -6
- data/spec/spec_helper.rb +17 -0
- data/spec/support/file_helpers.rb +12 -2
- data/spec/support/git_helpers.rb +23 -18
- data/spec/support/matchers.rb +22 -0
- data/spec/support/output_helpers.rb +29 -0
- data/spec/unit/build_version_dsl_spec.rb +31 -4
- data/spec/unit/build_version_spec.rb +11 -4
- data/spec/unit/builder_spec.rb +33 -0
- data/spec/unit/changelog_spec.rb +55 -0
- data/spec/unit/cleanroom_spec.rb +1 -1
- data/spec/unit/compressors/dmg_spec.rb +3 -3
- data/spec/unit/compressors/tgz_spec.rb +3 -3
- data/spec/unit/config_spec.rb +3 -1
- data/spec/unit/fetcher_spec.rb +35 -0
- data/spec/unit/fetchers/git_fetcher_spec.rb +28 -14
- data/spec/unit/fetchers/net_fetcher_spec.rb +178 -24
- data/spec/unit/fetchers/path_fetcher_spec.rb +8 -7
- data/spec/unit/generator_spec.rb +22 -21
- data/spec/unit/git_repository_spec.rb +60 -0
- data/spec/unit/manifest_diff_spec.rb +75 -0
- data/spec/unit/manifest_spec.rb +116 -0
- data/spec/unit/metadata_spec.rb +11 -0
- data/spec/unit/omnibus_spec.rb +9 -6
- data/spec/unit/package_spec.rb +1 -1
- data/spec/unit/packagers/base_spec.rb +8 -18
- data/spec/unit/packagers/bff_spec.rb +9 -5
- data/spec/unit/packagers/deb_spec.rb +44 -12
- data/spec/unit/packagers/makeself_spec.rb +4 -4
- data/spec/unit/packagers/msi_spec.rb +122 -6
- data/spec/unit/packagers/pkg_spec.rb +3 -3
- data/spec/unit/packagers/rpm_spec.rb +37 -12
- data/spec/unit/project_spec.rb +18 -1
- data/spec/unit/publisher_spec.rb +65 -0
- data/spec/unit/publishers/artifactory_publisher_spec.rb +26 -20
- data/spec/unit/publishers/s3_publisher_spec.rb +14 -30
- data/spec/unit/s3_cacher_spec.rb +1 -1
- data/spec/unit/s3_helpers_spec.rb +32 -0
- data/spec/unit/semantic_version_spec.rb +55 -0
- data/spec/unit/software_spec.rb +112 -4
- metadata +86 -16
data/lib/omnibus/cli/publish.rb
CHANGED
@@ -18,19 +18,27 @@ module Omnibus
|
|
18
18
|
class Command::Publish < Command::Base
|
19
19
|
namespace :publish
|
20
20
|
|
21
|
-
#
|
22
|
-
#
|
21
|
+
# This option is useful for publish packages that were built for a
|
22
|
+
# particular platform/version but tested on other platform/versions.
|
23
23
|
#
|
24
24
|
# For example, one might build on Ubuntu 10.04 and test/publish on
|
25
|
-
# Ubuntu
|
25
|
+
# Ubuntu 10.04, 12.04, and 14.04.
|
26
26
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
|
30
|
-
|
27
|
+
# @example JSON
|
28
|
+
# {
|
29
|
+
# "ubuntu-10.04": [
|
30
|
+
# "ubuntu-10.04",
|
31
|
+
# "ubuntu-12.04",
|
32
|
+
# "ubuntu-14.04"
|
33
|
+
# ]
|
34
|
+
# }
|
35
|
+
#
|
36
|
+
class_option :platform_mappings,
|
37
|
+
desc: 'The optional platform mappings JSON file to publish with',
|
31
38
|
type: :string
|
32
|
-
|
33
|
-
|
39
|
+
|
40
|
+
class_option :version_manifest,
|
41
|
+
desc: 'Path to the version-manifest.json file to publish with',
|
34
42
|
type: :string
|
35
43
|
|
36
44
|
#
|
@@ -43,6 +51,10 @@ module Omnibus
|
|
43
51
|
desc: 'The accessibility of the uploaded packages',
|
44
52
|
enum: %w(public private),
|
45
53
|
default: 'private'
|
54
|
+
method_option :region,
|
55
|
+
type: :string,
|
56
|
+
desc: 'The region in which the bucket is located',
|
57
|
+
default: 'us-east-1'
|
46
58
|
desc 's3 BUCKET PATTERN', 'Publish to an S3 bucket'
|
47
59
|
def s3(bucket, pattern)
|
48
60
|
options[:bucket] = bucket
|
@@ -54,6 +66,10 @@ module Omnibus
|
|
54
66
|
#
|
55
67
|
# $ omnibus publish artifactory libs-omnibus-local pkg/chef*
|
56
68
|
#
|
69
|
+
method_option :build_record,
|
70
|
+
type: :boolean,
|
71
|
+
desc: 'Optionally create an Artifactory build record for the published artifacts',
|
72
|
+
default: true
|
57
73
|
desc 'artifactory REPOSITORY PATTERN', 'Publish to an Artifactory instance'
|
58
74
|
def artifactory(repository, pattern)
|
59
75
|
options[:repository] = repository
|
@@ -68,8 +84,12 @@ module Omnibus
|
|
68
84
|
# @return [void]
|
69
85
|
#
|
70
86
|
def publish(klass, pattern, options)
|
87
|
+
if options[:platform_mappings]
|
88
|
+
options[:platform_mappings] = JSON.parse(File.read(File.expand_path(options[:platform_mappings])))
|
89
|
+
end
|
90
|
+
|
71
91
|
klass.publish(pattern, options) do |package|
|
72
|
-
say("
|
92
|
+
say("Published '#{package.name}' for #{package.metadata[:platform]}-#{package.metadata[:platform_version]}", :green)
|
73
93
|
end
|
74
94
|
end
|
75
95
|
end
|
data/lib/omnibus/config.rb
CHANGED
@@ -289,6 +289,14 @@ module Omnibus
|
|
289
289
|
raise MissingRequiredAttribute.new(self, :s3_secret_key, "'EFGH5678'")
|
290
290
|
end
|
291
291
|
|
292
|
+
# The region of the S3 bucket you want to cache software artifacts in.
|
293
|
+
# Defaults to 'us-east-1'
|
294
|
+
#
|
295
|
+
# @return [String]
|
296
|
+
default(:s3_region) do
|
297
|
+
'us-east-1'
|
298
|
+
end
|
299
|
+
|
292
300
|
# --------------------------------------------------
|
293
301
|
# @!endgroup
|
294
302
|
#
|
@@ -432,10 +440,36 @@ module Omnibus
|
|
432
440
|
['omnibus-software']
|
433
441
|
end
|
434
442
|
|
435
|
-
#
|
443
|
+
# Solaris linker mapfile to use, if needed
|
444
|
+
# see http://docs.oracle.com/cd/E23824_01/html/819-0690/chapter5-1.html
|
445
|
+
# Path is relative to the 'files' directory in your omnibus project
|
446
|
+
#
|
447
|
+
# For example:
|
448
|
+
#
|
449
|
+
# /PATH/files/my_map_file
|
436
450
|
#
|
437
451
|
# @return [String, nil]
|
438
|
-
default(:
|
452
|
+
default(:solaris_linker_mapfile, "files/mapfiles/solaris")
|
453
|
+
|
454
|
+
# Architecture to target when building on windows. This option
|
455
|
+
# should affect the bit-ness of Ruby and DevKit used, the platform of
|
456
|
+
# any MSIs generated and package dlls being downloaded.
|
457
|
+
#
|
458
|
+
# See the windows_arch_i386? software definition dsl
|
459
|
+
# methods.
|
460
|
+
#
|
461
|
+
# @return [:x86, :x64]
|
462
|
+
default(:windows_arch) do
|
463
|
+
if Ohai['kernel']['machine'] == 'x86_64'
|
464
|
+
Omnibus.logger.deprecated('Config') do
|
465
|
+
"windows_arch is defaulting to :x86. In Omnibus 5, it will " \
|
466
|
+
"default to :x64 if the machine architecture is x86_64. " \
|
467
|
+
"If you would like to continue building 32 bit packages, please "\
|
468
|
+
"manually set windows_arch in your omnibus.rb file to :x86."
|
469
|
+
end
|
470
|
+
end
|
471
|
+
:x86
|
472
|
+
end
|
439
473
|
|
440
474
|
# --------------------------------------------------
|
441
475
|
# @!endgroup
|
@@ -488,6 +522,11 @@ module Omnibus
|
|
488
522
|
# @return [Integer]
|
489
523
|
default(:fetcher_read_timeout, 60)
|
490
524
|
|
525
|
+
# The number of retries before marking a download as failed
|
526
|
+
#
|
527
|
+
# @return [Integer]
|
528
|
+
default(:fetcher_retries, 5)
|
529
|
+
|
491
530
|
# --------------------------------------------------
|
492
531
|
# @!endgroup
|
493
532
|
#
|
data/lib/omnibus/digestable.rb
CHANGED
@@ -16,9 +16,14 @@
|
|
16
16
|
|
17
17
|
require 'openssl'
|
18
18
|
require 'pathname'
|
19
|
+
require 'omnibus/logging'
|
19
20
|
|
20
21
|
module Omnibus
|
21
22
|
module Digestable
|
23
|
+
|
24
|
+
def self.included(other)
|
25
|
+
other.send(:include, Logging)
|
26
|
+
end
|
22
27
|
#
|
23
28
|
# Calculate the digest of the file at the given path. Files are read in
|
24
29
|
# binary chunks to prevent Ruby from exploding.
|
@@ -63,7 +68,7 @@ module Omnibus
|
|
63
68
|
#
|
64
69
|
def digest_directory(path, type = :md5)
|
65
70
|
digest = digest_from_type(type)
|
66
|
-
|
71
|
+
log.info(log_key) { "Digesting #{path} with #{type}" }
|
67
72
|
FileSyncer.glob("#{path}/**/*").each do |filename|
|
68
73
|
# Calculate the filename relative to the given path. Since directories
|
69
74
|
# are SHAed according to their filepath, two difference directories on
|
data/lib/omnibus/exceptions.rb
CHANGED
@@ -87,7 +87,7 @@ EOH
|
|
87
87
|
|
88
88
|
def to_s
|
89
89
|
<<-EOH
|
90
|
-
Attempting to evaluate the template `#{@
|
90
|
+
Attempting to evaluate the template `#{@template}', but it was not found at any of
|
91
91
|
the following locations:
|
92
92
|
|
93
93
|
#{@search_paths.map { |path| " #{path}" }.join("\n")}
|
@@ -309,4 +309,18 @@ Could not resolve `#{ref}' to a valid git SHA-1.
|
|
309
309
|
EOH
|
310
310
|
end
|
311
311
|
end
|
312
|
+
|
313
|
+
class InvalidVersion < Error
|
314
|
+
def initialize(version)
|
315
|
+
super <<-EOF
|
316
|
+
'#{version}' could not be parsed as a valid version.
|
317
|
+
EOF
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
class FailedToTimestampMSI < Error
|
322
|
+
def initialize
|
323
|
+
super("Failed to add timestamp to MSI.")
|
324
|
+
end
|
325
|
+
end
|
312
326
|
end
|
data/lib/omnibus/fetcher.rb
CHANGED
@@ -19,22 +19,65 @@ module Omnibus
|
|
19
19
|
include Digestable
|
20
20
|
include Logging
|
21
21
|
include Util
|
22
|
+
extend Util
|
22
23
|
|
23
24
|
#
|
24
|
-
# The software
|
25
|
+
# The name of the software this fetcher shall fetch
|
25
26
|
#
|
26
|
-
# @return [
|
27
|
+
# @return [String]
|
28
|
+
#
|
29
|
+
attr_reader :name
|
30
|
+
|
31
|
+
#
|
32
|
+
# The source for this fetcher.
|
33
|
+
#
|
34
|
+
# @return [Hash]
|
35
|
+
#
|
36
|
+
attr_reader :source
|
37
|
+
|
38
|
+
#
|
39
|
+
# The exact upstream version that a fetcher should fetch.
|
40
|
+
#
|
41
|
+
# @return [String]
|
42
|
+
#
|
43
|
+
# For sources that allow aliases (branch name, tags, etc). Users
|
44
|
+
# should use the class method resolve_version to determine this
|
45
|
+
# before constructing a fetcher.
|
46
|
+
attr_reader :resolved_version
|
47
|
+
|
48
|
+
#
|
49
|
+
# The upstream version as described before resolution.
|
50
|
+
#
|
51
|
+
# @return [String]
|
52
|
+
#
|
53
|
+
# This will usually be the same as +resolved_version+ but may
|
54
|
+
# refer toa remote ref name or tag for a source such as git.
|
55
|
+
attr_reader :described_version
|
56
|
+
|
27
57
|
#
|
28
|
-
|
58
|
+
# The path where extracted software should live.
|
59
|
+
#
|
60
|
+
# @return [String]
|
61
|
+
#
|
62
|
+
attr_reader :project_dir
|
63
|
+
attr_reader :build_dir
|
64
|
+
|
29
65
|
|
30
66
|
#
|
31
67
|
# Create a new Fetcher object from the given software.
|
32
68
|
#
|
33
69
|
# @param [Software] software
|
34
|
-
# the software to create this fetcher
|
35
70
|
#
|
36
|
-
|
37
|
-
|
71
|
+
# To preserve the original interface, this still takes a software-like
|
72
|
+
# argument, but to avoid coupling with the software object, we pull out
|
73
|
+
# what we need and don't touch it again.
|
74
|
+
def initialize(manifest_entry, project_dir, build_dir)
|
75
|
+
@name = manifest_entry.name
|
76
|
+
@source = manifest_entry.locked_source
|
77
|
+
@resolved_version = manifest_entry.locked_version
|
78
|
+
@described_version = manifest_entry.described_version
|
79
|
+
@project_dir = project_dir
|
80
|
+
@build_dir = build_dir
|
38
81
|
end
|
39
82
|
|
40
83
|
#
|
@@ -83,37 +126,20 @@ module Omnibus
|
|
83
126
|
# @!endgroup
|
84
127
|
# --------------------------------------------------
|
85
128
|
|
86
|
-
|
87
|
-
|
88
|
-
#
|
89
|
-
# The "source" for this software, with applied overrides.
|
90
|
-
#
|
91
|
-
# @return [Hash]
|
92
|
-
#
|
93
|
-
def source
|
94
|
-
software.source
|
129
|
+
def fetcher
|
130
|
+
self
|
95
131
|
end
|
96
132
|
|
97
133
|
#
|
98
|
-
#
|
99
|
-
#
|
100
|
-
# @see Software#project_dir
|
101
|
-
#
|
102
|
-
# @return [String]
|
103
|
-
#
|
104
|
-
def project_dir
|
105
|
-
software.project_dir
|
106
|
-
end
|
107
|
-
|
108
|
-
#
|
109
|
-
# The version for this sfotware, with applied overrides.
|
110
|
-
#
|
111
|
-
# @return [String]
|
134
|
+
# All fetchers should prefer resolved_version to version
|
135
|
+
# this is provided for compatibility.
|
112
136
|
#
|
113
137
|
def version
|
114
|
-
|
138
|
+
resolved_version
|
115
139
|
end
|
116
140
|
|
141
|
+
private
|
142
|
+
|
117
143
|
#
|
118
144
|
# Override the +log_key+ for this fetcher to include the name of the
|
119
145
|
# software during the fetch.
|
@@ -121,10 +147,9 @@ module Omnibus
|
|
121
147
|
# @return [String]
|
122
148
|
#
|
123
149
|
def log_key
|
124
|
-
@log_key ||= "#{super}: #{
|
150
|
+
@log_key ||= "#{super}: #{name}"
|
125
151
|
end
|
126
152
|
|
127
|
-
|
128
153
|
#
|
129
154
|
# Idempotently create the required directories for building/downloading.
|
130
155
|
# Fetchers should call this method before performing any operations that
|
@@ -136,11 +161,30 @@ module Omnibus
|
|
136
161
|
[
|
137
162
|
Config.cache_dir,
|
138
163
|
Config.source_dir,
|
139
|
-
|
140
|
-
|
164
|
+
build_dir,
|
165
|
+
project_dir,
|
141
166
|
].each do |directory|
|
142
167
|
FileUtils.mkdir_p(directory) unless File.directory?(directory)
|
143
168
|
end
|
144
169
|
end
|
170
|
+
|
171
|
+
# Class Methods
|
172
|
+
def self.resolve_version(version, source)
|
173
|
+
fetcher_class_for_source(source).resolve_version(version, source)
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.fetcher_class_for_source(source)
|
177
|
+
if source
|
178
|
+
if source[:url]
|
179
|
+
NetFetcher
|
180
|
+
elsif source[:git]
|
181
|
+
GitFetcher
|
182
|
+
elsif source[:path]
|
183
|
+
PathFetcher
|
184
|
+
end
|
185
|
+
else
|
186
|
+
NullFetcher
|
187
|
+
end
|
188
|
+
end
|
145
189
|
end
|
146
190
|
end
|
@@ -23,7 +23,7 @@ module Omnibus
|
|
23
23
|
# @return [true, false]
|
24
24
|
#
|
25
25
|
def fetch_required?
|
26
|
-
!(cloned? && same_revision?)
|
26
|
+
!(cloned? && same_revision?(resolved_version))
|
27
27
|
end
|
28
28
|
|
29
29
|
#
|
@@ -59,12 +59,12 @@ module Omnibus
|
|
59
59
|
#
|
60
60
|
def fetch
|
61
61
|
log.info(log_key) { "Fetching from `#{source_url}'" }
|
62
|
-
|
63
62
|
create_required_directories
|
64
63
|
|
65
64
|
if cloned?
|
66
|
-
git_fetch unless same_revision?
|
65
|
+
git_fetch unless same_revision?(resolved_version)
|
67
66
|
else
|
67
|
+
force_recreate_project_dir! unless dir_empty?(project_dir)
|
68
68
|
git_clone
|
69
69
|
git_checkout
|
70
70
|
end
|
@@ -91,6 +91,33 @@ module Omnibus
|
|
91
91
|
source[:git]
|
92
92
|
end
|
93
93
|
|
94
|
+
#
|
95
|
+
# Determine if submodules should be cloned.
|
96
|
+
#
|
97
|
+
# @return [true, false]
|
98
|
+
#
|
99
|
+
def clone_submodules?
|
100
|
+
source[:submodules] || false
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Determine if a directory is empty
|
105
|
+
#
|
106
|
+
# @return [true, false]
|
107
|
+
#
|
108
|
+
def dir_empty?(dir)
|
109
|
+
Dir.entries(dir).reject {|d| ['.', '..'].include?(d) }.empty?
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Forcibly remove and recreate the project directory
|
114
|
+
#
|
115
|
+
def force_recreate_project_dir!
|
116
|
+
log.warn(log_key) { "Removing existing directory #{project_dir} before cloning" }
|
117
|
+
FileUtils.rm_rf(project_dir)
|
118
|
+
Dir.mkdir(project_dir)
|
119
|
+
end
|
120
|
+
|
94
121
|
#
|
95
122
|
# Determine if the clone exists.
|
96
123
|
#
|
@@ -106,27 +133,28 @@ module Omnibus
|
|
106
133
|
# @return [void]
|
107
134
|
#
|
108
135
|
def git_clone
|
109
|
-
git("clone #{source_url} .")
|
136
|
+
git("clone#{" --recursive" if clone_submodules?} #{source_url} .")
|
110
137
|
end
|
111
138
|
|
112
139
|
#
|
113
|
-
# Checkout the +
|
140
|
+
# Checkout the +resolved_version+.
|
114
141
|
#
|
115
142
|
# @return [void]
|
116
143
|
#
|
117
144
|
def git_checkout
|
118
|
-
git("
|
119
|
-
git("checkout #{target_revision}")
|
145
|
+
git("checkout #{resolved_version}")
|
120
146
|
end
|
121
147
|
|
122
148
|
#
|
123
|
-
# Fetch the remote tags and refs, and reset to +
|
149
|
+
# Fetch the remote tags and refs, and reset to +resolved_version+.
|
124
150
|
#
|
125
151
|
# @return [void]
|
126
152
|
#
|
127
153
|
def git_fetch
|
128
|
-
|
129
|
-
|
154
|
+
fetch_cmd = "fetch #{source_url} #{described_version}"
|
155
|
+
fetch_cmd << ' --recurse-submodules=on-demand' if clone_submodules?
|
156
|
+
git(fetch_cmd)
|
157
|
+
git("reset --hard #{resolved_version}")
|
130
158
|
end
|
131
159
|
|
132
160
|
#
|
@@ -135,31 +163,55 @@ module Omnibus
|
|
135
163
|
# @return [String]
|
136
164
|
#
|
137
165
|
def current_revision
|
138
|
-
|
166
|
+
git('rev-parse HEAD').stdout.strip
|
139
167
|
rescue CommandFailed
|
140
168
|
nil
|
141
169
|
end
|
142
170
|
|
143
171
|
#
|
144
|
-
#
|
172
|
+
# Determine if the given revision matches the current revision.
|
145
173
|
#
|
146
|
-
# @return [
|
174
|
+
# @return [true, false]
|
147
175
|
#
|
148
|
-
def
|
149
|
-
|
150
|
-
version
|
151
|
-
else
|
152
|
-
revision_from_remote_reference(version)
|
153
|
-
end
|
176
|
+
def same_revision?(rev=resolved_version)
|
177
|
+
current_revision == rev
|
154
178
|
end
|
155
179
|
|
156
180
|
#
|
157
|
-
#
|
181
|
+
# Execute the given git command, inside the +project_dir+.
|
158
182
|
#
|
159
|
-
# @
|
183
|
+
# @see Util#shellout!
|
184
|
+
#
|
185
|
+
# @return [Mixlib::ShellOut]
|
186
|
+
# the shellout object
|
160
187
|
#
|
161
|
-
def
|
162
|
-
|
188
|
+
def git(command)
|
189
|
+
shellout!("git #{command}", cwd: project_dir)
|
190
|
+
end
|
191
|
+
|
192
|
+
# Class methods
|
193
|
+
public
|
194
|
+
|
195
|
+
# Return the SHA1 corresponding to a ref as determined by the remote source.
|
196
|
+
#
|
197
|
+
# @return [String]
|
198
|
+
#
|
199
|
+
def self.resolve_version(ref, source)
|
200
|
+
if sha_hash?(ref)
|
201
|
+
# A git server negotiates in terms of refs during the info-refs phase
|
202
|
+
# of a fetch. During upload-pack, the client is not allowed to specify
|
203
|
+
# any sha1s in the "wants" unless the server has publicized them during
|
204
|
+
# info-refs. Hence, the server is allowed to drop requests to fetch
|
205
|
+
# particular sha1s, even if it is an otherwise reachable commit object.
|
206
|
+
# Only when the service is specifically configured with
|
207
|
+
# uploadpack.allowReachableSHA1InWant is there any guarantee that it
|
208
|
+
# considers "naked" wants.
|
209
|
+
log.warn(log_key) { 'git fetch on a sha1 is not guaranteed to work' }
|
210
|
+
log.warn(log_key) { "Specify a ref name instead of #{ref} on #{source}" }
|
211
|
+
ref
|
212
|
+
else
|
213
|
+
revision_from_remote_reference(ref, source)
|
214
|
+
end
|
163
215
|
end
|
164
216
|
|
165
217
|
#
|
@@ -167,22 +219,24 @@ module Omnibus
|
|
167
219
|
#
|
168
220
|
# @return [true, false]
|
169
221
|
#
|
170
|
-
def sha_hash?(rev)
|
171
|
-
rev =~ /^[0-9a-f]{4,40}$/
|
222
|
+
def self.sha_hash?(rev)
|
223
|
+
rev =~ /^[0-9a-f]{4,40}$/i
|
172
224
|
end
|
173
225
|
|
174
226
|
#
|
175
|
-
# Return the SHA corresponding to ref.
|
176
|
-
#
|
227
|
+
# Return the SHA corresponding to ref.
|
228
|
+
#
|
229
|
+
# If ref is an annotated tag, return the SHA that was tagged not the SHA of
|
230
|
+
# the tag itself.
|
177
231
|
#
|
178
232
|
# @return [String]
|
179
233
|
#
|
180
|
-
def revision_from_remote_reference(ref)
|
234
|
+
def self.revision_from_remote_reference(ref, source)
|
181
235
|
# execute `git ls-remote` the trailing '*' does globbing. This
|
182
236
|
# allows us to return the SHA of the tagged commit for annotated
|
183
237
|
# tags. We take care to only return exact matches in
|
184
238
|
# process_remote_list.
|
185
|
-
remote_list =
|
239
|
+
remote_list = shellout!("git ls-remote \"#{source[:git]}\" #{ref}*").stdout
|
186
240
|
commit_ref = dereference_annotated_tag(remote_list, ref)
|
187
241
|
|
188
242
|
unless commit_ref
|
@@ -210,7 +264,7 @@ module Omnibus
|
|
210
264
|
#
|
211
265
|
# @return [String]
|
212
266
|
#
|
213
|
-
def dereference_annotated_tag(remote_list, ref)
|
267
|
+
def self.dereference_annotated_tag(remote_list, ref)
|
214
268
|
# We'll return the SHA corresponding to the ^{} which is the
|
215
269
|
# commit pointed to by an annotated tag. If no such commit
|
216
270
|
# exists (not an annotated tag) then we return the SHA of the
|
@@ -231,17 +285,5 @@ module Omnibus
|
|
231
285
|
end
|
232
286
|
end
|
233
287
|
end
|
234
|
-
|
235
|
-
#
|
236
|
-
# Execute the given git command, inside the +project_dir+.
|
237
|
-
#
|
238
|
-
# @see Util#shellout!
|
239
|
-
#
|
240
|
-
# @return [Mixlib::ShellOut]
|
241
|
-
# the shellout object
|
242
|
-
#
|
243
|
-
def git(command)
|
244
|
-
shellout!("git #{command}", cwd: project_dir)
|
245
|
-
end
|
246
288
|
end
|
247
289
|
end
|