Permalink
Browse files

Refactoring of Rakefile and all tasks + added new versioning based on…

… SemVer specs
  • Loading branch information...
dieterdemeyer committed May 11, 2012
1 parent 9245a50 commit 301a065b40a6cdd12b3e331d40b63a25c76e1f26
View
201 Rakefile
@@ -1,204 +1,11 @@
require 'rubygems'
-require 'rake/clean'
-require 'rspec/core/rake_task'
+require 'rake'
-$:.unshift(File.join(File.dirname(__FILE__), 'build'))
-require 'rpm_packager'
-require 'deb_packager'
+task_dir = File.expand_path("../tasks", __FILE__)
-CLEAN.include("")
-CLOBBER.include("target")
+FileList["#{task_dir}/**/*.rake"].each { |fn| load fn }
-desc "Default task prints the possible targets."
+desc "Default task prints the available targets."
task :default do
sh %{rake -T}
end
-
-desc "Run puppet module RSpec tests."
-RSpec::Core::RakeTask.new(:spec) do |t|
- t.rspec_opts = ["--format", "doc", "--color"]
- t.fail_on_error = false
- t.pattern = 'spec/**/*_spec.rb'
-end
-
-desc "Run puppet module acceptance tests."
-task :acceptance do
- puts "Running acceptance tests..."
- # cucumber ? cucumber-puppet
-end
-
-desc "Check puppet module syntax."
-task :syntax do
- begin
- require 'puppet/face'
- rescue LoadError
- fail 'Cannot load puppet/face, are you sure you have Puppet 2.7?'
- end
-
- def validate_manifest(file)
- begin
- Puppet::Face[:parser, '0.0.1'].validate(file)
- rescue Puppet::Error => error
- puts error.message
- end
- end
-
- puts "Checking puppet module syntax..."
- FileList['**/*.pp'].each do |manifest|
- puts "Evaluating syntax for #{manifest}"
- validate_manifest manifest
- end
-end
-
-desc "Check puppet module code style."
-task :style do
- begin
- require 'puppet-lint'
- rescue LoadError
- fail 'Cannot load puppet-lint, did you install it?'
- end
-
- puts "Checking puppet module code style..."
- linter = PuppetLint.new
- linter.configuration.log_format = '%{path}:%{linenumber}:%{check}:%{KIND}:%{message}'
- linter.configuration.send("disable_80chars")
-
- FileList['**/*.pp'].each do |puppet_file|
- puts "Evaluating code style for #{puppet_file}"
- linter.file = puppet_file
- linter.run
- end
- fail if linter.errors?
-end
-
-# TODO: Reevaluate this when/if it becomes available in Puppet Faces
-desc "Create puppet module documentation."
-task :doc do
- output_dir = "target/doc"
- manifest_dir = "target/manifests"
-
- if File.directory?(output_dir)
- FileUtils.rm_r output_dir
- end
- if File.directory?(manifest_dir)
- FileUtils.rm_r manifest_dir
- end
- FileUtils.mkdir_p manifest_dir
-
- puts "Generating puppet module documentation..."
- FileUtils.mkdir_p("target/manifests")
- sh %{puppet doc --mode rdoc --manifestdir target/manifests/ --modulepath ../ --outputdir target/doc}
-
- work_dir = File.dirname(__FILE__)
- parent_dir = File.dirname(work_dir)
-
- if File.exists? "#{work_dir}/target/doc/files/#{work_dir}"
- FileUtils.mv "#{work_dir}/target/doc/files/#{work_dir}", "#{work_dir}/target/doc/files"
- end
-
- FileList['target/doc/**/*.html'].egrep(%r(#{parent_dir})) do |fn,line,match|
- text = File.read(fn)
- replace = text.gsub(%r(#{parent_dir}), "")
- File.open(fn, "w") { |file| file.puts replace }
- end
-
- FileList['target/doc/files/**/*_pp.html'].egrep(/rdoc-style\.css/) do |fn,line,match|
- depth_in_doc = fn.split(/\//).length - 3
- original_string = /[\.\/]*rdoc-style.css/
- replacement_string = '../' * depth_in_doc + 'rdoc-style.css'
- text = File.read(fn)
- replace = text.gsub(original_string, replacement_string)
- File.open(fn, "w") { |file| file.puts replace }
- end
-end
-
-desc "Create RPM package from puppet module."
-task :rpm do
- puts "Creating RPM package from puppet module..."
- module_name = ENV["JOB_NAME"].split('-')[1]
-
- rpm_packager = RpmPackager.new
- output = rpm_packager.build(module_name)
- puts output
-end
-
-desc "Create DEB package from puppet module."
-task :deb do
- puts "Creating DEB package from puppet module..."
- module_name = ENV["JOB_NAME"].split('-')[1]
-
- deb_packager = DebPackager.new
- output = deb_packager.build(module_name)
- puts output
-end
-
-desc "Create a puppet module, compatible with Puppet Forge."
-task :build do
- begin
- require 'puppet/face'
- rescue LoadError
- fail 'Cannot load puppet/face, are you sure you have Puppet 2.7?'
- end
-
- puts "Creating puppet module for Puppet Forge..."
- # puppet module build / upload to forge
- #Puppet::Face[:module, '1.0.0'].build()
-end
-
-desc "Create a version tag for the current commit."
-task :tag, [:version] do |t,args|
- puts "Tagging version #{args.version}"
- # git tag
- # deal with ChangeLog
-end
-
-desc "Create a puppet module release for the provided version."
-task :release, [:version] => [:tag] do |t,args|
- puts "Releasing version #{args.version}"
- # checkout tag / build rpm/deb/forge package
-end
-
-namespace "jenkins" do
- begin
- require 'ci/reporter/rake/rspec'
- require 'ci/reporter/rake/cucumber'
- rescue LoadError
- fail 'Cannot load ci_reporter, did you install it?'
- end
-
- SPEC_REPORTS_PATH = "target/reports/spec/"
- ACCEPTANCE_REPORTS_PATH = "target/reports/acceptance/"
-
- desc "Run Jenkins compatible Rspec tests."
- task :spec_tests => ["ci:setup:rspec"] do
- ENV["CI_REPORTS"] = SPEC_REPORTS_PATH
- FileUtils.mkdir_p(SPEC_REPORTS_PATH)
-
- Rake::Task[:spec].invoke
- end
-
- desc "Run Jenkins compatible acceptance tests."
- task :acceptance_tests => ["ci:setup:cucumber"] do
- ENV["CI_REPORTS"] = ACCEPTANCE_REPORTS_PATH
- FileUtils.mkdir_p(ACCEPTANCE_REPORTS_PATH)
-
- Rake::Task[:acceptance].invoke
- end
-
- desc "Archive job configuration in YAML format."
- task :archive_job_configuration do
- dist_dir = "target/dist"
-
- module_name = ENV["JOB_NAME"]
- git_commit = ENV["GIT_COMMIT"]
-
- if !git_commit.nil? and !git_commit.empty?
- puts "Saving #{module_name}.yaml file"
- FileUtils.mkdir_p(dist_dir)
- open("target/dist/#{module_name}.yaml", "w") { |file|
- file.puts "module_name: #{module_name}"
- file.puts "git_commit: #{git_commit}"
- }
- end
- end
-end
View
@@ -1,12 +0,0 @@
-/*
-+-----------------------------------------------------------------------+
-| |
-| ==> DO NOT EDIT THIS FILE! <== |
-| |
-| You should edit the `Modulefile` and run `puppet-module build` |
-| to generate the `metadata.json` file for your releases. |
-| |
-+-----------------------------------------------------------------------+
-*/
-
-{}
View
@@ -0,0 +1,8 @@
+source :rubygems
+
+gem 'rake'
+gem 'rspec'
+gem 'rspec-puppet'
+gem 'ci_reporter'
+gem 'puppet-lint'
+gem 'fpm', '<=0.3.11'
View
@@ -0,0 +1,16 @@
+# This file contains the environment configuration shared by all
+# tasks. It should be required at the top of each *.rake file with:
+#
+# require File.expand_path('../../env', __FILE__)
+
+# Sync all stdout/stderr to play nice with buildtools
+# running the rake tasks.
+$stdout.sync = true
+$stderr.sync = true
+
+# Module root directory
+MODULE_ROOT_DIR = Rake.original_dir
+
+# Basedir for all output.
+RESULTS = ENV['results'] || 'target'
+
View
@@ -0,0 +1,6 @@
+require 'rake/clean'
+
+require File.expand_path('../../env', __FILE__)
+
+CLEAN.include("")
+CLOBBER.include("#{RESULTS}")
View
@@ -0,0 +1,14 @@
+require File.expand_path('../../env', __FILE__)
+
+$:.unshift(File.join(File.dirname(__FILE__), 'lib', 'packaging'))
+require 'deb_packager'
+
+desc "Create DEB package from puppet module."
+task :deb do
+ puts "Creating DEB package from puppet module..."
+ module_name = ENV['JOB_NAME'].split('-')[1]
+
+ deb_packager = DebPackager.new
+ output = deb_packager.build(module_name)
+ puts output
+end
View
@@ -0,0 +1,47 @@
+require File.expand_path('../../env', __FILE__)
+
+task :doc_prep do
+ output_dir = "#{RESULTS}/doc"
+ manifest_dir = "#{RESULTS}/manifests"
+
+ if File.directory?(output_dir)
+ FileUtils.rm_r output_dir
+ end
+ if File.directory?(manifest_dir)
+ FileUtils.rm_r manifest_dir
+ end
+ FileUtils.mkdir_p manifest_dir
+end
+
+# TODO: Revisit this when/if it becomes available in Puppet Faces
+desc "Create puppet module documentation."
+task :doc => [:doc_prep] do
+ puts "Generating puppet module documentation..."
+
+ output_dir = "#{RESULTS}/doc"
+ manifest_dir = "#{RESULTS}/manifests"
+
+ sh %{puppet doc --mode rdoc --manifestdir #{manifest_dir} --modulepath ../ --outputdir #{output_dir}}
+
+ work_dir = File.dirname(__FILE__)
+ parent_dir = File.dirname(work_dir)
+
+ if File.directory? "#{output_dir}/files/#{work_dir}"
+ FileUtils.mv "#{output_dir}/files/#{work_dir}", "#{output_dir}/files"
+ end
+
+ FileList["#{output_dir}/**/*.html"].each do |fn|
+ text = File.read(fn)
+ replace = text.gsub(%r(#{parent_dir}), "")
+ File.open(fn, "w") { |file| file.puts replace }
+ end
+
+ FileList["#{output_dir}/files/**/*_pp.html"].each do |fn|
+ depth_below_doc = fn.split(/\//).length - 3
+ original_string = /[\.\/]*rdoc-style.css/
+ replacement_string = '../' * depth_below_doc + 'rdoc-style.css'
+ text = File.read(fn)
+ replace = text.gsub(original_string, replacement_string)
+ File.open(fn, "w") { |file| file.puts replace }
+ end
+end
View
@@ -0,0 +1,46 @@
+require File.expand_path('../../env', __FILE__)
+
+namespace "jenkins" do
+ begin
+ require 'ci/reporter/rake/rspec'
+ require 'ci/reporter/rake/cucumber'
+ rescue LoadError
+ fail 'Cannot load ci_reporter, did you install it?'
+ end
+
+ SPEC_REPORTS_PATH = "#{RESULTS}/reports/spec/"
+ ACCEPTANCE_REPORTS_PATH = "#{RESULTS}/reports/acceptance/"
+
+ desc "Run Jenkins compatible Rspec tests."
+ task :spec_tests => ["ci:setup:rspec"] do
+ ENV['CI_REPORTS'] = SPEC_REPORTS_PATH
+ FileUtils.mkdir_p(SPEC_REPORTS_PATH)
+
+ Rake::Task[:spec].invoke
+ end
+
+ desc "Run Jenkins compatible acceptance tests."
+ task :acceptance_tests => ["ci:setup:cucumber"] do
+ ENV['CI_REPORTS'] = ACCEPTANCE_REPORTS_PATH
+ FileUtils.mkdir_p(ACCEPTANCE_REPORTS_PATH)
+
+ Rake::Task[:acceptance].invoke
+ end
+
+ desc "Archive job configuration in YAML format."
+ task :archive_job_configuration do
+ dist_dir = "#{RESULTS}/dist"
+
+ module_name = ENV['JOB_NAME']
+ git_commit = ENV['GIT_COMMIT']
+
+ if !git_commit.nil? and !git_commit.empty?
+ puts "Saving #{module_name}.yaml file"
+ FileUtils.mkdir_p(dist_dir)
+ open("#{dist_dir}/#{module_name}.yaml", "w") { |file|
+ file.puts "module_name: #{module_name}"
+ file.puts "git_commit: #{git_commit}"
+ }
+ end
+ end
+end
@@ -0,0 +1,18 @@
+require File.expand_path('../../../env', __FILE__)
+
+class ModulefileReader
+
+ def initialize()
+ filename = File.join(MODULE_ROOT_DIR, 'Modulefile')
+ @module_file = File.read(filename)
+ end
+
+ def version
+ @module_file.each_line do |line|
+ if line.match(/version/)
+ return line.split(' ')[1].gsub("'", "")
+ end
+ end
+ end
+
+end
Oops, something went wrong.

0 comments on commit 301a065

Please sign in to comment.