Skip to content
Merged
Changes from 7 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
74 changes: 51 additions & 23 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,74 @@ namespace :book do
if version_string.empty?
version_string = '0'
end
date_string = Time.now.strftime("%Y-%m-%d")
date_string = Time.now.strftime('%Y-%m-%d')
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
header_hash = `git rev-parse --short HEAD`.strip

# Check contributors list
# This checks commit hash stored in the header of list against current HEAD
def check_contrib
if File.exist?('book/contributors.txt')
current_head_hash = `git rev-parse --short HEAD`.strip
header = `head -n 1 book/contributors.txt`.strip
# Match regex, then coerce resulting array to string by join
header_hash = header.scan(/[a-f0-9]{7,}/).join

if header_hash == current_head_hash
puts "Hash on header of contributors list (#{header_hash}) matches the current HEAD (#{current_head_hash})"
else
puts "Hash on header of contributors list (#{header_hash}) does not match the current HEAD (#{current_head_hash}), refreshing"
`rm book/contributors.txt`
# Reenable and invoke task again
Rake::Task['book/contributors.txt'].reenable
Rake::Task['book/contributors.txt'].invoke
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Check contributors list
# This checks commit hash stored in the header of list against current HEAD
def check_contrib
if File.exist?('book/contributors.txt')
current_head_hash = `git rev-parse --short HEAD`.strip
header = `head -n 1 book/contributors.txt`.strip
# Match regex, then coerce resulting array to string by join
header_hash = header.scan(/[a-f0-9]{7,}/).join
if header_hash == current_head_hash
puts "Hash on header of contributors list (#{header_hash}) matches the current HEAD (#{current_head_hash})"
else
puts "Hash on header of contributors list (#{header_hash}) does not match the current HEAD (#{current_head_hash}), refreshing"
`rm book/contributors.txt`
# Reenable and invoke task again
Rake::Task['book/contributors.txt'].reenable
Rake::Task['book/contributors.txt'].invoke
end
end
end
# Check contributors list
# This checks the commit hash stored in the header of the list against the current HEAD
def check_contrib
if File.exist?('book/contributors.txt')
current_head_hash = `git rev-parse --short HEAD`.strip
header = `head -n 1 book/contributors.txt`.strip
# Match regex, then coerce resulting array to string by join
header_hash = header.scan(/[a-f0-9]{7,}/).join
if header_hash == current_head_hash
puts "Hash on header of contributors list (#{header_hash}) matches the current HEAD (#{current_head_hash})"
else
puts "Hash on header of contributors list (#{header_hash}) does not match the current HEAD (#{current_head_hash}), refreshing"
`rm book/contributors.txt`
# Re-enable and invoke task again
Rake::Task['book/contributors.txt'].reenable
Rake::Task['book/contributors.txt'].invoke
end
end
end

Some small comment fixes.


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

# Rescue to ignore checking errors
rescue => e
puts e.message
puts "Error when checking books (ignored)"
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
# Run check, but don't ignore any errors
Rake::Task["book:check"].invoke
end
# Run check, but don't ignore any errors
Rake::Task['book:check'].invoke
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`
puts 'Generating contributors list'
`echo "Contributors as of #{header_hash}:\n" > book/contributors.txt`
`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..."
check_contrib()

puts 'Converting to HTML...'
`bundle exec asciidoctor #{params} -a data-uri progit.asc`
puts " -- HTML output at progit.html"
puts ' -- HTML output at progit.html'

end

desc 'build Epub format'
task :build_epub => 'book/contributors.txt' do
puts "Converting to EPub..."
check_contrib()

puts 'Converting to EPub...'
`bundle exec asciidoctor-epub3 #{params} progit.asc`
puts " -- Epub output at progit.epub"
puts ' -- Epub output at progit.epub'

end

Expand All @@ -70,38 +95,41 @@ namespace :book do
# 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."
>>>>>>> fork/build-task-refactor
exit(127)
end

desc 'build PDF format'
task :build_pdf => 'book/contributors.txt' do
puts "Converting to PDF... (this one takes a while)"
check_contrib()

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"
puts ' -- PDF output at progit.pdf'
end

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

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

desc 'Clean all generated files'
task :clean do
begin
puts "Removing generated files"
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)"
begin
puts e.message
puts 'Error removing files (ignored)'
end
end
end
end
Expand Down