puppet-blacksmith 3.4.0 → 4.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 067263620b3ecaa64fcd67b770345766d46f2728
4
- data.tar.gz: 87c4bc41babc57dd308dca7307af27ce25e994dd
2
+ SHA256:
3
+ metadata.gz: 4234c7e6eeb4943c9c3bcd8c4917ae65f9b21e1c4fa5a288064a8d12f8c2323e
4
+ data.tar.gz: 1d079e264eed5b52b55fd8a1805ee4032d50d5837abd0597555c151ba0b3c3df
5
5
  SHA512:
6
- metadata.gz: d7a3db4d6999ab0ea7ee416b9fbc8b6f93c40e95bb8bf904fa91766b7a45f8abf87a1a2f7aba226a5710705c50026ef8181330a31f6113e95ba440dcc352d137
7
- data.tar.gz: f3514d2f03b03b182aaa6c826e5e01ab5b525456761d13d2fb08f97608bda1754b1f74af99917dc9a4b77615aaf18df88e6a0145342cd9400d9257257df1bfd1
6
+ metadata.gz: 8398190c749747ed961359f93b8c59409d0bfdf21d3f1a061b76c9c636962ba1e0c10ba2f5c8cd475bae2a50307c259f2f70e7e718b0dd87e5d858e91eecf544
7
+ data.tar.gz: 98ec860d42286e2e574d0ba1d0fdeee503f63e6cc354c8a0a3f857c487d8e2adda2b23d991d679249781dbcd90aa00f390a4c16e740c799df08f297378a60a86
@@ -3,47 +3,68 @@ require 'open3'
3
3
  module Blacksmith
4
4
  class Git
5
5
 
6
- attr_accessor :path, :tag_pattern
7
- attr_writer :tag_pattern
6
+ attr_accessor :path, :tag_pattern, :tag_message_pattern, :commit_message_pattern
7
+ attr_writer :tag_pattern, :tag_message_pattern, :commit_message_pattern
8
8
 
9
9
  # Pattern to use for tags, %s is replaced with the actual version
10
+ def commit_message_pattern
11
+ @commit_message_pattern || "[blacksmith] Bump version to %s"
12
+ end
13
+
10
14
  def tag_pattern
11
15
  @tag_pattern || 'v%s'
12
16
  end
13
17
 
18
+ def tag_message_pattern
19
+ @tag_message_pattern
20
+ end
21
+
14
22
  def initialize(path = ".")
15
23
  @path = File.expand_path(path)
16
24
  end
17
25
 
26
+ def has_tag?(tag)
27
+ exec_git(['tag', '--list', tag]).strip == tag
28
+ end
29
+
30
+ def has_version_tag?(version)
31
+ tag = tag_pattern % version
32
+ has_tag? tag
33
+ end
34
+
18
35
  def tag!(version)
19
36
  tag = tag_pattern % version
20
- exec_git "tag #{tag}"
37
+ command = ["tag", tag]
38
+ if tag_message_pattern
39
+ tag_message = tag_message_pattern % version
40
+ command += ["-m", tag_message]
41
+ end
42
+ exec_git command
21
43
  end
22
44
 
23
45
  def commit_modulefile!(version)
24
46
  files = Blacksmith::Modulefile::FILES.select {|f| File.exists?(File.join(@path,f))}
25
- s = exec_git "add #{files.join(" ")}"
26
- s += exec_git "commit -m '[blacksmith] Bump version to #{version}'"
47
+ message = commit_message_pattern % version
48
+ s = exec_git ["add"] + files
49
+ s += exec_git ["commit", "-m", message]
27
50
  s
28
51
  end
29
52
 
30
53
  def push!
31
- s = exec_git "push"
32
- s += exec_git "push --tags"
54
+ s = exec_git ["push"]
55
+ s += exec_git ["push", "--tags"]
33
56
  s
34
57
  end
35
58
 
36
- def git_cmd_with_path(cmd)
37
- "git --git-dir=#{File.join(path, '.git')} --work-tree=#{path} #{cmd}"
38
- end
59
+ private
39
60
 
40
61
  def exec_git(cmd)
41
62
  out = ""
42
63
  err = ""
43
64
  exit_status = nil
44
- new_cmd = git_cmd_with_path(cmd)
65
+ new_cmd = ["git", "--git-dir", File.join(@path, '.git'), "--work-tree", @path] + cmd
45
66
  # wait_thr is nil in JRuby < 1.7.5 see http://jira.codehaus.org/browse/JRUBY-6409
46
- Open3.popen3(new_cmd) do |stdin, stdout, stderr, wait_thr|
67
+ Open3.popen3(*new_cmd) do |stdin, stdout, stderr, wait_thr|
47
68
  out = stdout.read
48
69
  err = stderr.read
49
70
  exit_status = wait_thr.nil? ? nil : wait_thr.value
@@ -1,49 +1,25 @@
1
- # Avoid loading everything Puppet when we only need the module tool
2
- # It causes trouble running it from jruby warbled jars
3
- # module Puppet
4
- # def self.settings
5
- # {}
6
- # end
7
- # def self.[](param)
8
- # end
9
- # end
10
- # require 'puppet/error'
11
- # require 'puppet/module_tool'
12
- require 'puppet'
13
- require 'puppet/module_tool'
14
1
  require 'puppet_blacksmith/version_helper'
15
2
 
16
- Puppet[:confdir] = "."
17
-
18
3
  module Blacksmith
19
4
  class Modulefile
20
5
 
21
- FILES = ["metadata.json", "Modulefile"]
6
+ FILES = ["metadata.json"]
22
7
 
23
8
  attr_reader :path
24
9
 
25
10
  def initialize(path = nil)
26
11
  @path = path.nil? ? FILES.find {|f| File.exists? f} : path
27
12
  raise Blacksmith::Error, "Unable to find any of #{FILES}" unless @path
28
- @modulefile = @path =~ /Modulefile$/
29
13
  end
30
14
 
31
15
  def metadata
32
- unless @metadata
33
- if @modulefile
34
- metadata = Puppet::ModuleTool::Metadata.new
35
- Puppet::ModuleTool::ModulefileReader.evaluate(metadata, path)
36
- @metadata = { 'name' => metadata.name, 'version' => metadata.version, 'author' => metadata.author }
37
- else
38
- @metadata = JSON.parse(File.read(path))
39
- end
40
- end
16
+ @metadata = JSON.parse(File.read(path)) unless @metadata
41
17
  @metadata
42
18
  end
43
19
 
44
20
  # name in metadata.json is author-modulename
45
21
  def name
46
- @modulefile ? metadata['name'] : metadata['name'].split('-',2)[1]
22
+ metadata['name'].split('-',2)[1]
47
23
  end
48
24
  def author
49
25
  metadata['author'] || metadata['name'].split('-',2)[0]
@@ -71,13 +47,9 @@ module Blacksmith
71
47
  end
72
48
 
73
49
  def replace_version(text, version)
74
- if @modulefile
75
- text.gsub(/\nversion[ ]+['"].*['"]/, "\nversion '#{version}'")
76
- else
77
- json = JSON.parse(text)
78
- json['version'] = version
79
- JSON.pretty_generate(json)
80
- end
50
+ json = JSON.parse(text)
51
+ json['version'] = version
52
+ JSON.pretty_generate(json)
81
53
  end
82
54
 
83
55
  def increase_version(version, level = :patch)
@@ -86,21 +58,15 @@ module Blacksmith
86
58
  end
87
59
 
88
60
  def replace_dependency_version(text, module_name, version)
89
- if @modulefile
90
- # example: dependency 'puppetlabs/stdlib', '>= 2.3.0'
91
- module_name = module_name.sub(/^([^\/-]+)-/, '\1/')
92
- text.gsub(/\ndependency[ ]+['"].*#{module_name}['"],([ ]+['"].*['"]|)/, "\ndependency '#{module_name}', '#{version}'")
93
- else
94
- module_name = module_name.sub(/\//, '-')
95
- json = JSON.parse(text)
96
- new_dep_list = []
97
- json['dependencies'].each do |dep|
98
- dep['version_requirement'] = version if dep['name'] == module_name
99
- new_dep_list << dep
100
- end
101
- json['dependencies'] = new_dep_list
102
- JSON.pretty_generate(json)
61
+ module_name = module_name.sub(/\//, '-')
62
+ json = JSON.parse(text)
63
+ new_dep_list = []
64
+ json['dependencies'].each do |dep|
65
+ dep['version_requirement'] = version if dep['name'] == module_name
66
+ new_dep_list << dep
103
67
  end
68
+ json['dependencies'] = new_dep_list
69
+ JSON.pretty_generate(json)
104
70
  end
105
71
  end
106
72
  end
@@ -5,7 +5,7 @@ require 'puppet_blacksmith'
5
5
  module Blacksmith
6
6
  class RakeTask < ::Rake::TaskLib
7
7
 
8
- attr_accessor :tag_pattern, :build
8
+ attr_accessor :tag_pattern, :tag_message_pattern, :commit_message_pattern, :build
9
9
 
10
10
  def initialize(*args, &task_block)
11
11
  @build = true
@@ -69,6 +69,8 @@ module Blacksmith
69
69
  m = Blacksmith::Modulefile.new
70
70
  git = Blacksmith::Git.new
71
71
  git.tag_pattern = @tag_pattern
72
+ git.tag_message_pattern = @tag_message_pattern
73
+ git.commit_message_pattern = @commit_message_pattern
72
74
  git.tag!(m.version)
73
75
  end
74
76
 
@@ -99,7 +101,11 @@ module Blacksmith
99
101
  desc "Bump module version to the next #{level.upcase} version and git commit"
100
102
  task level => "bump:#{level}".to_sym do
101
103
  m = Blacksmith::Modulefile.new
102
- Blacksmith::Git.new.commit_modulefile!(m.version)
104
+ git = Blacksmith::Git.new
105
+ git.tag_pattern = @tag_pattern
106
+ git.tag_message_pattern = @tag_message_pattern
107
+ git.commit_message_pattern = @commit_message_pattern
108
+ git.commit_modulefile!(m.version)
103
109
  end
104
110
  end
105
111
  end
@@ -107,7 +113,11 @@ module Blacksmith
107
113
  desc "Bump version and git commit"
108
114
  task :bump_commit => :bump do
109
115
  m = Blacksmith::Modulefile.new
110
- Blacksmith::Git.new.commit_modulefile!(m.version)
116
+ git = Blacksmith::Git.new
117
+ git.tag_pattern = @tag_pattern
118
+ git.tag_message_pattern = @tag_message_pattern
119
+ git.commit_message_pattern = @commit_message_pattern
120
+ git.commit_modulefile!(m.version)
111
121
  end
112
122
 
113
123
  desc "Push module to the Puppet Forge"
@@ -125,10 +135,14 @@ module Blacksmith
125
135
  end
126
136
 
127
137
  desc "Release the Puppet module, doing a clean, build, tag, push, bump_commit and git push."
128
- release_dependencies = @build ? [:clean, :build, :tag, :push, :bump_commit] : [:clean, :tag, :bump_commit]
138
+ release_dependencies = @build ? [:clean, :build, :bump_commit, :tag, :push] : [:clean, :bump_commit, :tag]
129
139
  task :release => release_dependencies do
130
140
  puts "Pushing to remote git repo"
131
- Blacksmith::Git.new.push!
141
+ git = Blacksmith::Git.new
142
+ git.tag_pattern = @tag_pattern
143
+ git.tag_message_pattern = @tag_message_pattern
144
+ git.commit_message_pattern = @commit_message_pattern
145
+ git.push!
132
146
  end
133
147
 
134
148
  desc "Set specific module dependency version"
@@ -1,3 +1,3 @@
1
1
  module Blacksmith
2
- VERSION = '3.4.0'
2
+ VERSION = '4.0.0'
3
3
  end
@@ -91,9 +91,10 @@ describe 'Blacksmith::Forge' do
91
91
  :headers => {})
92
92
 
93
93
  stub_request(:post, "#{forge}/v2/releases").with(
94
- :body => %r{Content-Disposition: form-data; name=\"file\"; filename=\"maestrodev-test.tar.gz\"\r\nContent-Type: application/gzip},
95
- :headers => headers.merge({'Accept'=>'*/*; q=0.5, application/xml', 'Accept-Encoding'=>'gzip, deflate', 'Authorization'=>'Bearer e52f78b62e97cb8d8db6659a73aa522cca0f5c74d4714e0ed0bdd10000000000', 'Content-Type'=>%r{multipart/form-data;}})
96
- ).to_return(:status => 200, :body => File.read(File.join(spec_data, "response.json")), :headers => {})
94
+ :headers => headers.merge({'Accept'=>'*/*', 'Accept-Encoding'=>'gzip, deflate', 'Authorization'=>'Bearer e52f78b62e97cb8d8db6659a73aa522cca0f5c74d4714e0ed0bdd10000000000', 'Content-Type'=>%r{\Amultipart/form-data;}})
95
+ ) { |request |
96
+ request.body =~ %r{Content-Disposition: form-data; name=\"file\"; filename=\"maestrodev-test.tar.gz\"\r\nContent-Type: application/gzip}
97
+ }.to_return(:status => 200, :body => File.read(File.join(spec_data, "response.json")), :headers => {})
97
98
 
98
99
  end
99
100
 
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe 'Blacksmith::Git' do
4
4
 
5
5
  subject { Blacksmith::Git.new(path) }
6
- let(:path) { File.join(File.dirname(__FILE__), '../../tmp/git_test') }
6
+ let(:path) { File.expand_path(File.join(File.dirname(__FILE__), '../../tmp/git_test')) }
7
7
  let(:version) { '1.0.0' }
8
8
  let(:metadata_file) { "metadata.json" }
9
9
 
@@ -16,6 +16,33 @@ describe 'Blacksmith::Git' do
16
16
  end
17
17
 
18
18
  shared_examples_for :git do
19
+ describe 'has_tag?' do
20
+ context 'with a tag' do
21
+ before { subject.tag!(version) }
22
+ it { expect(subject.has_tag?("v#{version}")).to be true }
23
+ end
24
+
25
+ context 'with a partial match' do
26
+ before { subject.tag!(version) }
27
+ it { expect(subject.has_tag?(version)).to be false }
28
+ end
29
+
30
+ context 'without a tag' do
31
+ it { expect(subject.has_tag?('something')).to be false }
32
+ end
33
+ end
34
+
35
+ describe 'has_tag?' do
36
+ context 'with a tag' do
37
+ before { subject.tag!(version) }
38
+ it { expect(subject.has_version_tag?(version)).to be true }
39
+ end
40
+
41
+ context 'without a tag' do
42
+ it { expect(subject.has_version_tag?('something')).to be false }
43
+ end
44
+ end
45
+
19
46
  describe 'tag!' do
20
47
  before { subject.tag!(version) }
21
48
  it "should have the tag" do
@@ -37,7 +64,7 @@ describe 'Blacksmith::Git' do
37
64
  end
38
65
 
39
66
  describe 'exec_git' do
40
- let(:cmd) { 'log' }
67
+ let(:cmd) { ['log'] }
41
68
  let(:stdin) { nil }
42
69
  let(:stdout) { '' }
43
70
  let(:stderr) { '' }
@@ -46,8 +73,10 @@ describe 'Blacksmith::Git' do
46
73
 
47
74
  context 'when git succeeds' do
48
75
  before do
49
- allow(Open3).to receive(:popen3).and_yield(nil, double(:read => stdout), double(:read => stderr), wait_thr)
50
- expect { subject.exec_git(cmd) }.to_not raise_error
76
+ allow(Open3).to receive(:popen3). \
77
+ with('git', '--git-dir', File.join(path, '.git'), '--work-tree', path, *cmd). \
78
+ and_yield(nil, double(:read => stdout), double(:read => stderr), wait_thr)
79
+ expect { subject.send(:exec_git, cmd) }.to_not raise_error
51
80
  end
52
81
 
53
82
  context 'when stderr is empty' do
@@ -62,27 +91,20 @@ describe 'Blacksmith::Git' do
62
91
  end
63
92
 
64
93
  context 'when git fails' do
65
- before { allow(subject).to receive(:git_cmd_with_path) {cmd} }
66
-
67
94
  # this spec fails on jruby, can't detect exit code of script
68
95
  context 'when stderr is empty' do
69
- let(:cmd) { "git" } # exits with 1
70
- it { expect { subject.exec_git(cmd) }.to raise_error(Blacksmith::Error, /^Command .* failed with exit status.*1.*$/) }
96
+ let(:cmd) { [] } # exits with 1
97
+ it { expect { subject.send(:exec_git, cmd) }.to raise_error(Blacksmith::Error, /^Command .* failed with exit status.*1.*$/) }
71
98
  end
72
99
 
73
100
  context 'when stderr is not empty' do
74
- let(:cmd) { "git help xxxx" } # exits with 1 and prints to stdout
75
- it { expect { subject.exec_git(cmd) }.to raise_error(Blacksmith::Error, /No manual entry for gitxxx/) }
101
+ let(:cmd) { ["help", "xxxx"] } # exits with 1 and prints to stdout
102
+ it { expect { subject.send(:exec_git, cmd) }.to raise_error(Blacksmith::Error, /No manual entry for gitxxx/) }
76
103
  end
77
104
  end
78
105
  end
79
106
  end
80
107
 
81
- context "Using Modulefile" do
82
- let(:metadata_file) { "Modulefile" }
83
- it_behaves_like :git
84
- end
85
-
86
108
  context "Using metadata.json" do
87
109
  it_behaves_like :git
88
110
  end
@@ -109,49 +109,6 @@ describe 'Blacksmith::Modulefile' do
109
109
 
110
110
  end
111
111
 
112
- context "using a Modulefile" do
113
-
114
- let(:path) { "spec/data/Modulefile" }
115
-
116
- it_behaves_like :metadata
117
-
118
- describe 'replace_version' do
119
- it "should replace the version in a Modulefile" do
120
- expected = <<-eos
121
- name 'maestrodev-test'
122
- version '1.0.1'
123
-
124
- license 'Apache License, Version 2.0'
125
- project_page 'http://github.com/maestrodev/puppet-blacksmith'
126
- source 'http://github.com/maestrodev/puppet-blacksmith'
127
- summary 'Testing Puppet module operations'
128
- description 'Testing Puppet module operations'
129
- dependency 'puppetlabs/stdlib', '>= 3.0.0'
130
- eos
131
-
132
- expect(subject.replace_version(File.read(path), "1.0.1")).to eql(expected)
133
- end
134
- end
135
-
136
- describe 'replace_dependency_version' do
137
- it "should replace the dependency version in a Modulefile" do
138
- expected = <<-eos
139
- name 'maestrodev-test'
140
- version '1.0.0'
141
-
142
- license 'Apache License, Version 2.0'
143
- project_page 'http://github.com/maestrodev/puppet-blacksmith'
144
- source 'http://github.com/maestrodev/puppet-blacksmith'
145
- summary 'Testing Puppet module operations'
146
- description 'Testing Puppet module operations'
147
- dependency 'puppetlabs/stdlib', '>= 4.0.0'
148
- eos
149
-
150
- expect(subject.replace_dependency_version(File.read(path), 'puppetlabs-stdlib', '>= 4.0.0')).to eql(expected)
151
- end
152
- end
153
- end
154
-
155
112
  describe 'increase_version' do
156
113
  it { expect(subject.increase_version("1.0.0")).to eql("1.0.1") }
157
114
  it { expect(subject.increase_version("1.0.1")).to eql("1.0.2") }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-blacksmith
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MaestroDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-11 00:00:00.000000000 Z
11
+ date: 2017-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.0
19
+ version: '2.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.8.0
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: puppet
28
+ name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 2.7.16
34
- type: :runtime
33
+ version: '0'
34
+ type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 2.7.16
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rake
42
+ name: puppet
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 2.7.16
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 2.7.16
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: puppetlabs_spec_helper
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: 1.23.0
117
+ version: '2.0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: 1.23.0
124
+ version: '2.0'
125
125
  description: Puppet module tools for development and Puppet Forge management
126
126
  email:
127
127
  - info@maestrodev.com
@@ -149,7 +149,7 @@ files:
149
149
  - spec/puppet_blacksmith/git_spec.rb
150
150
  - spec/puppet_blacksmith/modulefile_spec.rb
151
151
  - spec/spec_helper.rb
152
- homepage: http://github.com/maestrodev/puppet-blacksmith
152
+ homepage: http://github.com/voxpupuli/puppet-blacksmith
153
153
  licenses: []
154
154
  metadata: {}
155
155
  post_install_message:
@@ -168,14 +168,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.4.6
171
+ rubygems_version: 2.7.0
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Tasks to manage Puppet module builds
175
175
  test_files:
176
+ - spec/data/Modulefile
176
177
  - spec/data/maestrodev-test/metadata.json
177
178
  - spec/data/metadata.json
178
- - spec/data/Modulefile
179
179
  - spec/data/response.json
180
180
  - spec/puppet_blacksmith/forge_live_spec.rb
181
181
  - spec/puppet_blacksmith/forge_shared.rb