2011-11-18 23:13:04 +00:00
|
|
|
require 'bundler/setup'
|
2011-11-12 22:04:59 +00:00
|
|
|
require 'bundler/gem_tasks'
|
2010-12-13 22:28:59 +00:00
|
|
|
require 'rspec/core/rake_task'
|
2011-05-25 18:38:07 +00:00
|
|
|
require 'appraisal'
|
2014-04-04 17:11:46 +00:00
|
|
|
require 'erb'
|
|
|
|
require_relative 'lib/shoulda/matchers/version'
|
|
|
|
|
2014-10-27 00:51:42 +00:00
|
|
|
RSpec::Core::RakeTask.new('spec:unit') do |t|
|
2014-06-27 22:39:39 +00:00
|
|
|
t.ruby_opts = '-w -r ./spec/report_warnings'
|
2014-10-27 00:51:42 +00:00
|
|
|
t.pattern = "spec/unit/**/*_spec.rb"
|
2010-12-14 23:35:12 +00:00
|
|
|
t.rspec_opts = '--color --format progress'
|
|
|
|
t.verbose = false
|
2010-12-13 22:28:59 +00:00
|
|
|
end
|
|
|
|
|
2014-10-27 00:52:55 +00:00
|
|
|
RSpec::Core::RakeTask.new('spec:acceptance') do |t|
|
|
|
|
t.ruby_opts = '-w -r ./spec/report_warnings'
|
|
|
|
t.pattern = "spec/acceptance/**/*_spec.rb"
|
|
|
|
t.rspec_opts = '--color --format progress'
|
|
|
|
t.verbose = false
|
|
|
|
end
|
|
|
|
|
2014-01-20 18:35:10 +00:00
|
|
|
task :default do
|
2013-03-04 21:10:54 +00:00
|
|
|
if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
|
2014-10-27 00:51:42 +00:00
|
|
|
sh 'rake spec:unit'
|
2014-10-27 00:54:55 +00:00
|
|
|
sh 'rake spec:acceptance'
|
2013-03-04 21:10:54 +00:00
|
|
|
else
|
2014-01-20 18:35:10 +00:00
|
|
|
Rake::Task['appraise'].invoke
|
2013-03-04 21:10:54 +00:00
|
|
|
end
|
2011-05-25 18:38:07 +00:00
|
|
|
end
|
2012-04-10 04:06:09 +00:00
|
|
|
|
2014-01-20 18:39:18 +00:00
|
|
|
task :appraise do
|
|
|
|
exec 'appraisal install && appraisal rake'
|
2013-03-04 21:10:54 +00:00
|
|
|
end
|
2014-04-04 17:11:46 +00:00
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
CURRENT_VERSION = Shoulda::Matchers::VERSION
|
2014-04-04 17:11:46 +00:00
|
|
|
GH_PAGES_DIR = '.gh-pages'
|
2015-01-23 18:40:43 +00:00
|
|
|
# GITHUB_USERNAME = 'thoughtbot'
|
|
|
|
GITHUB_USERNAME = 'mcmire'
|
2014-04-04 17:11:46 +00:00
|
|
|
|
|
|
|
namespace :docs do
|
|
|
|
file GH_PAGES_DIR do
|
2015-01-23 18:40:43 +00:00
|
|
|
create_reference_to_gh_pages_branch
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
task :setup => GH_PAGES_DIR do
|
2015-01-23 18:40:43 +00:00
|
|
|
reset_repo_directory
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Generate docs for a particular version'
|
|
|
|
task :generate, [:version, :latest_version] => :setup do |t, args|
|
2015-01-23 18:40:43 +00:00
|
|
|
generate_docs_for(args.version, latest_version: latest_version)
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Generate docs for a particular version and push them to GitHub'
|
|
|
|
task :publish, [:version, :latest_version] => :setup do |t, args|
|
2015-01-23 18:40:43 +00:00
|
|
|
generate_docs_for(args.version, latest_version: latest_version)
|
|
|
|
publish_docs_for(args.version, latest_version: latest_version)
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
desc "Generate docs for version #{CURRENT_VERSION} and push them to GitHub"
|
|
|
|
task :publish_latest => :setup do
|
|
|
|
version = Gem::Version.new(CURRENT_VERSION)
|
2015-01-23 18:40:43 +00:00
|
|
|
options = {}
|
2014-04-04 17:11:46 +00:00
|
|
|
|
|
|
|
unless version.prerelease?
|
2015-01-23 18:40:43 +00:00
|
|
|
options[:latest_version] = version.to_s
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
generate_docs_for(CURRENT_VERSION, options)
|
|
|
|
publish_docs_for(CURRENT_VERSION, options)
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_reference_to_gh_pages_branch
|
|
|
|
sh "git clone git@github.com:#{GITHUB_USERNAME}/shoulda-matchers.git #{GH_PAGES_DIR} --branch gh-pages"
|
|
|
|
end
|
|
|
|
|
|
|
|
def reset_repo_directory
|
|
|
|
within_gh_pages_dir do
|
|
|
|
sh 'git fetch origin'
|
|
|
|
sh 'git reset --hard origin/gh-pages'
|
|
|
|
end
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
def add_version_to_index_page_for(ref, version)
|
|
|
|
within_gh_pages_dir do
|
2014-04-04 17:11:46 +00:00
|
|
|
filename = "#{ref}/index.html"
|
|
|
|
content = File.read(filename)
|
|
|
|
content.sub!(%r{<h1>shoulda-matchers.+</h1>}, "<h1>shoulda-matchers (#{version})</h1>")
|
|
|
|
File.open(filename, 'w') {|f| f.write(content) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
def generate_docs_for(version, options = {})
|
2014-04-04 17:11:46 +00:00
|
|
|
ref = determine_ref_from(version)
|
|
|
|
|
|
|
|
sh "rm -rf #{GH_PAGES_DIR}/#{ref}"
|
|
|
|
sh "bundle exec yard -o #{GH_PAGES_DIR}/#{ref}"
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
add_version_to_index_page_for(ref, version)
|
2014-04-04 17:11:46 +00:00
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
within_gh_pages_dir do
|
2014-09-03 06:44:06 +00:00
|
|
|
sh "git add #{ref}"
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if options[:latest_version]
|
|
|
|
generate_file_that_redirects_to_latest_version(options[:latest_version])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
def publish_docs_for(version, options = {})
|
2014-04-04 17:11:46 +00:00
|
|
|
message = build_commit_message(version)
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
within_gh_pages_dir do
|
2014-04-04 17:11:46 +00:00
|
|
|
sh 'git clean -f'
|
|
|
|
sh "git commit -m '#{message}'"
|
2015-01-23 18:40:43 +00:00
|
|
|
sh 'git push origin gh-pages'
|
2014-04-04 17:11:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_file_that_redirects_to_latest_version(version)
|
|
|
|
ref = determine_ref_from(version)
|
|
|
|
locals = { ref: ref }
|
|
|
|
|
|
|
|
erb = ERB.new(File.read('doc_config/gh-pages/index.html.erb'))
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
within_gh_pages_dir do
|
2014-04-04 17:11:46 +00:00
|
|
|
File.open('index.html', 'w') { |f| f.write(erb.result(binding)) }
|
|
|
|
sh 'git add index.html'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def determine_ref_from(version)
|
|
|
|
if version =~ /^\d+\.\d+\.\d+/
|
|
|
|
'v' + version
|
|
|
|
else
|
|
|
|
version
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_commit_message(version)
|
|
|
|
"Regenerated docs for version #{version}"
|
|
|
|
end
|
|
|
|
|
2015-01-23 18:40:43 +00:00
|
|
|
def within_gh_pages_dir(&block)
|
2014-04-04 17:11:46 +00:00
|
|
|
Dir.chdir(GH_PAGES_DIR, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task release: 'docs:publish_latest'
|