-
Notifications
You must be signed in to change notification settings - Fork 16
/
Rakefile
158 lines (137 loc) · 4.25 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
require 'rake/clean'
require 'date'
task default: :test
ROOTDIR = File.expand_path(__dir__).sub(/#{Dir.pwd}(?=\/)/, '.')
LIBDIR = "#{ROOTDIR}/lib".freeze
BINDIR = "#{ROOTDIR}/bin".freeze
desc 'Set up environment'
task :environment do
$LOAD_PATH.unshift ROOTDIR unless $LOAD_PATH.include?(ROOTDIR)
$LOAD_PATH.unshift LIBDIR unless $LOAD_PATH.include?(LIBDIR)
require_library 'nokogiri'
require_library 'kramdown'
ENV['RUBYLIB'] = $LOAD_PATH.join(':')
ENV['PATH'] = "#{BINDIR}:#{ENV.fetch('PATH', nil)}"
end
desc 'Run tests'
task test: :environment do
$LOAD_PATH.unshift "#{ROOTDIR}/test"
Dir['test/test_*.rb'].sort.each { |f| require(f) }
end
desc 'Start the server'
task server: :environment do
if system('type shotgun >/dev/null 2>&1')
exec 'shotgun config.ru'
else
require 'ronn/server'
Ronn::Server.run('man/*.ronn')
end
end
desc 'Build the manual'
task man: :environment do
require 'ronn'
ENV['RONN_MANUAL'] = 'Ronn Manual'
ENV['RONN_ORGANIZATION'] = "Ronn-NG #{Ronn.revision}"
sh 'ronn -w -s toc -r5 --markdown man/*.ronn'
end
desc 'Publish to GitHub pages'
task pages: :man do
puts '----------------------------------------------'
puts 'Rebuilding pages ...'
verbose(false) do
rm_rf 'pages'
push_url = `git remote show origin`.grep(/Push.*URL/).first[/git@.*/]
sh "
set -e
git fetch -q origin
rev=$(git rev-parse origin/gh-pages)
git clone -q -b gh-pages . pages
cd pages
git reset --hard $rev
rm -f ronn*.html index.html
cp -rp ../man/ronn*.html ../man/index.txt ../man/index.html ./
git add -u ronn*.html index.html index.txt
git commit -m 'rebuild manual'
git push #{push_url} gh-pages
", verbose: false
end
end
# PACKAGING ============================================================
# Rev Ronn::VERSION
desc 'Bump package version'
task :rev do
rev = ENV['REV'] || `git describe --tags`.chomp
data = File.read('lib/ronn.rb')
data.gsub!(/^( *)REV *=.*/, "\\1REV = '#{rev.sub(/\Av/, '')}'.freeze")
File.binwrite('lib/ronn.rb', data)
puts "revision: #{rev}"
puts "version: #{`ruby -Ilib -rronn -e 'puts Ronn::VERSION'`}"
end
require 'rubygems'
@spec = eval(File.read('ronn-ng.gemspec'))
def package(ext = '')
"pkg/ronn-ng-#{@spec.version}" + ext
end
desc 'Build packages'
task package: %w[.gem .tar.gz].map { |ext| package(ext) }
desc 'Build and install as local gem'
task install: package('.gem') do
sh "gem install #{package('.gem')}"
end
directory 'pkg/'
CLOBBER.include('pkg')
file package('.gem') => %w[pkg/ ronn-ng.gemspec] + @spec.files do |f|
sh 'gem build ronn-ng.gemspec'
mv File.basename(f.name), f.name
end
file package('.tar.gz') => %w[pkg/] + @spec.files do |f|
sh <<-SH
git archive --prefix=ronn-#{source_version}/ --format=tar HEAD |
gzip > #{f.name}
SH
end
def source_version
@source_version ||= `ruby -Ilib -rronn -e 'puts Ronn::VERSION'`.chomp
end
file 'ronn-ng.gemspec' => FileList['{lib,test,bin}/**', 'Rakefile'] do |f|
# read spec file and split out manifest section
spec = File.read(f.name)
head, _manifest, tail = spec.split(" # = MANIFEST =\n")
# replace version and date
head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
head.sub!(/\.date = '.*'/, ".date = '#{Date.today}'")
# determine file list from git ls-files
files = `git ls-files`
.split("\n")
.sort
.grep_v(/^\./)
# .reject { |file| file =~ /^\./ }
.grep_v(/^doc/)
# .reject { |file| file =~ /^doc/ }
.map { |file| " #{file}" }
.join("\n")
# piece file back together and write...
manifest = " s.files = %w[\n#{files}\n ]\n"
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
File.write(f.name, spec)
puts "updated #{f.name}"
end
# Misc ===============================================================
def require_library(name)
require name
rescue LoadError => e
unless defined?(Gem)
warn "warn: #{e}. trying again with rubygems."
require 'rubygems'
retry
end
abort "fatal: the '#{name}' library is required (gem install #{name})"
end
# make .wrong test files right
desc 'Mark *.wrong test files as right'
task :right do
Dir['test/*.wrong'].each do |file|
dest = file.sub(/\.wrong$/, '')
mv file, dest
end
end