Skip to content

Commit

Permalink
Fail build on unexpected manual change
Browse files Browse the repository at this point in the history
  • Loading branch information
pointlessone committed Feb 13, 2017
1 parent d7facca commit 1444f4d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 29 deletions.
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ desc "Generate the 'Prawn by Example' manual"
task :manual do
puts 'Building manual...'
require File.expand_path(File.join(__dir__, %w[manual contents]))
prawn_manual_document.render_file('manual.pdf')
puts 'The Prawn manual is available at manual.pdf. Happy Prawning!'
end

Expand Down
46 changes: 25 additions & 21 deletions manual/contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,32 @@

require_relative 'example_helper'

Encoding.default_external = Encoding::UTF_8
def prawn_manual_document
old_default_external_encoding = Encoding.default_external
Encoding.default_external = Encoding::UTF_8

Prawn::ManualBuilder::Example.generate(
'manual.pdf',
skip_page_creation: true,
page_size: 'FOLIO'
) do
load_page '', 'cover'
load_page '', 'how_to_read_this_manual'
Prawn::ManualBuilder::Example.new(
skip_page_creation: true,
page_size: 'FOLIO'
) do
load_page '', 'cover'
load_page '', 'how_to_read_this_manual'

# Core chapters
load_package 'basic_concepts'
load_package 'graphics'
load_package 'text'
load_package 'bounding_box'
# Core chapters
load_package 'basic_concepts'
load_package 'graphics'
load_package 'text'
load_package 'bounding_box'

# Remaining chapters
load_package 'layout'
load_page '', 'table'
load_package 'images'
load_package 'document_and_page_options'
load_package 'outline'
load_package 'repeatable_content'
load_package 'security'
# Remaining chapters
load_package 'layout'
load_page '', 'table'
load_package 'images'
load_package 'document_and_page_options'
load_package 'outline'
load_package 'repeatable_content'
load_package 'security'
end
ensure
Encoding.default_external = old_default_external_encoding
end
18 changes: 10 additions & 8 deletions manual/cover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
git_commit = ''
end

formatted_text_box(
[{
text: "Last Update: #{Time.now.strftime('%Y-%m-%d')}\n" \
"Prawn Version: #{Prawn::VERSION}\n#{git_commit}",
size: 12
}],
at: [390, cursor - 620]
)
unless ENV['CI']
formatted_text_box(
[{
text: "Last Update: #{Time.now.strftime('%Y-%m-%d')}\n" \
"Prawn Version: #{Prawn::VERSION}\n#{git_commit}",
size: 12
}],
at: [390, cursor - 620]
)
end
end
33 changes: 33 additions & 0 deletions spec/manual_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'spec_helper'
require 'digest/sha2'

# rubocop: disable Metrics/LineLength
MANUAL_HASH =
case RUBY_ENGINE
when 'ruby'
'6aae613c48e7d9f7d4f57f026fe7c70eddff0bda8698ce7e8720bcd8c72ba1ca48f795aff153c39669e9282ee7350aeeabc39dd7051269cba95ae4a06e7437c8'
when 'jruby'
'483874116106a5f6276a1f196c6e72f9f823c613108512431d4e805ef5f03387d7a1a05a481540eebde8f86cba254f231d5b56872857c2e27900effccd2804f9'
end
# rubocop: enable Metrics/LineLength

RSpec.describe Prawn do
describe 'manual' do
# JRuby's zlib is a bit quirky. It sometimes produces different output to
# libzlib (used by MRI). It's still a proper deflate stream and can be
# decompressed just fine but for whatever reason compressin produses
# different output.
#
# See: https://github.com/jruby/jruby/issues/4244
it 'contains no unexpected changes' do
ENV['CI'] ||= 'true'

require File.expand_path(File.join(__dir__, %w[.. manual contents]))
s = prawn_manual_document.render

hash = Digest::SHA512.hexdigest(s)

expect(hash).to eq MANUAL_HASH
end
end
end

0 comments on commit 1444f4d

Please sign in to comment.