vanagon 0.15.3 → 0.15.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 507a58974dda3aa6cf97fe0d8a8e2f1329ce1662
4
- data.tar.gz: 6e5308dd84de5909fe9620838977d1f16814269d
3
+ metadata.gz: 3744e8372acb3ce656a75a360273b489ad3a5607
4
+ data.tar.gz: 61d3c29607c0d2f6a70317a6220dac9f766f8117
5
5
  SHA512:
6
- metadata.gz: 7d22c6b298644338b4d4e1164749d40620f59425d23179cf8a4d4d0c66eb45ae40cce5f8bc4cefa96488e172a4ddc5d92acdf5f4073bd38e18a4eacb2ac433a5
7
- data.tar.gz: 7a7980280d44cd994ff4b7c8e41ac337240e9a3762bfd3409ccf1dbdbf10c5380fb056a0f940f1e84bf54c3df69378b0578421fa4d4a8d1c474bed8f0363cb6a
6
+ metadata.gz: e8b86569bdea4ffd7a45299cfefe30aff38c9dafe55af28ba3d05d8aa6ceb95abab3fc83c013ba0c62288f01a1f01ad8332bd5950831036a797ced98b17370b6
7
+ data.tar.gz: b3215529d393fdfd7af5f46ec116c90b79996f71b30654a87cf6caabd1ae790e8ae46d371be0dbe8394fe634364856ff7e694cf6ba7397cdd39aa84b91f1ebb6
@@ -0,0 +1,36 @@
1
+ require 'git'
2
+
3
+ module LibRevList
4
+ def rev_list(committish = nil, opts = {})
5
+ arr_opts = []
6
+
7
+ opts.each do |k, v|
8
+ # allow for passing, say, :max-count or :max_count
9
+ k = k.to_s
10
+ k.tr!('_', '-')
11
+ if v && v.to_s.downcase == 'true'
12
+ arr_opts << "--#{k}"
13
+ elsif v
14
+ arr_opts << "--#{k}=#{v}"
15
+ end
16
+ end
17
+
18
+ arr_opts << committish if committish
19
+
20
+ command('rev-list', arr_opts)
21
+ end
22
+ end
23
+
24
+ module Git
25
+ class Lib
26
+ include LibRevList
27
+ end
28
+ end
29
+
30
+ module Git
31
+ class Base
32
+ def rev_list(committish = nil, opts = {})
33
+ lib.rev_list(committish, opts)
34
+ end
35
+ end
36
+ end
@@ -5,6 +5,7 @@ require 'vanagon/component/source/rewrite'
5
5
 
6
6
  class Vanagon
7
7
  class Component
8
+ include Vanagon::Utilities
8
9
  # @!attribute [r] files
9
10
  # @return [Set] the list of files marked for installation
10
11
 
@@ -326,6 +327,9 @@ class Vanagon
326
327
  )
327
328
  src.fetch
328
329
  src.verify
330
+ if source.erb
331
+ erb_file(src.file, File.join(File.dirname(src.file), File.basename(src.file, ".erb")), true)
332
+ end
329
333
  # set src.file to only be populated with the basename instead of entire file path
330
334
  src.file = File.basename(src.url)
331
335
  extract_with << src.extract(platform.tar) if src.respond_to? :extract
@@ -368,6 +368,7 @@ class Vanagon
368
368
  # @param [Hash] options optional keyword arguments used to instatiate a new source
369
369
  # @option opts [String] :sum
370
370
  # @option opts [String] :ref
371
+ # @option opts [Bool] :erb set to 'true' to specify that the source file should be translated by erb
371
372
  def add_source(uri, **options)
372
373
  @component.sources << OpenStruct.new(options.merge({ url: uri }))
373
374
  end
@@ -116,14 +116,20 @@ class Vanagon
116
116
  end
117
117
  end
118
118
 
119
- def run # rubocop:disable Metrics/AbcSize
119
+ def run # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
120
120
  # Simple sanity check for the project
121
121
  if @project.version.nil? or @project.version.empty?
122
122
  raise Vanagon::Error, "Project requires a version set, all is lost."
123
123
  end
124
124
 
125
- @engine.startup(workdir)
125
+ # if no_packaging has been set in the project, don't execute the
126
+ # whole makefile. Instead just perform the installation.
127
+ make_target = ''
128
+ if @project.no_packaging
129
+ make_target = @project.name + '-project'
130
+ end
126
131
 
132
+ @engine.startup(workdir)
127
133
  warn "Target is #{@engine.target}"
128
134
  Vanagon::Utilities.retry_with_timeout(retry_count, timeout) do
129
135
  install_build_dependencies
@@ -132,11 +138,12 @@ class Vanagon
132
138
 
133
139
  @project.make_makefile(workdir)
134
140
  @project.make_bill_of_materials(workdir)
135
- @project.generate_packaging_artifacts(workdir)
141
+ # Don't generate packaging artifacts if no_packaging is set
142
+ @project.generate_packaging_artifacts(workdir) unless @project.no_packaging
136
143
  @project.save_manifest_json
137
144
  @engine.ship_workdir(workdir)
138
- @engine.dispatch("(cd #{@engine.remote_workdir}; #{@platform.make})")
139
- @engine.retrieve_built_artifact
145
+ @engine.dispatch("(cd #{@engine.remote_workdir}; #{@platform.make} #{make_target})")
146
+ @engine.retrieve_built_artifact(@project.artifacts_to_fetch, @project.no_packaging)
140
147
 
141
148
  if %i[never on-failure].include? @preserve
142
149
  @engine.teardown
@@ -73,9 +73,15 @@ class Vanagon
73
73
  Vanagon::Utilities.rsync_to("#{workdir}/*", "#{@target_user}@#{@target}", @remote_workdir, @platform.ssh_port)
74
74
  end
75
75
 
76
- def retrieve_built_artifact
77
- FileUtils.mkdir_p("output")
78
- Vanagon::Utilities.rsync_from("#{@remote_workdir}/output/*", "#{@target_user}@#{@target}", "output/", @platform.ssh_port)
76
+ def retrieve_built_artifact(artifacts_to_fetch, no_packaging)
77
+ output_path = 'output/'
78
+ FileUtils.mkdir_p(output_path)
79
+ unless no_packaging
80
+ artifacts_to_fetch << "#{@remote_workdir}/output/*"
81
+ end
82
+ artifacts_to_fetch.each do |path|
83
+ Vanagon::Utilities.rsync_from(path, "#{@target_user}@#{@target}", output_path, @platform.ssh_port)
84
+ end
79
85
  end
80
86
 
81
87
  # Ensures that the platform defines the attributes that the engine needs to function.
@@ -90,6 +90,17 @@ class Vanagon
90
90
  # Should we generate platform-specific packages (rpm, deb, dmg, msi, etc)
91
91
  attr_accessor :generate_packages
92
92
 
93
+ # Additional File(s) to retrieve from the system after the installation
94
+ # steps are all complete.
95
+ attr_accessor :artifacts_to_fetch
96
+
97
+ # Specify that the project should not perform the packaging steps in vanagon
98
+ # and instead just stop after installation.
99
+ #
100
+ # Useful alongside fetch_artifact when you don't need vanagon's packaging system and
101
+ # you just want to perform installation and pull down a file.
102
+ attr_accessor :no_packaging
103
+
93
104
  # Loads a given project from the configdir
94
105
  #
95
106
  # @param name [String] the name of the project
@@ -134,6 +145,8 @@ class Vanagon
134
145
  @source_artifacts = false
135
146
  @compiled_archive = false
136
147
  @generate_packages = true
148
+ @no_packaging = false
149
+ @artifacts_to_fetch = []
137
150
  end
138
151
 
139
152
  # Magic getter to retrieve settings in the project
@@ -2,6 +2,7 @@ require 'vanagon/project'
2
2
  require 'vanagon/utilities'
3
3
  require 'vanagon/component/source'
4
4
  require 'set'
5
+ require 'git/rev_list'
5
6
 
6
7
  class Vanagon
7
8
  class Project
@@ -171,6 +172,18 @@ class Vanagon
171
172
  @project.compiled_archive = archive
172
173
  end
173
174
 
175
+ # Sets the release for the project to the number of commits since the
176
+ # last tag. Requires that a git tag be present
177
+ # and reachable from the current commit in that repository.
178
+ #
179
+ def release_from_git
180
+ repo_object = Git.open(File.expand_path("..", Vanagon::Driver.configdir))
181
+ last_tag = repo_object.describe('HEAD', { :abbrev => 0 })
182
+ release(repo_object.rev_list("#{last_tag}..HEAD", { :count => true }))
183
+ rescue Git::GitExecuteError
184
+ warn "Directory '#{dirname}' cannot be versioned by git. Maybe it hasn't been tagged yet?"
185
+ end
186
+
174
187
  # Sets the version for the project based on a git describe of the
175
188
  # directory that holds the configs. Requires that a git tag be present
176
189
  # and reachable from the current commit in that repository.
@@ -317,6 +330,20 @@ class Vanagon
317
330
  platform = @project.platform
318
331
  platform.package_override(self._project, var)
319
332
  end
333
+
334
+ # Set additional artifacts to fetch from the build
335
+ #
336
+ # @param [String] path to artifact to fetch from builder
337
+ def fetch_artifact(path)
338
+ @project.artifacts_to_fetch << path
339
+ end
340
+
341
+ # Set to true to skip packaging steps during the vanagon build
342
+ #
343
+ # @param [Boolean] var whether or not execute packaging steps during build
344
+ def no_packaging(var)
345
+ @project.no_packaging = var
346
+ end
320
347
  end
321
348
  end
322
349
  end
File without changes
@@ -0,0 +1,26 @@
1
+ require 'git/rev_list'
2
+ include LibRevList
3
+
4
+ describe 'Git::LibRevList' do
5
+ describe '#rev_list' do
6
+ it 'calls command' do
7
+ expect(LibRevList).to receive(:command).with('rev-list', [])
8
+ LibRevList.rev_list
9
+ end
10
+
11
+ it 'calls command with commitish' do
12
+ expect(LibRevList).to receive(:command).with('rev-list', ['HEAD'])
13
+ LibRevList.rev_list('HEAD')
14
+ end
15
+
16
+ it 'calls command with commitish and a boolean option' do
17
+ expect(LibRevList).to receive(:command).with('rev-list', ['--count', 'HEAD'])
18
+ LibRevList.rev_list('HEAD', { :count => true })
19
+ end
20
+
21
+ it 'calls command with commitish and an option that uses a param' do
22
+ expect(LibRevList).to receive(:command).with('rev-list', ['--max-age=200', 'HEAD'])
23
+ LibRevList.rev_list('HEAD', { :max_age => 200 })
24
+ end
25
+ end
26
+ end
@@ -102,6 +102,7 @@ describe "Vanagon::Component" do
102
102
  @workdir = Dir.mktmpdir
103
103
  @file_name = 'fake_file.txt'
104
104
  @fake_file = "file://spec/fixtures/files/#{@file_name}"
105
+ @fake_erb_file = "file://spec/fixtures/files/#{@file_name}.erb"
105
106
  @fake_dir = 'fake_dir'
106
107
  @fake_tar = "file://spec/fixtures/files/#{@fake_dir}.tar.gz"
107
108
  end
@@ -142,5 +143,54 @@ describe "Vanagon::Component" do
142
143
  expect(File.exist?(File.join(@workdir, "#{@fake_dir}.tar.gz"))).to be true
143
144
  expect(subject.extract_with.join(" && ")).to match "#{@fake_dir}.tar.gz"
144
145
  end
146
+
147
+ it "Performs an erb translation when erb: is true" do
148
+ # Initialize a new instance of Vanagon::Component and define a
149
+ # new secondary source that's *compressed*. We can now reason about
150
+ # this instance and test behavior for retrieving secondary sources.
151
+ plat = Vanagon::Platform::DSL.new('el-5-x86_64')
152
+ plat.instance_eval("platform 'el-5-x86_64' do |plat| end")
153
+ @platform = plat._platform
154
+
155
+ comp = Vanagon::Component::DSL.new('build-dir-test', {}, @platform)
156
+ comp.add_source @fake_erb_file, erb: true
157
+ subject = comp._component
158
+
159
+ file_path = File.join(@workdir, File.basename(@fake_erb_file))
160
+ expect(subject).to receive(:erb_file).with(Pathname.new(file_path), file_path.gsub('.erb', ''), true)
161
+ subject.get_sources(@workdir)
162
+ end
163
+
164
+ it "Does not perform an erb transformation when erb: is false" do
165
+ # Initialize a new instance of Vanagon::Component and define a
166
+ # new secondary source that's *compressed*. We can now reason about
167
+ # this instance and test behavior for retrieving secondary sources.
168
+ plat = Vanagon::Platform::DSL.new('el-5-x86_64')
169
+ plat.instance_eval("platform 'el-5-x86_64' do |plat| end")
170
+ @platform = plat._platform
171
+
172
+ comp = Vanagon::Component::DSL.new('build-dir-test', {}, @platform)
173
+ comp.add_source @fake_file, erb: false
174
+ subject = comp._component
175
+
176
+ expect(subject).to_not receive(:erb_file)
177
+ subject.get_sources(@workdir)
178
+ end
179
+
180
+ it "Does not perform an erb transformation when erb: is nil (not set)" do
181
+ # Initialize a new instance of Vanagon::Component and define a
182
+ # new secondary source that's *compressed*. We can now reason about
183
+ # this instance and test behavior for retrieving secondary sources.
184
+ plat = Vanagon::Platform::DSL.new('el-5-x86_64')
185
+ plat.instance_eval("platform 'el-5-x86_64' do |plat| end")
186
+ @platform = plat._platform
187
+
188
+ comp = Vanagon::Component::DSL.new('build-dir-test', {}, @platform)
189
+ comp.add_source @fake_file
190
+ subject = comp._component
191
+
192
+ expect(subject).to_not receive(:erb_file)
193
+ subject.get_sources(@workdir)
194
+ end
145
195
  end
146
196
  end
@@ -37,4 +37,35 @@ describe 'Vanagon::Engine::Base' do
37
37
  expect(Vanagon::Engine::Base.new(platform).validate_platform).to be(true)
38
38
  end
39
39
  end
40
+
41
+ describe "#retrieve_built_artifact" do
42
+ it 'creates a new output dir' do
43
+ base = Vanagon::Engine::Base.new(platform)
44
+ allow(Vanagon::Utilities).to receive(:rsync_from)
45
+ expect(FileUtils).to receive(:mkdir_p)
46
+ base.retrieve_built_artifact([], false)
47
+ end
48
+
49
+ it 'rsync uses normal output dir when no_package param is false' do
50
+ base = Vanagon::Engine::Base.new(platform, 'abcd')
51
+ allow(FileUtils).to receive(:mkdir_p)
52
+ expect(Vanagon::Utilities).to receive(:rsync_from).with('/output/*', 'root@abcd', 'output/', 22)
53
+ base.retrieve_built_artifact([], false)
54
+ end
55
+
56
+ it 'rsync only contents of parameter if no_package is true' do
57
+ base = Vanagon::Engine::Base.new(platform, 'abcd')
58
+ allow(FileUtils).to receive(:mkdir_p)
59
+ expect(Vanagon::Utilities).to receive(:rsync_from).with('foo/bar/baz.file', 'root@abcd', 'output/', 22)
60
+ base.retrieve_built_artifact(['foo/bar/baz.file'], true)
61
+ end
62
+
63
+ it 'rsync only contents of parameter with multiple entries if no_package param is true' do
64
+ base = Vanagon::Engine::Base.new(platform, 'abcd')
65
+ allow(FileUtils).to receive(:mkdir_p)
66
+ expect(Vanagon::Utilities).to receive(:rsync_from).with('foo/bar/baz.file', 'root@abcd', 'output/', 22)
67
+ expect(Vanagon::Utilities).to receive(:rsync_from).with('foo/foobar/foobarbaz.file', 'root@abcd', 'output/', 22)
68
+ base.retrieve_built_artifact(['foo/bar/baz.file', 'foo/foobar/foobarbaz.file'], true)
69
+ end
70
+ end
40
71
  end
@@ -53,6 +53,35 @@ end" }
53
53
  end
54
54
  end
55
55
 
56
+ describe '#release_from_git' do
57
+ it 'sets the release based on commits since last tag' do
58
+ repo = double
59
+ tag = double
60
+ log = double
61
+ diff = double
62
+ expect(Vanagon::Driver).to receive(:configdir).and_return(configdir)
63
+ proj = Vanagon::Project::DSL.new('test-fixture', {})
64
+ proj.instance_eval(project_block)
65
+ repo = double("repo")
66
+ expect(::Git)
67
+ .to receive(:open)
68
+ .and_return(repo)
69
+
70
+
71
+ expect(repo)
72
+ .to receive(:describe)
73
+ .and_return('1.2.3')
74
+
75
+ expect(repo)
76
+ .to receive(:rev_list)
77
+ .with('1.2.3..HEAD', { :count => true })
78
+ .and_return('999')
79
+
80
+ proj.release_from_git
81
+ expect(proj._project.release).to eq('999')
82
+ end
83
+ end
84
+
56
85
  describe '#version_from_branch' do
57
86
  it 'parses out versions from branch names' do
58
87
  branches = {
@@ -517,4 +546,75 @@ end"
517
546
  expect(proj._project.components).to_not include(component)
518
547
  end
519
548
  end
549
+
550
+ describe "#fetch_artifact" do
551
+ let(:project_block) {
552
+ "project 'test-fixture' do |proj|
553
+ proj.fetch_artifact 'foo/bar/baz.file'
554
+ end"
555
+ }
556
+ let(:project_block_multiple) {
557
+ "project 'test-fixture' do |proj|
558
+ proj.fetch_artifact 'foo/bar/baz.file'
559
+ proj.fetch_artifact 'foo/foobar/foobarbaz.file'
560
+ end"
561
+ }
562
+ let(:empty_project_block) {
563
+ "project 'test-fixture' do |proj|
564
+ end"
565
+ }
566
+
567
+ it 'has an empty project.fetch_artifact when fetch_artifact is not called' do
568
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
569
+ proj.instance_eval(empty_project_block)
570
+ expect(proj._project.artifacts_to_fetch).to eq([])
571
+ end
572
+
573
+ it 'Adds a path to project.fetch_artifact when fetch_artifact is called' do
574
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
575
+ proj.instance_eval(project_block)
576
+ expect(proj._project.artifacts_to_fetch).to eq(['foo/bar/baz.file'])
577
+ end
578
+
579
+ it 'Adds multiple paths to project.fetch_artifact when fetch_artifact is called more than once' do
580
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
581
+ proj.instance_eval(project_block_multiple)
582
+ expect(proj._project.artifacts_to_fetch).to eq(['foo/bar/baz.file', 'foo/foobar/foobarbaz.file'])
583
+ end
584
+ end
585
+
586
+ describe "#no_packaging" do
587
+ let(:project_block) {
588
+ "project 'test-fixture' do |proj|
589
+ proj.no_packaging true
590
+ end"
591
+ }
592
+ let(:project_block_false) {
593
+ "project 'test-fixture' do |proj|
594
+ proj.no_packaging false
595
+ end"
596
+ }
597
+ let(:empty_project_block) {
598
+ "project 'test-fixture' do |proj|
599
+ end"
600
+ }
601
+
602
+ it 'has no_packaging set to false by default' do
603
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
604
+ proj.instance_eval(empty_project_block)
605
+ expect(proj._project.no_packaging).to eq(false)
606
+ end
607
+
608
+ it 'sets no_packaging to true when proj.no_packaging true is called' do
609
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
610
+ proj.instance_eval(project_block)
611
+ expect(proj._project.no_packaging).to eq(true)
612
+ end
613
+
614
+ it 'sets no_packaging to false when proj.no_packaging false is called' do
615
+ proj = Vanagon::Project::DSL.new('test-fixture', {}, [])
616
+ proj.instance_eval(project_block_false)
617
+ expect(proj._project.no_packaging).to eq(false)
618
+ end
619
+ end
520
620
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.3
4
+ version: 0.15.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-06 00:00:00.000000000 Z
11
+ date: 2018-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -88,6 +88,7 @@ files:
88
88
  - bin/repo
89
89
  - bin/ship
90
90
  - lib/git/basic_submodules.rb
91
+ - lib/git/rev_list.rb
91
92
  - lib/makefile.rb
92
93
  - lib/vanagon.rb
93
94
  - lib/vanagon/common.rb
@@ -169,6 +170,7 @@ files:
169
170
  - spec/fixtures/files/fake_dir.tar.gz
170
171
  - spec/fixtures/files/fake_dir/fake_file.txt
171
172
  - spec/fixtures/files/fake_file.txt
173
+ - spec/fixtures/files/fake_file.txt.erb
172
174
  - spec/fixtures/files/fake_file_ext.7z
173
175
  - spec/fixtures/files/fake_file_ext.bz
174
176
  - spec/fixtures/files/fake_file_ext.bz2
@@ -196,6 +198,7 @@ files:
196
198
  - spec/fixtures/wix/resources/windows/wix/project.wxs
197
199
  - spec/fixtures/wix/resources/windows/wix/ui/bitmaps/bitmap.bmp
198
200
  - spec/fixtures/wix/resources/windows/wix/ui/ui-sample-1.wxs
201
+ - spec/lib/git/rev_list_spec.rb
199
202
  - spec/lib/makefile_spec.rb
200
203
  - spec/lib/vanagon/common/pathname_spec.rb
201
204
  - spec/lib/vanagon/common/user_spec.rb
@@ -296,3 +299,4 @@ test_files:
296
299
  - spec/lib/vanagon/engine/base_spec.rb
297
300
  - spec/lib/vanagon/engine/pooler_spec.rb
298
301
  - spec/lib/makefile_spec.rb
302
+ - spec/lib/git/rev_list_spec.rb