puppet-blacksmith 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MGI4M2FiZTBmMzY4ODVmZWY1YWUwZDkwODY5M2Q3M2YwZDFjYTliZA==
4
+ NGJhY2U2NDIxMDJlNTY5Nzk5ODg2ZDNhNmExMDNmMDYzYTkwNjE3Mg==
5
5
  data.tar.gz: !binary |-
6
- OTgyOTQ3ZGYxMGMxYmQ1Zjc4M2Y4ZjI3OTc0MjFiZjE2NzljNmI2MA==
6
+ OTg0ZGM3NzI0Nzg1MWM3MDlhNWNjZTE4YzBkODU2MDQ4OThiZmI4OQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZGEyYjk5ZWNmNzNhNTIxMzQ2NTk1YzY4MGNhNjYyZTYwYTI4NjQ5OWI0NGRj
10
- YmQ2ODRjMjMyY2UxNGRhMjI1OGNlYzQxZjRiMjk5ZjM3ODhhZmE2MzI4NjUx
11
- Njc1OWZkY2U1MDMxNTY2OTk5MmE0ZjNkNjliMmYyNTA5MmVjODg=
9
+ YmM2ODBkOTJmZjQ2OWM3YzYyNjk4Y2QzOGIwNDQ3YWNiNTQwNTllY2MyM2I2
10
+ OTVkN2MxMWExOTkxNTE4YjZkNjJhYWZmNDBjYzQ4NWY1N2FlYjk0ZDkyZjRl
11
+ NGM2NDcwM2FhZDlhNmI4ZjZhYjA5MTYxMzJhMDJmNTEyOTRmNTI=
12
12
  data.tar.gz: !binary |-
13
- MjU3MDMwZGYwZDAzZWY5NzE1MTcwODEwMjhjYTAyYzNiZjNlZmJkMjY2MDhh
14
- YTNhNTA3MmZlNDM2MDgyNTk1NDNmYjVjNzlkN2RhZDUzN2Q5MjdjZGQ0YTlk
15
- YTgwOTU2YzhhNTA0ZWZmYTFjYmU2YTIyMDI5MmI0NWZiYmViZGI=
13
+ ZWEyNTI4MTNiYWQ2NzU1MGFkYmE5ZDA3NzNlZmEyNGQwMzk5OTZhOGUyYmY4
14
+ ZTQyMWRjYjk0ZDBiNjgzYWFhYWM1ZGJjY2UwMjI4YzZhMjA0N2E0YmI0OTc2
15
+ OWYxNjM1MTMyMTc5NGM1NzBkZjY5MzU4ZDRhNzA3MDRhN2JmYWQ=
@@ -3,14 +3,21 @@ require 'open3'
3
3
  module Blacksmith
4
4
  class Git
5
5
 
6
- attr_accessor :path
6
+ attr_accessor :path, :tag_pattern
7
+ attr_writer :tag_pattern
8
+
9
+ # Pattern to use for tags, %s is replaced with the actual version
10
+ def tag_pattern
11
+ @tag_pattern || 'v%s'
12
+ end
7
13
 
8
14
  def initialize(path = ".")
9
15
  @path = File.expand_path(path)
10
16
  end
11
17
 
12
18
  def tag!(version)
13
- exec_git "tag v#{version}"
19
+ tag = tag_pattern % version
20
+ exec_git "tag #{tag}"
14
21
  end
15
22
 
16
23
  def commit_modulefile!(version)
@@ -59,6 +59,12 @@ module Blacksmith
59
59
  new_version
60
60
  end
61
61
 
62
+ def bump_dep!(module_name, version)
63
+ text = File.read(path)
64
+ text = replace_dependency_version(text, module_name, version)
65
+ File.open(path, "w") {|file| file.puts text}
66
+ end
67
+
62
68
  def replace_version(text, version)
63
69
  if @modulefile
64
70
  text.gsub(/\nversion[ ]+['"].*['"]/, "\nversion '#{version}'")
@@ -74,5 +80,23 @@ module Blacksmith
74
80
  raise Blacksmith::Error, "Unable to increase prerelease version #{version}" if v.prerelease?
75
81
  v.bump.to_s
76
82
  end
83
+
84
+ def replace_dependency_version(text, module_name, version)
85
+ if @modulefile
86
+ # example: dependency 'puppetlabs/stdlib', '>= 2.3.0'
87
+ module_name = module_name.sub(/^([^\/-]+)-/, '\1/')
88
+ text.gsub(/\ndependency[ ]+['"].*#{module_name}['"],([ ]+['"].*['"]|)/, "\ndependency '#{module_name}', '#{version}'")
89
+ else
90
+ module_name = module_name.sub(/\//, '-')
91
+ json = JSON.parse(text)
92
+ new_dep_list = []
93
+ json['dependencies'].each do |dep|
94
+ dep['version_requirement'] = version if dep['name'] == module_name
95
+ new_dep_list << dep
96
+ end
97
+ json['dependencies'] = new_dep_list
98
+ JSON.pretty_generate(json)
99
+ end
100
+ end
77
101
  end
78
102
  end
@@ -1,44 +1,82 @@
1
1
  require 'rake'
2
+ require 'rake/tasklib'
2
3
  require 'puppet_blacksmith'
3
4
 
4
- namespace :module do
5
- desc "Bump module version to the next minor"
6
- task :bump do
7
- m = Blacksmith::Modulefile.new
8
- v = m.bump!
9
- puts "Bumping version from #{m.version} to #{v}"
10
- end
5
+ module Blacksmith
6
+ class RakeTask < ::Rake::TaskLib
11
7
 
12
- desc "Git tag with the current module version"
13
- task :tag do
14
- m = Blacksmith::Modulefile.new
15
- Blacksmith::Git.new.tag!(m.version)
16
- end
8
+ attr_accessor :tag_pattern
17
9
 
18
- desc "Bump version and git commit"
19
- task :bump_commit => :bump do
20
- m = Blacksmith::Modulefile.new
21
- Blacksmith::Git.new.commit_modulefile!(m.version)
22
- end
10
+ def initialize(*args, &task_block)
11
+ @task_name = args.shift || "blacksmith"
12
+ @desc = args.shift || "Puppet Forge utilities"
13
+ puts "INIT"
14
+ define(args, &task_block)
15
+ end
23
16
 
24
- desc "Push module to the Puppet Forge"
25
- task :push => :build do
26
- m = Blacksmith::Modulefile.new
27
- forge = Blacksmith::Forge.new
28
- puts "Uploading to Puppet Forge #{forge.username}/#{m.name}"
29
- forge.push!(m.name)
30
- end
17
+ def define(args, &task_block)
31
18
 
32
- desc "Runs clean again"
33
- task :clean do
34
- puts "Cleaning for module build"
35
- Rake::Task["clean"].execute
36
- end
19
+ task_block.call(*[self, args].slice(0, task_block.arity)) if task_block
37
20
 
38
- desc "Release the Puppet module, doing a clean, build, tag, push, bump_commit and git push."
39
- task :release => [:clean, :build, :tag, :push, :bump_commit] do
40
- puts "Pushing to remote git repo"
41
- Blacksmith::Git.new.push!
42
- end
21
+ # clear any (auto-)pre-existing task
22
+ [:bump, :tag, :bump_commit, :push, :clean, :release, :dependency].each do |t|
23
+ Rake::Task.task_defined?("module:#{t}") && Rake::Task["module:#{t}"].clear
24
+ end
25
+
26
+ namespace :module do
27
+
28
+ desc "Bump module version to the next minor"
29
+ task :bump do
30
+ m = Blacksmith::Modulefile.new
31
+ v = m.bump!
32
+ puts "Bumping version from #{m.version} to #{v}"
33
+ end
43
34
 
35
+ desc "Git tag with the current module version"
36
+ task :tag do
37
+ m = Blacksmith::Modulefile.new
38
+ git = Blacksmith::Git.new
39
+ git.tag_pattern = @tag_pattern
40
+ git.tag!(m.version)
41
+ end
42
+
43
+ desc "Bump version and git commit"
44
+ task :bump_commit => :bump do
45
+ m = Blacksmith::Modulefile.new
46
+ Blacksmith::Git.new.commit_modulefile!(m.version)
47
+ end
48
+
49
+ desc "Push module to the Puppet Forge"
50
+ task :push => :build do
51
+ m = Blacksmith::Modulefile.new
52
+ forge = Blacksmith::Forge.new
53
+ puts "Uploading to Puppet Forge #{forge.username}/#{m.name}"
54
+ forge.push!(m.name)
55
+ end
56
+
57
+ desc "Runs clean again"
58
+ task :clean do
59
+ puts "Cleaning for module build"
60
+ Rake::Task["clean"].execute
61
+ end
62
+
63
+ desc "Release the Puppet module, doing a clean, build, tag, push, bump_commit and git push."
64
+ task :release => [:clean, :build, :tag, :push, :bump_commit] do
65
+ puts "Pushing to remote git repo"
66
+ Blacksmith::Git.new.push!
67
+ end
68
+
69
+ desc "Set specific module dependency version"
70
+ task :dependency, [:module_name, :version] do |t, args|
71
+ mn = args[:module_name]
72
+ mv = args[:version]
73
+ m = Blacksmith::Modulefile.new
74
+ m.bump_dep! mn, mv
75
+ puts "Updated module dependency #{mn} to #{mv}"
76
+ end
77
+ end
78
+ end
79
+ end
44
80
  end
81
+
82
+ Blacksmith::RakeTask.new
@@ -1,3 +1,3 @@
1
1
  module Blacksmith
2
- VERSION = '3.0.3'
2
+ VERSION = '3.1.0'
3
3
  end
data/spec/data/Modulefile CHANGED
@@ -6,3 +6,4 @@ project_page 'http://github.com/maestrodev/puppet-blacksmith'
6
6
  source 'http://github.com/maestrodev/puppet-blacksmith'
7
7
  summary 'Testing Puppet module operations'
8
8
  description 'Testing Puppet module operations'
9
+ dependency 'puppetlabs/stdlib', '>= 3.0.0'
@@ -28,5 +28,9 @@
28
28
  "description": "Standard Library for Puppet Modules",
29
29
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
30
30
  "dependencies": [
31
+ {
32
+ "name": "puppetlabs-stdlib",
33
+ "version_requirement": ">= 3.0.0"
34
+ }
31
35
  ]
32
36
  }
@@ -49,6 +49,10 @@ describe 'Blacksmith::Modulefile' do
49
49
  "description": "Standard Library for Puppet Modules",
50
50
  "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
51
51
  "dependencies": [
52
+ {
53
+ "name": "puppetlabs-stdlib",
54
+ "version_requirement": ">= 3.0.0"
55
+ }
52
56
  ]
53
57
  }
54
58
  eos
@@ -57,6 +61,52 @@ describe 'Blacksmith::Modulefile' do
57
61
  end
58
62
  end
59
63
 
64
+ describe 'replace_dependency_version' do
65
+ it "should replace the version in metadata" do
66
+
67
+ expected = <<-eos
68
+ {
69
+ "operatingsystem_support": [
70
+ {
71
+ "operatingsystem": "CentOS",
72
+ "operatingsystemrelease": [
73
+ "4",
74
+ "5",
75
+ "6"
76
+ ]
77
+ }
78
+ ],
79
+ "requirements": [
80
+ {
81
+ "name": "pe",
82
+ "version_requirement": "3.2.x"
83
+ },
84
+ {
85
+ "name": "puppet",
86
+ "version_requirement": ">=2.7.20 <4.0.0"
87
+ }
88
+ ],
89
+ "name": "maestrodev-test",
90
+ "version": "1.0.0",
91
+ "source": "git://github.com/puppetlabs/puppetlabs-stdlib",
92
+ "author": "maestrodev",
93
+ "license": "Apache 2.0",
94
+ "summary": "Puppet Module Standard Library",
95
+ "description": "Standard Library for Puppet Modules",
96
+ "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib",
97
+ "dependencies": [
98
+ {
99
+ "name": "puppetlabs-stdlib",
100
+ "version_requirement": ">= 4.0.0"
101
+ }
102
+ ]
103
+ }
104
+ eos
105
+
106
+ expect(JSON.parse(subject.replace_dependency_version(File.read(path), 'puppetlabs-stdlib', '>= 4.0.0'))).to eql(JSON.parse(expected))
107
+ end
108
+ end
109
+
60
110
  end
61
111
 
62
112
  context "using a Modulefile" do
@@ -76,12 +126,30 @@ project_page 'http://github.com/maestrodev/puppet-blacksmith'
76
126
  source 'http://github.com/maestrodev/puppet-blacksmith'
77
127
  summary 'Testing Puppet module operations'
78
128
  description 'Testing Puppet module operations'
129
+ dependency 'puppetlabs/stdlib', '>= 3.0.0'
79
130
  eos
80
131
 
81
132
  expect(subject.replace_version(File.read(path), "1.0.1")).to eql(expected)
82
133
  end
83
134
  end
84
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
85
153
  end
86
154
 
87
155
  describe 'increase_version' do
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.0.3
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MaestroDev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-29 00:00:00.000000000 Z
11
+ date: 2014-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -172,13 +172,13 @@ signing_key:
172
172
  specification_version: 4
173
173
  summary: Tasks to manage Puppet module builds
174
174
  test_files:
175
- - spec/spec_helper.rb
176
175
  - spec/data/metadata.json
177
176
  - spec/data/response.json
178
177
  - spec/data/Modulefile
179
178
  - spec/data/maestrodev-test/metadata.json
180
- - spec/puppet_blacksmith/forge_spec.rb
181
- - spec/puppet_blacksmith/forge_shared.rb
182
- - spec/puppet_blacksmith/forge_live_spec.rb
183
179
  - spec/puppet_blacksmith/modulefile_spec.rb
184
180
  - spec/puppet_blacksmith/git_spec.rb
181
+ - spec/puppet_blacksmith/forge_shared.rb
182
+ - spec/puppet_blacksmith/forge_spec.rb
183
+ - spec/puppet_blacksmith/forge_live_spec.rb
184
+ - spec/spec_helper.rb