diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 20bbc0d..4eabd25 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -8,12 +8,8 @@ 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: @@ -21,4 +17,4 @@ jobs: 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 diff --git a/.github/workflows/release-on-merge.yml b/.github/workflows/release-on-merge.yml index 3c877b8..109383f 100644 --- a/.github/workflows/release-on-merge.yml +++ b/.github/workflows/release-on-merge.yml @@ -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 @@ -31,7 +27,7 @@ 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 @@ -39,4 +35,4 @@ jobs: 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' diff --git a/.gitignore b/.gitignore index 424a30e..6edb8af 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ progit.html progit.pdf progit.pdfmarks progit.epub +progit.fb2.zip progit-kf8.epub progit.mobi -contributors.txt \ No newline at end of file +contributors.txt +progit.mobi8 diff --git a/Gemfile b/Gemfile index ee74b4a..2211a4f 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Rakefile b/Rakefile index ae49df0..cb01f18 100644 --- a/Rakefile +++ b/Rakefile @@ -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 @@ -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 @@ -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 @@ -50,7 +82,7 @@ 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 @@ -58,8 +90,8 @@ namespace :book do 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' @@ -67,7 +99,7 @@ namespace :book 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 @@ -77,25 +109,28 @@ 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' @@ -103,7 +138,7 @@ namespace :book 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 @@ -111,8 +146,8 @@ namespace :book do 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' @@ -120,7 +155,7 @@ namespace :book 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