Skip to content

Commit f7e4ec2

Browse files
committed
Merge pull request #3 from nhr/initial_build_system
Initial build system
2 parents 74445de + cdcd357 commit f7e4ec2

File tree

13 files changed

+1840
-0
lines changed

13 files changed

+1840
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.html
2+
_package
3+
_preview

_build_cfg.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# This configuration file dictates the organization of the topic groups and
2+
# topics on the main page of the doc site for this branch. Each record
3+
# consists of the following:
4+
#
5+
# --- <= Record delimiter
6+
# Name: Origin of the Species <= Display name of topic group
7+
# Dir: origin_of_the_species <= Directory name of topic group
8+
# Topics:
9+
# - Name: The Majestic Marmoset <= Topic name
10+
# File: the_majestic_marmoset <= Topic file under group dir +/- .adoc
11+
# - Name: The Curious Crocodile <= Topic 2 name
12+
# File: the_curious_crocodile <= Topic 2 file
13+
#
14+
# The ordering of the records in this document determines the ordering of the
15+
# topic groups and topics on the main page.
16+
---
17+
Name: Installing Client Tools
18+
Dir: client_tools_install_guide
19+
Topics:
20+
- Name: On Fedora
21+
File: installing_client_tools_on_fedora
22+
- Name: On OS X
23+
File: installing_client_tools_on_macosx
24+
- Name: On openSUSE
25+
File: installing_client_tools_on_opensuse
26+
- Name: On RHEL / CentOS
27+
File: installing_client_tools_on_rhel
28+
- Name: On Debian / Ubuntu
29+
File: installing_client_tools_on_ubuntu_debian
30+
- Name: On Windows
31+
File: installing_client_tools_on_windows
32+
- Name: Configuring Client Tools
33+
File: configuring_client_tools
34+
- Name: Updating Client Tools
35+
File: updating_client_tools

_build_system/Gemfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
source "https://rubygems.org"
2+
3+
gem 'asciidoctor'
4+
gem 'guard'
5+
gem 'guard-shell'
6+
gem 'guard-livereload'
7+
gem 'haml'
8+
gem 'pandoc-ruby'
9+
gem 'rake'
10+
gem 'yajl-ruby'

_build_system/Gemfile.lock

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
asciidoctor (0.1.4)
5+
celluloid (0.15.2)
6+
timers (~> 1.1.0)
7+
coderay (1.1.0)
8+
em-websocket (0.5.1)
9+
eventmachine (>= 0.12.9)
10+
http_parser.rb (~> 0.6.0)
11+
eventmachine (1.0.3)
12+
ffi (1.9.3)
13+
formatador (0.2.5)
14+
guard (2.6.1)
15+
formatador (>= 0.2.4)
16+
listen (~> 2.7)
17+
lumberjack (~> 1.0)
18+
pry (>= 0.9.12)
19+
thor (>= 0.18.1)
20+
guard-livereload (2.3.0)
21+
em-websocket (~> 0.5)
22+
guard (~> 2.0)
23+
multi_json (~> 1.8)
24+
guard-shell (0.6.1)
25+
guard (>= 1.1.0)
26+
haml (4.0.5)
27+
tilt
28+
http_parser.rb (0.6.0)
29+
listen (2.7.9)
30+
celluloid (>= 0.15.2)
31+
rb-fsevent (>= 0.9.3)
32+
rb-inotify (>= 0.9)
33+
lumberjack (1.0.9)
34+
method_source (0.8.2)
35+
multi_json (1.10.1)
36+
pandoc-ruby (0.7.5)
37+
pry (0.10.0)
38+
coderay (~> 1.1.0)
39+
method_source (~> 0.8.1)
40+
slop (~> 3.4)
41+
rake (10.3.2)
42+
rb-fsevent (0.9.4)
43+
rb-inotify (0.9.5)
44+
ffi (>= 0.5.0)
45+
slop (3.6.0)
46+
thor (0.19.1)
47+
tilt (2.0.1)
48+
timers (1.1.0)
49+
yajl-ruby (1.2.1)
50+
51+
PLATFORMS
52+
ruby
53+
54+
DEPENDENCIES
55+
asciidoctor
56+
guard
57+
guard-livereload
58+
guard-shell
59+
haml
60+
pandoc-ruby
61+
rake
62+
yajl-ruby

_build_system/Guardfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
require 'asciidoctor'
2+
require 'erb'
3+
require 'haml'
4+
require 'tilt'
5+
6+
guard 'shell' do
7+
watch(/^.*\.adoc$/) {|m|
8+
Asciidoctor.render_file m[0], :in_place => true, :safe => :safe, :template_dir => './templates', :attributes => %w(source-highlighter=coderay coderay-css=style stylesdir=./stylesheets imagesdir=./images stylesheet=origin.css linkcss! icons=font idprefix= idseparator=- sectanchors)
9+
}
10+
end
11+
12+
guard 'livereload' do
13+
watch(%r{^.+\.(css|js|html)$})
14+
end

_build_system/Rakefile

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
require 'asciidoctor'
2+
require 'pandoc-ruby'
3+
require 'pathname'
4+
require 'rake'
5+
require 'yaml'
6+
7+
BUILD_FILENAME = '_build_cfg.yml'
8+
BUILDER_DIRNAME = '_build_system'
9+
PREVIEW_DIRNAME = '_preview'
10+
PACKAGE_DIRNAME = '_package'
11+
BLANK_STRING_RE = Regexp.new('^\s*$')
12+
13+
def source_dir
14+
@source_dir ||= File.expand_path('..',Dir.pwd)
15+
end
16+
17+
def builder_dir
18+
@builder_dir = File.join(source_dir,BUILDER_DIRNAME)
19+
end
20+
21+
def builder_template_dir
22+
@builder_template_dir ||= File.join(builder_dir,'templates')
23+
end
24+
25+
def preview_dir
26+
@preview_dir ||= begin
27+
preview_dir = File.join(source_dir,PREVIEW_DIRNAME)
28+
if not File.exists?(preview_dir)
29+
Dir.mkdir(preview_dir)
30+
end
31+
preview_dir
32+
end
33+
end
34+
35+
def package_dir
36+
@package_dir ||= begin
37+
package_dir = File.join(source_dir,PACKAGE_DIRNAME)
38+
if not File.exists?(package_dir)
39+
Dir.mkdir(package_dir)
40+
end
41+
package_dir
42+
end
43+
end
44+
45+
def build_config_file
46+
@build_config_file ||= File.join(source_dir,BUILD_FILENAME)
47+
end
48+
49+
def build_config
50+
@build_config ||= validate_config(YAML.load_stream(open(build_config_file)))
51+
end
52+
53+
def validate_config config_data
54+
# Validate/normalize the config file straight away
55+
if not config_data.is_a?(Array)
56+
raise "The configutaration in #{build_config_file} is malformed; the build system is expecting an array of topic groups."
57+
end
58+
config_data.each do |topic_group|
59+
# Check for presence of topic group keys
60+
['Name','Dir','Topics'].each do |group_key|
61+
if not topic_group.has_key?(group_key)
62+
raise "One of the topic groups in #{build_config_file} is missing the '#{group_key}' key."
63+
end
64+
end
65+
# Check for right format of topic group values
66+
['Name','Dir'].each do |group_key|
67+
if not topic_group[group_key].is_a?(String)
68+
raise "One of the topic groups in #{build_config_file} is not using a string for the #{group_key} setting; current value is #{topic_group[group_key].inspect}"
69+
end
70+
if topic_group[group_key].empty? or topic_group[group_key].match BLANK_STRING_RE
71+
raise "One of the topic groups in #{build_config_file} is using a blank value for the #{group_key} setting."
72+
end
73+
end
74+
if not File.exists?(File.join(source_dir,topic_group['Dir']))
75+
raise "In #{build_config_file}, the directory #{topic_group['Dir']} for topic group #{topic_group['Name']} does not exist under #{source_dir}"
76+
end
77+
if not topic_group['Topics'].is_a?(Array)
78+
raise "The #{topic_group['Name']} topic group in #{build_config_file} is malformed; the build system is expecting an array of 'Topic' definitions."
79+
end
80+
# Now buzz through the topics
81+
topic_group['Topics'].each do |topic|
82+
['Name','File'].each do |topic_key|
83+
if not topic[topic_key].is_a?(String)
84+
raise "In #{build_config_file}, topic group #{topic_group['Name']}, one of the topics is not using a string for the '#{topic_key}' setting; current value is #{topic[topic_key].inspect}"
85+
end
86+
if topic[topic_key].empty? or topic[topic_key].match BLANK_STRING_RE
87+
raise "In #{build_config_file}, topic group #{topic_group['Name']}, one of the topics is using a blank value for the '#{topic_key}' setting"
88+
end
89+
end
90+
# Normalize the filenames
91+
if topic['File'].end_with?('.adoc')
92+
topic['File'] = topic['File'][0..-6]
93+
end
94+
if not File.exists?(File.join(source_dir,topic_group['Dir'],"#{topic['File']}.adoc"))
95+
raise "In #{build_config_file}, could not find file #{topic['File']} under directory #{topic_group['Dir']} for topic #{topic['Name']} in topic group #{topic_group['Name']}."
96+
end
97+
end
98+
end
99+
config_data
100+
end
101+
102+
def nav_tree
103+
@nav_tree ||= begin
104+
navigation = []
105+
build_config.each do |topic_group|
106+
topic_list = []
107+
topic_group['Topics'].each do |topic|
108+
topic_list << ["#{topic_group['Dir']}/#{topic['File']}.html",topic['Name']]
109+
end
110+
navigation << { :title => topic_group['Name'], :topics => topic_list }
111+
end
112+
navigation
113+
end
114+
end
115+
116+
task :build do
117+
# Copy stylesheets into preview area
118+
system("cp -r #{builder_dir}/stylesheets #{preview_dir}")
119+
# Build the topic files
120+
build_config.each do |topic_group|
121+
src_group_path = File.join(source_dir,topic_group['Dir'])
122+
tgt_group_path = File.join(preview_dir,topic_group['Dir'])
123+
if not File.exists?(tgt_group_path)
124+
Dir.mkdir(tgt_group_path)
125+
end
126+
if File.exists?(File.join(src_group_path,'images'))
127+
system("cp -r #{src_group_path}/images #{tgt_group_path}")
128+
end
129+
topic_group['Topics'].each do |topic|
130+
src_file_path = File.join(src_group_path,"#{topic['File']}.adoc")
131+
tgt_file_path = File.join(tgt_group_path,"#{topic['File']}.adoc")
132+
system('cp', src_file_path, tgt_file_path)
133+
Asciidoctor.render_file tgt_file_path, :in_place => true, :safe => :unsafe, :template_dir => builder_template_dir, :attributes => ['source-highlighter=coderay','coderay-css=style',"stylesdir=#{preview_dir}/stylesheets","imagesdir=./images",'stylesheet=origin.css','linkcss!','icons=font','idprefix=','idseparator=-','sectanchors']
134+
system('rm', tgt_file_path)
135+
end
136+
end
137+
end
138+
139+
task :package do
140+
builds = [
141+
{ :branch => 'master',
142+
:branch_dir => ['/','openshift_origin/nightly'],
143+
:doc_version => 'OpenShift Origin Latest'
144+
},
145+
]
146+
147+
branches = `git branch`.split(/\n/).map{ |branch| branch.strip }
148+
149+
# Remeber the working branch so that we can return here later.
150+
working_branch = 'master'
151+
branches.each do |branch|
152+
next if not branch.start_with?('*')
153+
working_branch = branch.sub!(/^\* /,'')
154+
end
155+
156+
# Make sure the working branch doesn't have any uncommitted changes
157+
changed_files = `git status --porcelain`
158+
if not changed_files.empty?
159+
puts "Warning: Your current branch has uncommitted changes. Hit <CTRL+C> if you want to exit."
160+
print "Starting packager in "
161+
[3,2,1].each do |i|
162+
print "#{i}..."
163+
sleep 1
164+
end
165+
print "\n"
166+
end
167+
168+
# Now make sure the build branches are available.
169+
missing_branches = false
170+
builds.each do |build|
171+
if not branches.include?(build[:branch])
172+
if not missing_branches
173+
puts "ERROR: One or more branches for packaging are not available in this local repo:"
174+
missing_branches = true
175+
end
176+
puts "- #{build[:branch]}"
177+
end
178+
end
179+
if missing_branches
180+
puts "Add these branches and rerun the packaging command."
181+
exit 1
182+
end
183+
184+
# Start packaging. Clear out the old package dir before making the new package
185+
if Dir.entries('..').include?('_package')
186+
system 'rm', '-rf', '../_package'
187+
end
188+
Dir.mkdir('../_package')
189+
190+
# Now make each package.
191+
builds.each do |build|
192+
# Check out this build branch
193+
system("git checkout #{build[:branch]}")
194+
195+
if not $?.exitstatus == 0
196+
puts "ERROR: Could not check out branch #{build[:branch]}, please investigate."
197+
exit 1
198+
end
199+
200+
# Make the build dir
201+
build_dir = "../_package/#{build[:site_dir]}"
202+
Dir.mkdir(build_dir)
203+
204+
# Build the docs
205+
Rake::Task['build'].execute
206+
207+
# Clean everything up
208+
Rake::Task['clean'].execute
209+
end
210+
211+
# Return to the original branch
212+
system("git checkout #{working_branch}")
213+
214+
puts "Packaging completed."
215+
end
216+
217+
task :clean do
218+
sh "rm -rf ../_preview ../_package" do |ok,res|
219+
if ! ok
220+
puts "Nothing to clean."
221+
end
222+
end
223+
end

0 commit comments

Comments
 (0)