Skip to content

Commit

Permalink
Merge pull request #206 from burlakvo/fix-generating
Browse files Browse the repository at this point in the history
Attempt to fix book generating
  • Loading branch information
hedrok authored Oct 20, 2024
2 parents 1f35ef8 + 932bb7f commit 59cb96c
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 54 deletions.
10 changes: 3 additions & 7 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
ruby-version: 3.1
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
28 changes: 12 additions & 16 deletions .github/workflows/release-on-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,31 @@ 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/}"

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.7
ruby-version: 3.1
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: 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 "tagname=2.1.${PATCH}" >> $GITHUB_OUTPUT
- 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'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ progit.html
progit.pdf
progit.pdfmarks
progit.epub
progit.fb2.zip
progit-kf8.epub
progit.mobi
contributors.txt
24 changes: 13 additions & 11 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
source 'https://rubygems.org'

gem 'rake'
gem 'asciidoctor', '1.5.6.1'
gem 'rake', '13.2.1'
gem 'asciidoctor', '2.0.22'

gem 'json'
gem 'awesome_print'
gem 'json', '2.7.2'
gem 'awesome_print', '1.9.2'

gem 'asciidoctor-epub3', :git => 'https://github.com/asciidoctor/asciidoctor-epub3'
gem 'asciidoctor-pdf', '1.5.0.alpha.16'
gem 'asciidoctor-fb2', '0.7.0'
gem 'asciidoctor-epub3', '2.1.3'
gem 'asciidoctor-pdf', '2.3.17'

gem 'coderay'
gem 'pygments.rb'
gem 'thread_safe'
gem 'epubcheck'
gem 'kindlegen'
gem 'coderay', '1.1.3'
gem 'pygments.rb', '2.4.1'
gem 'thread_safe', '0.3.6'
gem 'epubcheck-ruby', '5.1.0.0'
gem 'html-proofer', '5.0.9'
gem 'kindlegen', '3.1.1'
142 changes: 127 additions & 15 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,138 @@
namespace :book do

# Variables referenced for build
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 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"
sh "rm book/contributors.txt"
# Reenable and invoke task again
Rake::Task['book/contributors.txt'].reenable
Rake::Task['book/contributors.txt'].invoke
end
end
end

desc 'build basic book formats'
task :build do
task :build => [:build_html, :build_epub, :build_fb2, :build_mobi, :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_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'
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...'
sh "bundle exec asciidoctor #{params} -a data-uri progit.asc"
puts ' -- HTML output at progit.html'

end

puts "Generating contributors list"
`git shortlog -s master| grep -v -E "(Straub|Chacon)" | cut -f 2- | column -c 120 > book/contributors.txt`
desc 'build Epub format'
task :build_epub => 'book/contributors.txt' do
check_contrib()

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

puts "Converting to EPub..."
`bundle exec asciidoctor-epub3 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
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

puts "Converting to Mobi (kf8)..."
`bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc`
puts " -- Mobi output at progit.mobi"
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 progit.asc 2>/dev/null`
puts " -- PDF output at progit.pdf"
puts 'Converting to PDF... (this one takes a while)'
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'

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-kf8.epub', 'progit.epub', 'progit.fb2.zip', 'progit.mobi', 'progit.pdf'].each do |file|
rm file

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

end

task :default => "book:build"
9 changes: 4 additions & 5 deletions progit.asc
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
Pro Git
=======
= Pro Git
Скот Чакон (Scott Chacon); Бен Страуб (Ben Straub)
:doctype: book
:docinfo:
:toc-title: Зміст
:toc:
:toclevels: 2
:pagenums:
:front-cover-image: image:book/cover.png[width=1050,height=1600]

ifdef::ebook-format[:leveloffset: -1]
:icons: font

include::book/license.asc[]

Expand Down Expand Up @@ -48,4 +47,4 @@ include::B-embedding-git-in-your-applications.asc[]

include::C-git-commands.asc[]

ifndef::ebook-format[include::index.asc[]]
ifdef::backend-pdf[include::index.asc[]]

0 comments on commit 59cb96c

Please sign in to comment.