forked from thoughtbot/shoulda-matchers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
139 lines (111 loc) · 3.53 KB
/
Rakefile
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
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'appraisal'
require 'erb'
require_relative 'lib/shoulda/matchers/version'
CURRENT_VERSION = Shoulda::Matchers::VERSION
RSpec::Core::RakeTask.new('spec:unit') do |t|
t.ruby_opts = '-w -r ./spec/report_warnings'
t.pattern = "spec/unit/**/*_spec.rb"
t.rspec_opts = '--color --format progress'
t.verbose = false
end
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
task :default do
if ENV['BUNDLE_GEMFILE'] =~ /gemfiles/
sh 'rake spec:unit'
sh 'rake spec:acceptance'
else
Rake::Task['appraise'].invoke
end
end
task :appraise do
exec 'appraisal install && appraisal rake'
end
GH_PAGES_DIR = '.gh-pages'
namespace :docs do
file GH_PAGES_DIR do
sh "git clone [email protected]:thoughtbot/shoulda-matchers.git #{GH_PAGES_DIR} --branch gh-pages"
end
task :setup => GH_PAGES_DIR do
within_gh_pages do
sh 'git fetch origin'
sh 'git reset --hard origin/gh-pages'
end
end
desc 'Generate docs for a particular version'
task :generate, [:version, :latest_version] => :setup do |t, args|
generate_docs(args.version, latest_version: latest_version)
end
desc 'Generate docs for a particular version and push them to GitHub'
task :publish, [:version, :latest_version] => :setup do |t, args|
generate_docs(args.version, latest_version: latest_version)
publish_docs(args.version, latest_version: latest_version)
end
desc "Generate docs for version #{CURRENT_VERSION} and push them to GitHub"
task :publish_latest => :setup do
version = Gem::Version.new(CURRENT_VERSION)
unless version.prerelease?
latest_version = version.to_s
end
generate_docs(CURRENT_VERSION, latest_version: latest_version)
publish_docs(CURRENT_VERSION, latest_version: latest_version)
end
def rewrite_index_to_inject_version(ref, version)
within_gh_pages do
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
def generate_docs(version, options = {})
ref = determine_ref_from(version)
sh "rm -rf #{GH_PAGES_DIR}/#{ref}"
sh "bundle exec yard -o #{GH_PAGES_DIR}/#{ref}"
rewrite_index_to_inject_version(ref, version)
within_gh_pages do
sh "git add #{ref}"
end
if options[:latest_version]
generate_file_that_redirects_to_latest_version(options[:latest_version])
end
end
def publish_docs(version, options = {})
message = build_commit_message(version)
within_gh_pages do
sh 'git clean -f'
sh "git commit -m '#{message}'"
sh 'git push'
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'))
within_gh_pages do
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
def within_gh_pages(&block)
Dir.chdir(GH_PAGES_DIR, &block)
end
end
task release: 'docs:publish_latest'