Skip to content

Commit 59cb96c

Browse files
authored
Merge pull request #206 from burlakvo/fix-generating
Attempt to fix book generating
2 parents 1f35ef8 + 932bb7f commit 59cb96c

File tree

6 files changed

+160
-54
lines changed

6 files changed

+160
-54
lines changed

.github/workflows/pr-build.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,13 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212

13-
- name: Download bootstrap file
14-
run: wget https://raw.githubusercontent.com/progit/progit2-pub/master/bootstrap.sh
15-
- name: Run bootstrap
16-
run: sh bootstrap.sh
1713
- name: Set up Ruby
1814
uses: ruby/setup-ruby@v1
1915
with:
20-
ruby-version: 2.7
16+
ruby-version: 3.1
2117
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
2218

2319
- name: Build book
24-
run: bundle exec rake book:build_action
20+
run: bundle exec rake book:build

.github/workflows/release-on-merge.yml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,35 +8,31 @@ jobs:
88
release:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
11+
- uses: actions/checkout@v4
1212
with:
1313
fetch-depth: 0
14-
- name: get bootstrap file
15-
run: wget https://raw.githubusercontent.com/progit/progit2-pub/master/bootstrap.sh
16-
- name: run bootstrap
17-
run: sh bootstrap.sh
18-
- name: Compute tag name
19-
id: compute-tag
20-
run: |
21-
echo Computing next tag number
22-
LASTPATCH=$(git describe --tags | cut -d- -f1 | cut -d. -f3)
23-
PATCH=$(($LASTPATCH+1))
24-
echo "::set-output name=tagname::2.1.${PATCH}"
25-
echo "::set-output name=branch::${GITHUB_REF#refs/heads/}"
2614

2715
- name: Set up Ruby
2816
uses: ruby/setup-ruby@v1
2917
with:
30-
ruby-version: 2.7
18+
ruby-version: 3.1
3119
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
3220

3321
- name: Build release assets
34-
run: bundle exec rake book:build_action
22+
run: bundle exec rake book:build
23+
24+
- name: Compute tag name
25+
id: compute-tag
26+
run: |
27+
echo Computing next tag number
28+
LASTPATCH=$(git describe --tags | cut -d- -f1 | cut -d. -f3)
29+
PATCH=$(($LASTPATCH+1))
30+
echo "tagname=2.1.${PATCH}" >> $GITHUB_OUTPUT
3531
3632
- name: Create release
3733
uses: ncipollo/release-action@v1
3834
with:
3935
token: ${{ secrets.GITHUB_TOKEN }}
4036
tag: ${{ steps.compute-tag.outputs.tagname }}
4137
commit: ${{ steps.compute-tag.outputs.branch }}
42-
artifacts: './progit.epub,./progit.mobi,./progit.pdf,./progit.html'
38+
artifacts: './progit.epub,./progit.fb2.zip,./progit.mobi,./progit.pdf,./progit.html'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ progit.html
77
progit.pdf
88
progit.pdfmarks
99
progit.epub
10+
progit.fb2.zip
1011
progit-kf8.epub
1112
progit.mobi
1213
contributors.txt

Gemfile

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
source 'https://rubygems.org'
22

3-
gem 'rake'
4-
gem 'asciidoctor', '1.5.6.1'
3+
gem 'rake', '13.2.1'
4+
gem 'asciidoctor', '2.0.22'
55

6-
gem 'json'
7-
gem 'awesome_print'
6+
gem 'json', '2.7.2'
7+
gem 'awesome_print', '1.9.2'
88

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

12-
gem 'coderay'
13-
gem 'pygments.rb'
14-
gem 'thread_safe'
15-
gem 'epubcheck'
16-
gem 'kindlegen'
13+
gem 'coderay', '1.1.3'
14+
gem 'pygments.rb', '2.4.1'
15+
gem 'thread_safe', '0.3.6'
16+
gem 'epubcheck-ruby', '5.1.0.0'
17+
gem 'html-proofer', '5.0.9'
18+
gem 'kindlegen', '3.1.1'

Rakefile

Lines changed: 127 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,138 @@
11
namespace :book do
2+
3+
# Variables referenced for build
4+
version_string = `git describe --tags --abbrev=0`.chomp
5+
if version_string.empty?
6+
version_string = '0'
7+
else
8+
versions = version_string.split('.')
9+
version_string = versions[0] + '.' + versions[1] + '.' + versions[2].to_i.next.to_s
10+
end
11+
date_string = Time.now.strftime('%Y-%m-%d')
12+
params = "--attribute revnumber='#{version_string}' --attribute revdate='#{date_string}'"
13+
header_hash = `git rev-parse --short HEAD`.strip
14+
15+
# Check contributors list
16+
# This checks commit hash stored in the header of list against current HEAD
17+
def check_contrib
18+
if File.exist?('book/contributors.txt')
19+
current_head_hash = `git rev-parse --short HEAD`.strip
20+
header = `head -n 1 book/contributors.txt`.strip
21+
# Match regex, then coerce resulting array to string by join
22+
header_hash = header.scan(/[a-f0-9]{7,}/).join
23+
24+
if header_hash == current_head_hash
25+
puts "Hash on header of contributors list (#{header_hash}) matches the current HEAD (#{current_head_hash})"
26+
else
27+
puts "Hash on header of contributors list (#{header_hash}) does not match the current HEAD (#{current_head_hash}), refreshing"
28+
sh "rm book/contributors.txt"
29+
# Reenable and invoke task again
30+
Rake::Task['book/contributors.txt'].reenable
31+
Rake::Task['book/contributors.txt'].invoke
32+
end
33+
end
34+
end
35+
236
desc 'build basic book formats'
3-
task :build do
37+
task :build => [:build_html, :build_epub, :build_fb2, :build_mobi, :build_pdf] do
38+
begin
39+
# Run check
40+
Rake::Task['book:check'].invoke
41+
42+
# Rescue to ignore checking errors
43+
rescue => e
44+
puts e.message
45+
puts 'Error when checking books (ignored)'
46+
end
47+
end
48+
49+
desc 'build basic book formats (for ci)'
50+
task :ci => [:build_html, :build_epub, :build_fb2, :build_mobi, :build_pdf] do
51+
# Run check, but don't ignore any errors
52+
Rake::Task['book:check'].invoke
53+
end
54+
55+
desc 'generate contributors list'
56+
file 'book/contributors.txt' do
57+
puts 'Generating contributors list'
58+
sh "echo 'Contributors as of #{header_hash}:\n' > book/contributors.txt"
59+
sh "git shortlog -s HEAD | grep -v -E '(Straub|Chacon|dependabot)' | cut -f 2- | sort | column -c 120 >> book/contributors.txt"
60+
end
61+
62+
desc 'build HTML format'
63+
task :build_html => 'book/contributors.txt' do
64+
check_contrib()
65+
66+
puts 'Converting to HTML...'
67+
sh "bundle exec asciidoctor #{params} -a data-uri progit.asc"
68+
puts ' -- HTML output at progit.html'
69+
70+
end
471

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

8-
puts "Converting to HTML..."
9-
`bundle exec asciidoctor progit.asc`
10-
puts " -- HTML output at progit.html"
76+
puts 'Converting to EPub...'
77+
sh "bundle exec asciidoctor-epub3 #{params} progit.asc"
78+
puts ' -- Epub output at progit.epub'
1179

12-
puts "Converting to EPub..."
13-
`bundle exec asciidoctor-epub3 progit.asc`
14-
puts " -- Epub output at progit.epub"
80+
end
81+
82+
desc 'build FB2 format'
83+
task :build_fb2 => 'book/contributors.txt' do
84+
check_contrib()
85+
86+
puts 'Converting to FB2...'
87+
sh "bundle exec asciidoctor-fb2 #{params} progit.asc"
88+
puts ' -- FB2 output at progit.fb2.zip'
89+
90+
end
91+
92+
desc 'build Mobi format'
93+
task :build_mobi => 'book/contributors.txt' do
94+
check_contrib()
95+
96+
puts "Converting to Mobi (kf8)..."
97+
sh "bundle exec asciidoctor-epub3 #{params} -a ebook-format=kf8 progit.asc"
98+
puts " -- Mobi output at progit.mobi"
99+
end
15100

16-
puts "Converting to Mobi (kf8)..."
17-
`bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc`
18-
puts " -- Mobi output at progit.mobi"
101+
desc 'build PDF format'
102+
task :build_pdf => 'book/contributors.txt' do
103+
check_contrib()
19104

20-
puts "Converting to PDF... (this one takes a while)"
21-
`bundle exec asciidoctor-pdf progit.asc 2>/dev/null`
22-
puts " -- PDF output at progit.pdf"
105+
puts 'Converting to PDF... (this one takes a while)'
106+
sh "bundle exec asciidoctor-pdf #{params} progit.asc 2>/dev/null"
107+
puts ' -- PDF output at progit.pdf'
23108
end
109+
110+
desc 'Check generated books'
111+
task :check => [:build_html, :build_epub] do
112+
puts 'Checking generated books'
113+
114+
sh "htmlproofer progit.html"
115+
sh "epubcheck progit.epub"
116+
end
117+
118+
desc 'Clean all generated files'
119+
task :clean do
120+
begin
121+
puts 'Removing generated files'
122+
123+
FileList['book/contributors.txt', 'progit.html', 'progit-kf8.epub', 'progit.epub', 'progit.fb2.zip', 'progit.mobi', 'progit.pdf'].each do |file|
124+
rm file
125+
126+
# Rescue if file not found
127+
rescue Errno::ENOENT => e
128+
begin
129+
puts e.message
130+
puts 'Error removing files (ignored)'
131+
end
132+
end
133+
end
134+
end
135+
24136
end
25137

26138
task :default => "book:build"

progit.asc

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
Pro Git
2-
=======
1+
= Pro Git
2+
Скот Чакон (Scott Chacon); Бен Страуб (Ben Straub)
33
:doctype: book
44
:docinfo:
55
:toc-title: Зміст
66
:toc:
77
:toclevels: 2
88
:pagenums:
99
:front-cover-image: image:book/cover.png[width=1050,height=1600]
10-
11-
ifdef::ebook-format[:leveloffset: -1]
10+
:icons: font
1211

1312
include::book/license.asc[]
1413

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

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

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

0 commit comments

Comments
 (0)