summaryrefslogtreecommitdiffstats
path: root/Rakefile
blob: de7626f342dcf4fc61a49cce30ba0f5c18177643 (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# Rakefile for Puppet

begin
    require 'rubygems'
    require 'rake/gempackagetask'
rescue Exception
    nil
end

require 'rdoc/rdoc'
require 'rake/clean'
require 'rake/testtask'

require 'rake/rdoctask'
CLEAN.include('**/*.o')
CLOBBER.include('doc/*')

def announce(msg='')
    STDERR.puts msg
end

# Determine the current version

if `ruby -Ilib ./bin/puppet --version` =~ /\S+$/
    CURRENT_VERSION = $&
else
    CURRENT_VERSION = "0.0.0"
end

if ENV['REL']
  PKG_VERSION = ENV['REL']
else
  PKG_VERSION = CURRENT_VERSION
end

DOWNDIR = "/export/docroots/reductivelabs.com/htdocs/downloads"

if ENV['HOSTS']
    TESTHOSTS = ENV['HOSTS'].split(/\s+/)
else
    TESTHOSTS = %w{fedora1 rh3a kirby culain openbsd1 centos1}
end
#TESTHOSTS = %w{sol10b}

# The default task is run if rake is given no explicit arguments.

desc "Default Task"
task :default => :alltests

# Test Tasks ---------------------------------------------------------

task :u => :unittests
task :a => :alltests

task :alltests do
    sh %{cd test; ./test}
end

#Rake::TestTask.new(:alltests) do |t|
#    t.test_files = FileList['test/*/*.rb']
#    t.warning = true
#    t.verbose = false
#end

#Rake::TestTask.new(:unittests) do |t|
#    t.test_files = FileList['test/test']
#    t.warning = true
#    t.verbose = false
#end

# SVN Tasks ----------------------------------------------------------
# ... none.

# Install rake using the standard install.rb script.

desc "Install the application"
task :install do
    ruby "install.rb"
end

# Create a task to build the RDOC documentation tree.

#Rake::RDocTask.new("ri") { |rdoc|
#    #rdoc.rdoc_dir = 'html'
#    #rdoc.template = 'html'
#    rdoc.title    = "Puppet"
#    rdoc.options << '--ri' << '--line-numbers' << '--inline-source' << '--main' << 'README'
#    rdoc.rdoc_files.include('README', 'LICENSE', 'TODO', 'CHANGELOG')
#    rdoc.rdoc_files.include('lib/**/*.rb', 'doc/**/*.rdoc')
#}

Rake::RDocTask.new(:html) { |rdoc|
    rdoc.rdoc_dir = 'html'
    rdoc.template = 'html'
    rdoc.title    = "Puppet"
    rdoc.options << '--line-numbers' << '--inline-source' << '--main' << 'README'
    rdoc.rdoc_files.include('README', 'LICENSE', 'TODO', 'CHANGELOG')
    rdoc.rdoc_files.include('lib/**/*.rb')
    CLEAN.include("html")
}

task :ri do |ri|
    files = ['README', 'LICENSE', 'TODO', 'CHANGELOG'] + Dir.glob('lib/**/*.rb')
    puts "files are \n%s" % files.join("\n")
    begin
        ri = RDoc::RDoc.new
        ri.document(["--ri-site"] + files)
    rescue RDoc::RDocError => detail
        puts "Failed to build docs: %s" % detail
        return nil
    rescue LoadError
        puts "Missing rdoc; cannot build documentation"
        return nil
    end
end

# ====================================================================
# Create a task that will package the Rake software into distributable
# tar, zip and gem files.

PKG_FILES = FileList[
    'install.rb',
    '[A-Z]*',
    'lib/**/*.rb',
    'test/**/*.rb',
    'bin/**/*',
    'ext/**/*',
    'examples/**/*'
]
PKG_FILES.delete_if {|item| item.include?(".svn")}

if ! defined?(Gem)
    puts "Package Target requires RubyGEMs"
else
    spec = Gem::Specification.new { |s|

        #### Basic information.

        s.name = 'puppet'
        s.version = PKG_VERSION
        s.summary = "Puppet is a server configuration management tool."
        s.description = <<-EOF
Puppet is a declarative language for expressing system configuration,
a client and server for distributing it, and a library for realizing 
the configuration.
        EOF
        s.platform = Gem::Platform::RUBY

        #### Dependencies and requirements.

        # I'd love to explicitly list all of the libraries that I need,
        # but gems seem to only be able to handle dependencies on other
        # gems, which is, um, stupid.
        s.add_dependency('facter', '>= 1.1.0')
        #s.requirements << ""

        s.files = PKG_FILES.to_a

        #### Load-time details: library and application (you will need one or both).

        s.require_path = 'lib'                         # Use these for libraries.

        s.bindir = "bin"                               # Use these for applications.
        s.executables = ["puppet", "puppetd", "puppetmasterd", "puppetdoc",
                         "puppetca"]
        s.default_executable = "puppet"
        s.autorequire = 'puppet'

        #### Documentation and testing.

        s.has_rdoc = true
        #s.extra_rdoc_files = rd.rdoc_files.reject { |fn| fn =~ /\.rb$/ }.to_a
        s.rdoc_options <<
            '--title' <<  'Puppet - Configuration Management' <<
            '--main' << 'README' <<
            '--line-numbers'
        s.test_file = "test/test"

        #### Signing key and cert chain
        #s.signing_key = '/..../gem-private_key.pem'
        #s.cert_chain = ['gem-public_cert.pem']

        #### Author and project details.

        s.author = "Luke Kanies"
        s.email = "dev@reductivelabs.com"
        s.homepage = "http://reductivelabs.com/projects/puppet"
        s.rubyforge_project = "puppet"
    }

    Rake::GemPackageTask.new(spec) { |pkg|
        #pkg.need_zip = true
        pkg.need_tar = true
    }
    CLEAN.include("pkg")
end

# Misc tasks =========================================================

#ARCHIVEDIR = '/tmp'

#task :archive => [:package] do
#  cp FileList["pkg/*.tgz", "pkg/*.zip", "pkg/*.gem"], ARCHIVEDIR
#end

# Define an optional publish target in an external file.  If the
# publish.rf file is not found, the publish targets won't be defined.

#load "publish.rf" if File.exist? "publish.rf"

# Support Tasks ------------------------------------------------------

def egrep(pattern)
    Dir['**/*.rb'].each do |fn|
        count = 0
        open(fn) do |f|
            while line = f.gets
        count += 1
        if line =~ pattern
            puts "#{fn}:#{count}:#{line}"
        end
            end
        end
    end
end

desc "Look for TODO and FIXME tags in the code"
task :todo do
    egrep "/#.*(FIXME|TODO|TBD)/"
end

#desc "Look for Debugging print lines"
#task :dbg do
#  egrep /\bDBG|\bbreakpoint\b/
#end

#desc "List all ruby files"
#task :rubyfiles do 
#  puts Dir['**/*.rb'].reject { |fn| fn =~ /^pkg/ }
#  puts Dir['**/bin/*'].reject { |fn| fn =~ /svn|(~$)|(\.rb$)/ }
#end

# --------------------------------------------------------------------
# Creating a release

desc "Make a new release"
task :release => [
        :prerelease,
        :clobber,
        :update_version,
        :tag, # tag everything before we make a bunch of extra dirs
        :html,
        :package,
        :copy
      ] do
  
    announce 
    announce "**************************************************************"
    announce "* Release #{PKG_VERSION} Complete."
    announce "* Packages ready to upload."
    announce "**************************************************************"
    announce 
end

# Validate that everything is ready to go for a release.
task :prerelease do
    announce 
    announce "**************************************************************"
    announce "* Making RubyGem Release #{PKG_VERSION}"
    announce "* (current version #{CURRENT_VERSION})"
    announce "**************************************************************"
    announce  

    # Is a release number supplied?
    unless ENV['REL']
        fail "Usage: rake release REL=x.y.z [REUSE=tag_suffix]"
    end

    # Is the release different than the current release.
    # (or is REUSE set?)
    if PKG_VERSION == CURRENT_VERSION && ! ENV['REUSE']
        fail "Current version is #{PKG_VERSION}, must specify REUSE=tag_suffix to reuse version"
    end

    # Are all source files checked in?
    if ENV['RELTEST']
        announce "Release Task Testing, skipping checked-in file test"
    else
        announce "Checking for unchecked-in files..."
        data = `svn -q update`
        unless data =~ /^$/
            fail "SVN update is not clean ... do you have unchecked-in files?"
        end
        announce "No outstanding checkins found ... OK"
    end
end

task :update_version => [:prerelease] do
    if PKG_VERSION == CURRENT_VERSION
        announce "No version change ... skipping version update"
    else
        announce "Updating Puppet version to #{PKG_VERSION}"
        open("lib/puppet.rb") do |rakein|
            open("lib/puppet.rb.new", "w") do |rakeout|
                rakein.each do |line|
                    if line =~ /^\s*PUPPETVERSION\s*=\s*/
                        rakeout.puts "PUPPETVERSION = '#{PKG_VERSION}'"
                    else
                        rakeout.puts line
                    end
                end
            end
        end

        mv "lib/puppet.rb.new", "lib/puppet.rb"
        if ENV['RELTEST']
            announce "Release Task Testing, skipping commiting of new version"
        else
            sh %{svn commit -m "Updated to version #{PKG_VERSION}" lib/puppet.rb}
        end
    end
end

desc "Copy the newly created package into the downloads directory"
task :copy => [:package, :html] do
    sh %{cp pkg/puppet-#{PKG_VERSION}.gem #{DOWNDIR}/gems}
    sh %{generate_yaml_index.rb -d #{DOWNDIR}}
    sh %{cp pkg/puppet-#{PKG_VERSION}.tgz #{DOWNDIR}/puppet}
    sh %{ln -sf puppet-#{PKG_VERSION}.tgz #{DOWNDIR}/puppet/puppet-latest.tgz}
    sh %{cp -r html #{DOWNDIR}/puppet/apidocs}
end

desc "Tag all the SVN files with the latest release number (REL=x.y.z)"
task :tag => [:prerelease] do
    reltag = "REL_#{PKG_VERSION.gsub(/\./, '_')}"
    reltag << ENV['REUSE'].gsub(/\./, '_') if ENV['REUSE']
    announce "Tagging SVN copy with [#{reltag}]"
    if ENV['RELTEST']
        announce "Release Task Testing, skipping SVN tagging"
    else
        sh %{svn copy ../trunk/ ../tags/#{reltag}}
        sh %{cd ../tags; svn ci -m "Adding release tag #{reltag}"}
    end
end

desc "Test Puppet on each test host"
task :hosttest do
    out = ""
    TESTHOSTS.each { |host|
        puts "testing %s" % host
        cwd = Dir.getwd
        out += %x{ssh #{host} 'cd puppet/test; sudo ./test' 2>&1} 

        if $? != 0
            file = File.join("/tmp", "%stest.out" % host)
            File.open(file, "w") { |of| of.print out }
            puts "%s failed; output is in %s" % [host, file]
            puts out
        end
        #sh %{ssh #{host} 'cd #{cwd}/test; sudo ./test' 2>&1} 
    }

    #IO.popen("mail -s 'Puppet Test Results' luke@madstop.com") do |m|
    #    m.puts out
    #end
end

# $Id$