|
1 | 1 | # coding: utf-8 |
2 | 2 | require 'octokit' |
3 | 3 |
|
| 4 | +def exec_or_raise(command) |
| 5 | + puts `#{command}` |
| 6 | + if (! $?.success?) |
| 7 | + raise "'#{command}' failed" |
| 8 | + end |
| 9 | +end |
| 10 | + |
4 | 11 | namespace :book do |
5 | 12 | desc 'build basic book formats' |
6 | 13 | task :build do |
7 | 14 |
|
8 | 15 | puts "Generating contributors list" |
9 | | - `git shortlog -s --all| grep -v -E "(Straub|Chacon)" | cut -f 2- | column -c 120 > book/contributors.txt` |
| 16 | + exec_or_raise("git shortlog -s --all| grep -v -E '(Straub|Chacon)' | cut -f 2- | column -c 120 > book/contributors.txt") |
10 | 17 |
|
11 | 18 | puts "Converting to HTML..." |
12 | | - `bundle exec asciidoctor progit.asc` |
| 19 | + exec_or_raise("bundle exec asciidoctor progit.asc") |
13 | 20 | puts " -- HTML output at progit.html" |
14 | 21 |
|
15 | 22 | puts "Converting to EPub..." |
16 | | - `bundle exec asciidoctor-epub3 progit.asc` |
| 23 | + exec_or_raise("bundle exec asciidoctor-epub3 progit.asc") |
17 | 24 | puts " -- Epub output at progit.epub" |
18 | 25 |
|
19 | | - sh "epubcheck progit.epub" |
| 26 | + exec_or_raise("epubcheck progit.epub") |
20 | 27 |
|
21 | 28 | puts "Converting to Mobi (kf8)..." |
22 | | - `bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc` |
| 29 | + exec_or_raise("bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc") |
23 | 30 | puts " -- Mobi output at progit.mobi" |
24 | 31 |
|
| 32 | + repo = ENV['TRAVIS_REPO_SLUG'] |
25 | 33 | puts "Converting to PDF... (this one takes a while)" |
26 | | - `bundle exec asciidoctor-pdf progit.asc 2>/dev/null` |
| 34 | + if (repo == "progit/progit2-zh") |
| 35 | + exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install") |
| 36 | + exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN progit.asc") |
| 37 | + else |
| 38 | + exec_or_raise("bundle exec asciidoctor-pdf progit.asc 2>/dev/null") |
| 39 | + end |
27 | 40 | puts " -- PDF output at progit.pdf" |
28 | 41 | end |
29 | 42 |
|
30 | 43 | desc 'tag the repo with the latest version' |
31 | 44 | task :tag do |
32 | 45 | api_token = ENV['GITHUB_API_TOKEN'] |
33 | | - if (api_token && (ENV['TRAVIS_PULL_REQUEST'] == 'false') && (ENV['TRAVIS_BRANCH']=='master') && !ENV['TRAVIS_TAG']) |
| 46 | + if (api_token && (ENV['TRAVIS_PULL_REQUEST'] == 'false') && (ENV['TRAVIS_BRANCH']=='master')) |
34 | 47 | repo = ENV['TRAVIS_REPO_SLUG'] |
35 | 48 | @octokit = Octokit::Client.new(:access_token => api_token) |
36 | 49 | begin |
@@ -148,7 +161,7 @@ namespace :book do |
148 | 161 | content = File.read (filename) |
149 | 162 | new_contents = content.gsub(/include::(.*?)asc/) {|match| |
150 | 163 | "include::book/#{num}-#{title}/#{$1}asc"} |
151 | | - `git rm #{filename}` |
| 164 | + `git rm -f #{filename}` |
152 | 165 | File.open("#{chap}.asc", "w") {|file| |
153 | 166 | file.puts "[##{chap}]\n" |
154 | 167 | file.puts new_contents } |
|
0 commit comments