Skip to content

Refactor book:build task #1598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions README.asc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,27 @@ Converting to PDF...
-- PDF output at progit.pdf
----

You can generate just one of the supported formats (HTML, EPUB, or PDF).
Use one of the following commands:

To generate the HTML book:

----
$ bundle exec rake book:build_html
----

To generate the EPUB book:

----
$ bundle exec rake book:build_epub
----

To generate the PDF book:

----
$ bundle exec rake book:build_pdf
----

== Signaling an Issue

Before signaling an issue, please check that there isn't already a similar one in the bug tracking system.
Expand Down
79 changes: 70 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,59 @@ namespace :book do
end
end

# Variables referenced for build
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
if version_string.empty?
version_string = '0'
end
date_string = Time.now.strftime("%Y-%m-%d")
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"

desc 'build basic book formats'
task :build do
task :build => [:build_html, :build_epub, :build_pdf] do
begin
# Run check
Rake::Task["book:check"].invoke

# Rescue to ignore checking errors
rescue => e
puts e.message
puts "Error when checking books (ignored)"
end
end

desc 'build basic book formats (for ci)'
task :ci => [:build_html, :build_epub, :build_pdf] do
begin
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
if version_string.empty?
version_string = '0'
end
date_string = Time.now.strftime("%Y-%m-%d")
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
# Run check, but don't ignore any errors
Rake::Task["book:check"].invoke
end
end

desc 'generate contributors list'
file 'book/contributors.txt' do
puts "Generating contributors list"
`git shortlog -s | grep -v -E "(Straub|Chacon|dependabot)" | cut -f 2- | column -c 120 > book/contributors.txt`
end

desc 'build HTML format'
task :build_html => 'book/contributors.txt' do
puts "Converting to HTML..."
`bundle exec asciidoctor #{params} -a data-uri progit.asc`
puts " -- HTML output at progit.html"

exec_or_raise('htmlproofer --check-html progit.html')
end

desc 'build Epub format'
task :build_epub => 'book/contributors.txt' do
puts "Converting to EPub..."
`bundle exec asciidoctor-epub3 #{params} progit.asc`
puts " -- Epub output at progit.epub"

exec_or_raise('epubcheck progit.epub')
end

desc 'build Mobi format'
task :build_mobi => 'book/contributors.txt' do
# Commented out the .mobi file creation because the kindlegen dependency is not available.
# For more information on this see: #1496.
# This is a (hopefully) temporary fix until upstream asciidoctor-epub3 is fixed and we can offer .mobi files again.
Expand All @@ -39,12 +67,45 @@ namespace :book do
# `bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc`
# puts " -- Mobi output at progit.mobi"

# FIXME: If asciidoctor-epub3 supports Mobi again, uncomment these lines below
puts "Converting to Mobi isn't supported yet."
puts "For more information see issue #1496 at https://github.com/progit/progit2/issues/1496."
exit(127)
end

desc 'build PDF format'
task :build_pdf => 'book/contributors.txt' do
puts "Converting to PDF... (this one takes a while)"
`bundle exec asciidoctor-pdf #{params} progit.asc 2>/dev/null`
puts " -- PDF output at progit.pdf"
end

desc 'Check generated books'
task :check => [:build_html, :build_epub] do
begin
puts "Checking generated books"

exec_or_raise('htmlproofer --check-html progit.html')
exec_or_raise('epubcheck progit.epub')
end
end

desc 'Clean all generated files'
task :clean do
begin
puts "Removing generated files"

FileList['book/contributors.txt', 'progit.html', 'progit.epub', 'progit.pdf'].each do |file|
rm file

# Rescue if file not found
rescue Errno::ENOENT => e
puts e.message
puts "Error removing files (ignored)"
end
end
end

end

task :default => "book:build"