Skip to content

fix book build/release workflow #143

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 2 additions & 6 deletions .github/workflows/pr-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,13 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Download bootstrap file
run: wget https://raw.githubusercontent.com/progit/progit2-pub/master/bootstrap.sh
- name: Run bootstrap
run: sh bootstrap.sh
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Build book
run: bundle exec rake book:build_action
run: bundle exec rake book:build
14 changes: 5 additions & 9 deletions .github/workflows/release-on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,17 @@ jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: get bootstrap file
run: wget https://raw.githubusercontent.com/progit/progit2-pub/master/bootstrap.sh
- name: run bootstrap
run: sh bootstrap.sh
- name: Compute tag name
id: compute-tag
run: |
echo Computing next tag number
LASTPATCH=$(git describe --tags | cut -d- -f1 | cut -d. -f3)
PATCH=$(($LASTPATCH+1))
echo "::set-output name=tagname::2.1.${PATCH}"
echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
echo "tagname=2.1.${PATCH}" >> $GITHUB_OUTPUT
echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT

- name: Set up Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -31,12 +27,12 @@ jobs:
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

- name: Build release assets
run: bundle exec rake book:build_action
run: bundle exec rake book:build

- name: Create release
uses: ncipollo/release-action@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
tag: ${{ steps.compute-tag.outputs.tagname }}
commit: ${{ steps.compute-tag.outputs.branch }}
artifacts: './progit.epub,./progit.mobi,./progit.pdf,./progit.html'
artifacts: './progit.epub,./progit.fb2.zip,./progit.mobi,./progit.pdf,./progit.html'
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ progit.html
progit.pdf
progit.pdfmarks
progit.epub
progit.fb2.zip
progit-kf8.epub
progit.mobi
contributors.txt
contributors.txt
progit.mobi8
30 changes: 18 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
source 'https://rubygems.org'

gem 'rake', '13.0.3'
gem 'asciidoctor', '2.0.15'
gem 'ffi', '1.16.3'
gem 'rake'
gem 'asciidoctor', '2.0.12'

gem 'json', '2.5.1'
gem 'awesome_print', '1.9.2'
gem 'json'
gem 'awesome_print'

gem 'asciidoctor-epub3', '1.5.0.alpha.19'
gem 'asciidoctor-pdf', '1.5.4'
gem 'ttfunk', '1.5.1'
gem 'asciidoctor-fb2'
gem 'asciidoctor-epub3', '1.5.0.alpha.11'
gem 'asciidoctor-pdf', '1.5.0.alpha.16'
gem 'asciidoctor-pdf-cjk', '~> 0.1.3'
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.1'
gem 'asciidoctor-pdf-cjk-kai_gen_gothic', github: 'Sherry520/asciidoctor-pdf-cjk-kai_gen_gothic'

gem 'coderay', '1.1.3'
gem 'pygments.rb', '2.2.0'
gem 'thread_safe', '0.3.6'
gem 'epubcheck-ruby', '4.2.5.0'
gem 'html-proofer', '3.19.0'
gem 'coderay'
gem 'pygments.rb'
gem 'thread_safe'
gem 'epubcheck-ruby'
gem 'html-proofer'

gem 'kindlegen', '3.1.1'
gem 'nokogiri', '~> 1.13', '>= 1.13.10'
97 changes: 66 additions & 31 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
namespace :book do
def exec_or_raise(command)
puts `#{command}`
if (! $?.success?)
raise "'#{command}' failed"
end
def exec_or_raise(command)
puts `#{command}`
if (! $?.success?)
raise "'#{command}' failed"
end
end

namespace :book do

# Download asciidoctor-pdf-cjk-kai_gen_gothic
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")

# Variables referenced for build
version_string = ENV['TRAVIS_TAG'] || `git describe --tags`.chomp
version_string = `git describe --tags --abbrev=0`.chomp
if version_string.empty?
version_string = '0'
else
versions = version_string.split('.')
version_string = versions[0] + '.' + versions[1] + '.' + versions[2].to_i.next.to_s
end
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 language
repo = File.basename(`git rev-parse --show-toplevel`.chomp)
lang_match = repo.match(/progit2-([a-z-]*)/)
if lang_match
lang = lang_match[1]
else
lang = "en"
end

begin
if lang == "zh"
params = "-r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN --attribute revnumber='#{version_string}' --attribute revdate='#{date_string}' --attribute lang='#{lang}'"
elsif lang == "zh-tw"
params = "-r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicTW --attribute revnumber='#{version_string}' --attribute revdate='#{date_string}' --attribute lang='#{lang}'"
elsif lang == "ja"
params = "-r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicJP --attribute revnumber='#{version_string}' --attribute revdate='#{date_string}' --attribute lang='#{lang}'"
elsif lang == "ko"
params = "-r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicKR --attribute revnumber='#{version_string}' --attribute revdate='#{date_string}' --attribute lang='#{lang}'"
else
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
end
rescue => e
puts e.message
puts 'Error when checking repo language(ignored)'
end

# Check contributors list
# This checks commit hash stored in the header of list against current HEAD
Expand All @@ -28,7 +60,7 @@ namespace :book do
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`
sh "rm book/contributors.txt"
# Reenable and invoke task again
Rake::Task['book/contributors.txt'].reenable
Rake::Task['book/contributors.txt'].invoke
Expand All @@ -37,7 +69,7 @@ namespace :book do
end

desc 'build basic book formats'
task :build => [:build_html, :build_epub, :build_pdf] do
task :build => [:build_html, :build_epub, :build_fb2, :build_mobi, :build_pdf] do
begin
# Run check
Rake::Task['book:check'].invoke
Expand All @@ -50,24 +82,24 @@ namespace :book do
end

desc 'build basic book formats (for ci)'
task :ci => [:build_html, :build_epub, :build_pdf] do
task :ci => [:build_html, :build_epub, :build_fb2, :build_mobi, :build_pdf] do
# 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'
`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`
sh "echo 'Contributors as of #{header_hash}:\n' > book/contributors.txt"
sh "git shortlog -s HEAD | grep -v -E '(Straub|Chacon|dependabot)' | cut -f 2- | sort | column -c 120 >> book/contributors.txt"
end

desc 'build HTML format'
task :build_html => 'book/contributors.txt' do
check_contrib()

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

end
Expand All @@ -77,50 +109,53 @@ namespace :book do
check_contrib()

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

end

desc 'build FB2 format'
task :build_fb2 => 'book/contributors.txt' do
check_contrib()

puts 'Converting to FB2...'
sh "bundle exec asciidoctor-fb2 #{params} progit.asc"
puts ' -- FB2 output at progit.fb2.zip'

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.

# puts "Converting to Mobi (kf8)..."
# `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)
check_contrib()

puts "Converting to Mobi (kf8)..."
sh "bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc"
puts " -- Mobi output at progit.mobi"
end

desc 'build PDF format'
task :build_pdf => 'book/contributors.txt' do
check_contrib()

puts 'Converting to PDF... (this one takes a while)'
`bundle exec asciidoctor-pdf #{params} -a scripts=cjk -a pdf-theme=./korean-theme.yml -a pdf-fontsdir=$(ruby -r asciidoctor-pdf-cjk-kai_gen_gothic -e "print File.expand_path '../fonts', (Gem.datadir 'asciidoctor-pdf-cjk-kai_gen_gothic')") progit.asc 2>/dev/null`
sh "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
puts 'Checking generated books'

exec_or_raise('htmlproofer --check-html progit.html')
exec_or_raise('epubcheck progit.epub')
sh "htmlproofer progit.html"
sh "epubcheck progit.epub"
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|
FileList['book/contributors.txt', 'progit.html', 'progit-kf8.epub', 'progit.epub', 'progit.fb2.zip', 'progit.mobi', 'progit.pdf'].each do |file|
rm file

# Rescue if file not found
Expand Down