/
deploy_website.rb
executable file
·70 lines (50 loc) · 1.27 KB
/
deploy_website.rb
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
#!/usr/bin/env ruby
require 'fileutils'
extend FileUtils
REPO ='git@github.com:beyama/winter.git'
CNAME = "winter.jentz.io"
TMP_DIR = 'tmp_clone'
WORKING_DIR = File.dirname(File.expand_path(__FILE__))
TRY_RUN = !ARGV.empty?
cd WORKING_DIR
current_branch = `git rev-parse --abbrev-ref HEAD`
puts "Generating website based on branch #{current_branch}"
# checkout gh-pages branch into TMP_DIR
rm_rf TMP_DIR
if TRY_RUN
mkdir TMP_DIR
else
`git clone #{REPO} #{TMP_DIR}`
cd TMP_DIR
`git checkout -t origin/gh-pages`
# Remove old site
rm_rf '*'
cd WORKING_DIR
end
# write CNAME file to gh-pages
File.open(File.join(TMP_DIR, "CNAME"), "w") { |f| f.write(CNAME) }
# build Javadocs
`./gradlew dokka`
# copy Javadocs
Dir["*/build/javadoc"].each do |dir|
cp_r dir, TMP_DIR
end
# build asciidoc page
latest_version = `git describe master --abbrev=0 --tags`.strip
`asciidoctor --attribute winterVersion=#{latest_version} --destination-dir #{TMP_DIR} doc/index.adoc`
if TRY_RUN
if RUBY_PLATFORM =~ /darwin/
`open #{File.join(TMP_DIR, "index.html")}`
end
exit 0
end
cd TMP_DIR
# Stage all files in git and create a commit
`git add .`
`git add -u`
`git commit -m "Website at $(date)"`
# Push the new files up to GitHub
`git push origin gh-pages`
# Clean up
cd WORKING_DIR
rm_rf TMP_DIR