-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathRakefile
155 lines (123 loc) · 4.2 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
require "shellwords"
AVAILABLE_VERSIONS = %w(3.1 3.2 3.3 3.4).map(&:freeze).freeze
def version
@version ||= case (v = ENV.fetch("VERSION", nil))
when *AVAILABLE_VERSIONS
v
else
raise "!!! Please specify VERSION (#{AVAILABLE_VERSIONS.join(", ")}) !!!"
end
end
def root
__dir__
end
def sha1
`cd #{root.shellescape}/build/doctree && git log -n 1 --format=format:%H`.strip
end
def tarball_name
"Ruby-#{version}-ja.tgz"
end
def s3_endpoint
ENV["S3_ENDPOINT"] || "s3.amazonaws.com"
end
# s3 にアップロードする際の prefix。
# 通常 doctree の sha1 だが、doctree の更新を待たずに docset を更新したい場合に環境変数 BUILD を指定する。
def s3_prefix
[sha1, ENV.fetch("BUILD", nil)].compact.join("-")
end
task :clone do
unless File.exist? "build/doctree"
sh "git clone https://github.com/rurema/doctree.git build/doctree"
end
end
task :pull => :clone do
sh "cd build/doctree && git pull"
end
task :generate_html => :pull do
if File.exist?("html/#{version}/REVISION") &&
File.read("html/#{version}/REVISION").strip == sha1
next
end
outputdir = File.expand_path("html/#{version}")
rm_rf outputdir
mkdir_p "#{outputdir}/function"
mkdir_p "#{outputdir}/json"
database = File.expand_path("#{outputdir}/../db-#{version}")
stdlibtree = File.expand_path("build/doctree/refm/api/src")
capipaths = Dir.glob("build/doctree/refm/capi/src/*")
bitclust = "bundle exec bitclust --database=#{database.shellescape}"
sh "#{bitclust} init version=#{version} encoding=utf-8"
sh "#{bitclust} update --stdlibtree=#{stdlibtree.shellescape}"
sh "#{bitclust} --capi update #{capipaths.collect(&:shellescape).join(" ")}"
sh "#{bitclust} statichtml --outputdir=#{outputdir.shellescape}"
sh "echo #{sha1} > #{outputdir.shellescape}/REVISION"
rm_rf database
end
task :add_original_url => :generate_html do
next if File.read("html/#{version}/doc/index.html")[%(<html lang="ja-JP"><!-- Online page at http://docs.ruby-lang.org/ja/#{version}/doc/index.html -->)]
ruby "add_original_url.rb #{version}"
end
task :generate_docsets => :add_original_url do
revision_file = "docsets/Ruby #{version}-ja.docset/REVISION"
if File.exist?(revision_file) && File.read(revision_file).strip == (sha1)
next
end
ruby "generate_docsets.rb #{version}"
docset_file = "docsets/Ruby #{version}-ja.docset/Contents/Resources/docSet.dsidx"
sh %(echo 'PRAGMA journal_mode=delete' | sqlite3 #{docset_file.shellescape})
sh "echo #{sha1} > #{revision_file.shellescape}"
end
task :clean_docsets do
rm_rf "docsets/Ruby #{version}-ja.docset"
end
task :install => :generate_docsets do
source = "docsets/Ruby #{version}-ja.docset"
dest = "#{Dir.home}/Library/Application Support/Dash/DocSets/Ruby #{version}-ja"
rm_rf dest
mkdir_p dest
cp_r source, dest
end
task :uninstall do
dest = "#{Dir.home}/Library/Application Support/Dash/DocSets/Ruby #{version}-ja"
rm_rf dest
end
task :tarball => [:generate_docsets, :feed] do
source = "docsets/Ruby #{version}-ja.docset"
dest = "tarball/#{tarball_name}"
rm_f dest
mkdir_p File.dirname(dest)
loop do
break if File.exist?("#{source}/Contents/Resources/docSet.dsidx")
sleep 1
end
sh "tar --exclude='.DS_Store' -czf #{dest.shellescape} #{source.shellescape}"
end
task :feed => :generate_docsets do
mkdir_p "tarball"
url = "https://#{s3_endpoint}/rubydoc-ja-docsets/#{s3_prefix}/#{tarball_name}"
open("tarball/Ruby-#{version}-ja.xml", "w") {|f|
f.write %(<entry><version>#{s3_prefix}</version><url>#{url}</url></entry>)
}
end
task :release => :tarball do
require "aws"
s3 = Aws::S3.new(ENV.fetch("AWS_ACCESS_KEY_ID"), ENV.fetch("AWS_SECRET_ACCESS_KEY"), server: s3_endpoint)
bucket = s3.bucket("rubydoc-ja-docsets")
if bucket.key("#{s3_prefix}/#{tarball_name}").exists?
puts "Already uploaded"
next
end
open("tarball/#{tarball_name}", "rb:ascii-8bit") do |file|
puts "Uploading... tarball/#{tarball_name}"
bucket.put "#{s3_prefix}/#{tarball_name}", file, {}, "public-read", "content-type" => "application/x-compressed"
end
end
task :server do
ruby "-run", "-e", "httpd", "--", "gh-pages"
end
task :clean do
rm_rf "build"
rm_rf "docsets"
rm_rf "html"
rm_rf "tarball/*.tgz"
end