-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathrake_tasks.rb
180 lines (159 loc) · 5.51 KB
/
rake_tasks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
require 'rake'
require 'rake/tasklib'
require 'puppet_blacksmith'
module Blacksmith
class RakeTask < ::Rake::TaskLib
attr_accessor :tag_pattern, :tag_message_pattern, :tag_sign, :commit_message_pattern, :build
def initialize(*args, &task_block)
@build = true
@task_name = args.shift || 'blacksmith'
@desc = args.shift || 'Puppet Forge utilities'
define(args, &task_block)
end
def git
git = Blacksmith::Git.new
git.tag_pattern = @tag_pattern
git.tag_message_pattern = @tag_message_pattern
git.commit_message_pattern = @commit_message_pattern
git.tag_sign = @tag_sign
git
end
def define(args, &task_block)
yield(*[self, args].slice(0, task_block.arity)) if task_block
# clear any (auto-)pre-existing task
[
:build,
:bump,
'bump:major',
'bump:minor',
'bump:patch',
'bump:full',
:tag,
:version,
'version:next',
'version:next:major',
'version:next:minor',
'version:next:patch',
:bump_commit,
'bump_commit:major',
'bump_commit:minor',
'bump_commit:patch',
'bump_commit:full',
:push,
:clean,
:release,
:dependency,
].each do |t|
Rake::Task.task_defined?("module:#{t}") && Rake::Task["module:#{t}"].clear
end
namespace :module do
desc 'Build the module using puppet-modulebuilder'
task :build do
require 'puppet/modulebuilder'
builder = Puppet::Modulebuilder::Builder.new(Dir.pwd)
package_file = builder.build
puts "Built #{package_file}"
end
namespace :bump do
%i[major minor patch full].each do |level|
desc "Bump module version to the next #{level.upcase} version"
task level do
m = Blacksmith::Modulefile.new
v = m.bump!(level)
puts "Bumping version from #{m.version} to #{v}"
end
end
end
desc 'Bump module to specific version number'
task :bump_to_version, [:new_version] do |_t, targs|
m = Blacksmith::Modulefile.new
m.bump_to_version!(targs[:new_version])
puts "Bumping version to #{targs[:new_version]}"
end
desc 'Bump module version to the next patch'
task :bump do
m = Blacksmith::Modulefile.new
v = m.bump_patch!
puts "Bumping version from #{m.version} to #{v}"
end
desc 'Git tag with the current module version'
task :tag do
m = Blacksmith::Modulefile.new
git.tag!(m.version)
end
namespace :version do
desc 'Get next module version'
task :next do
m = Blacksmith::Modulefile.new
puts m.increase_version(m.version, 'patch')
end
%i[major minor patch].each do |level|
desc "Get the next #{level.upcase} version"
task "next:#{level}".to_sym do
m = Blacksmith::Modulefile.new
puts m.increase_version(m.version, level)
end
end
end
desc 'Get current module version'
task :version do
m = Blacksmith::Modulefile.new
puts m.version
end
namespace :bump_commit do
%i[major minor patch full].each do |level|
desc "Bump module version to the next #{level.upcase} version and git commit"
task level => "bump:#{level}".to_sym do
m = Blacksmith::Modulefile.new
git.commit_modulefile!(m.version)
end
end
end
desc 'Bump version and git commit'
task bump_commit: :bump do
m = Blacksmith::Modulefile.new
git.commit_modulefile!(m.version)
end
desc 'Push module to the Puppet Forge'
task push: :'module:build' do
m = Blacksmith::Modulefile.new
forge = Blacksmith::Forge.new
puts "Uploading to Puppet Forge #{m.namespace}/#{m.name}"
forge.push!(m.name, nil, m.namespace, m.version)
end
desc 'Runs clean again'
task :clean do
puts 'Cleaning for module build'
if Rake::Task.task_defined?(:clean)
Rake::Task['clean'].execute
else
# identical to the clean task in puppetlabs_spec_helper on 2021-07-30
# https://github.com/puppetlabs/puppetlabs_spec_helper/blob/24d7b21280a26cc682146839f41dbf1c0793e494/lib/puppetlabs_spec_helper/rake_tasks.rb#L165-L168
require 'fileutils'
FileUtils.rm_rf('pkg/')
end
end
desc 'Release the Puppet module, doing a clean, build, bump_commit, tag, push and git push.'
release_dependencies = if @build
%i[clean module:build bump_commit tag
push]
else
%i[clean bump_commit tag]
end
task release: release_dependencies do
puts 'Pushing to remote git repo'
git.push!
end
desc 'Set specific module dependency version'
task :dependency, [:module_name, :version] do |_t, targs|
mn = targs[:module_name]
mv = targs[:version]
m = Blacksmith::Modulefile.new
m.bump_dep! mn, mv
puts "Updated module dependency #{mn} to #{mv}"
end
end
end
end
end
Blacksmith::RakeTask.new