Skip to content

Commit 8e8da57

Browse files
jnavilanetworm
authored andcommitted
Apply new Rakefile
This fixes #355
1 parent a2e412c commit 8e8da57

File tree

2 files changed

+98
-23
lines changed

2 files changed

+98
-23
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ gem 'asciidoctor-pdf-cjk-kai_gen_gothic', '~> 0.1.1'
1414
gem 'coderay'
1515
gem 'pygments.rb'
1616
gem 'thread_safe'
17-
gem 'epubcheck'
17+
gem 'epubcheck-ruby'
1818
gem 'kindlegen'
1919

2020
gem 'octokit'
21+
gem 'github_changelog_generator', github: 'Furtif/github-changelog-generator'

Rakefile

Lines changed: 96 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# coding: utf-8
22
require 'octokit'
3+
require 'github_changelog_generator'
34

45
def exec_or_raise(command)
56
puts `#{command}`
@@ -8,42 +9,95 @@ def exec_or_raise(command)
89
end
910
end
1011

12+
module GitHubChangelogGenerator
13+
14+
#OPTIONS = %w[ user project token date_format output
15+
# bug_prefix enhancement_prefix issue_prefix
16+
# header merge_prefix issues
17+
# add_issues_wo_labels add_pr_wo_labels
18+
# pulls filter_issues_by_milestone author
19+
# unreleased_only unreleased unreleased_label
20+
# compare_link include_labels exclude_labels
21+
# bug_labels enhancement_labels
22+
# between_tags exclude_tags exclude_tags_regex since_tag max_issues
23+
# github_site github_endpoint simple_list
24+
# future_release release_branch verbose release_url
25+
# base configure_sections add_sections]
26+
27+
def get_log(&task_block)
28+
options = Parser.default_options
29+
yield(options) if task_block
30+
31+
options[:user],options[:project] = ENV['TRAVIS_REPO_SLUG'].split('/')
32+
options[:token] = ENV['GITHUB_API_TOKEN']
33+
options[:unreleased] = false
34+
35+
generator = Generator.new options
36+
generator.compound_changelog
37+
end
38+
39+
module_function :get_log
40+
end
41+
1142
namespace :book do
1243
desc 'build basic book formats'
1344
task :build do
1445

1546
puts "Generating contributors list"
16-
exec_or_raise("git shortlog -s --all| grep -v -E '(Straub|Chacon)' | cut -f 2- | column -c 120 > book/contributors.txt")
47+
exec_or_raise("git shortlog -s --all $translation_origin | grep -v -E '(Straub|Chacon)' | cut -f 2- | sort | column -c 110 > book/contributors.txt")
48+
49+
# detect if the deployment is using glob
50+
travis = File.read(".travis.yml")
51+
version_string = ENV['TRAVIS_TAG'] || '0'
52+
if travis.match(/file_glob/)
53+
progit_v = "progit_v#{version_string}"
54+
else
55+
progit_v = "progit"
56+
end
57+
text = File.read('progit.asc')
58+
new_contents = text.gsub("$$VERSION$$", version_string).gsub("$$DATE$$", Time.now.strftime("%Y-%m-%d"))
59+
File.open("#{progit_v}.asc", "w") {|file| file.puts new_contents }
1760

1861
puts "Converting to HTML..."
19-
exec_or_raise("bundle exec asciidoctor progit.asc")
20-
puts " -- HTML output at progit.html"
62+
exec_or_raise("bundle exec asciidoctor #{progit_v}.asc")
63+
puts " -- HTML output at #{progit_v}.html"
2164

2265
puts "Converting to EPub..."
23-
exec_or_raise("bundle exec asciidoctor-epub3 progit.asc")
24-
puts " -- Epub output at progit.epub"
66+
exec_or_raise("bundle exec asciidoctor-epub3 #{progit_v}.asc")
67+
puts " -- Epub output at #{progit_v}.epub"
2568

26-
exec_or_raise("epubcheck progit.epub")
69+
exec_or_raise("epubcheck #{progit_v}.epub")
2770

2871
puts "Converting to Mobi (kf8)..."
29-
exec_or_raise("bundle exec asciidoctor-epub3 -a ebook-format=kf8 progit.asc")
30-
puts " -- Mobi output at progit.mobi"
72+
exec_or_raise("bundle exec asciidoctor-epub3 -a ebook-format=kf8 #{progit_v}.asc")
73+
# remove the fake epub that would shadow the really one
74+
exec_or_raise("rm progit*kf8.epub")
75+
puts " -- Mobi output at #{progit_v}.mobi"
3176

3277
repo = ENV['TRAVIS_REPO_SLUG']
3378
puts "Converting to PDF... (this one takes a while)"
3479
if (repo == "progit/progit2-zh")
3580
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
36-
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN progit.asc")
81+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicCN #{progit_v}.asc")
82+
elsif (repo == "progit/progit2-ja")
83+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
84+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicJP #{progit_v}.asc")
85+
elsif (repo == "progit/progit2-zh-tw")
86+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
87+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicTW #{progit_v}.asc")
88+
elsif (repo == "progit/progit2-ko")
89+
exec_or_raise("asciidoctor-pdf-cjk-kai_gen_gothic-install")
90+
exec_or_raise("bundle exec asciidoctor-pdf -r asciidoctor-pdf-cjk -r asciidoctor-pdf-cjk-kai_gen_gothic -a pdf-style=KaiGenGothicKR #{progit_v}.asc")
3791
else
38-
exec_or_raise("bundle exec asciidoctor-pdf progit.asc 2>/dev/null")
92+
exec_or_raise("bundle exec asciidoctor-pdf #{progit_v}.asc 2>/dev/null")
3993
end
40-
puts " -- PDF output at progit.pdf"
94+
puts " -- PDF output at #{progit_v}.pdf"
4195
end
4296

4397
desc 'tag the repo with the latest version'
4498
task :tag do
4599
api_token = ENV['GITHUB_API_TOKEN']
46-
if (api_token && (ENV['TRAVIS_PULL_REQUEST'] == 'false') && (ENV['TRAVIS_BRANCH']=='master'))
100+
if ((api_token) && (ENV['TRAVIS_PULL_REQUEST'] == 'false'))
47101
repo = ENV['TRAVIS_REPO_SLUG']
48102
@octokit = Octokit::Client.new(:access_token => api_token)
49103
begin
@@ -53,14 +107,31 @@ namespace :book do
53107
end
54108
new_patchlevel= last_version.split('.')[-1].to_i + 1
55109
new_version="2.1.#{new_patchlevel}"
56-
obj = @octokit.create_tag(repo, new_version, "Version " + new_version, ENV['TRAVIS_COMMIT'],
57-
'commit',
58-
'Automatic build', '[email protected]',
59-
Time.now.utc.iso8601)
60-
@octokit.create_ref(repo, "tags/#{new_version}", obj.sha)
61-
p "Created tag #{new_version}"
110+
if (ENV['TRAVIS_BRANCH']=='master')
111+
obj = @octokit.create_tag(repo, new_version, "Version " + new_version,
112+
ENV['TRAVIS_COMMIT'], 'commit',
113+
'Automatic build', '[email protected]',
114+
Time.now.utc.iso8601)
115+
begin
116+
@octokit.create_ref(repo, "tags/#{new_version}", obj.sha)
117+
rescue
118+
p "the ref already exists ???"
119+
end
120+
p "Created tag #{last_version}"
121+
elsif (ENV['TRAVIS_TAG'])
122+
version = ENV['TRAVIS_TAG']
123+
changelog = GitHubChangelogGenerator.get_log do |config|
124+
config[:since_tag] = last_version
125+
end
126+
credit_line = "\\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*"
127+
changelog.gsub!(credit_line, "")
128+
@octokit.create_release(repo, new_version, {:name => "v#{new_version}", :body => changelog})
129+
p "Created release #{new_version}"
130+
else
131+
p 'This only runs on a commit to master'
132+
end
62133
else
63-
p 'This only runs on a commit to master'
134+
p 'No interaction with GitHub'
64135
end
65136
end
66137

@@ -109,7 +180,7 @@ namespace :book do
109180
chap = "ch#{num}-#{title}"
110181
end
111182
Dir[File.join ["book","#{num}-#{title}", "*.asc"]].map { |filename|
112-
File.read(filename).scan(/\[\[(.*?)\]\]/)
183+
File.read(filename).scan(/\[\[([_a-z0-9]*?)\]\]/)
113184
}.flatten.each { |ref|
114185
headrefs[ref] = "#{chap}"
115186
}
@@ -127,8 +198,8 @@ namespace :book do
127198
p files
128199
files.each { |filename|
129200
content = File.read(filename)
130-
new_contents = content.gsub(/\[\[(.*?)\]\]/, '[[r\1]]').gsub(
131-
"&rarr;", "→").gsub(/<<(.*?)>>/) { |match|
201+
new_contents = content.gsub(/\[\[([_a-z0-9]*?)\]\]/, '[[r\1]]').gsub(
202+
"&rarr;", "→").gsub(/<<([_a-z0-9]*?)>>/) { |match|
132203
ch = crossrefs[$1]
133204
h = headrefs[$1]
134205
# p " #{match} -> #{ch}, #{h}"
@@ -145,6 +216,9 @@ namespace :book do
145216
else
146217
"<<#{h}##{h}>>"
147218
end
219+
else
220+
p "could not match xref #{$1}"
221+
"<<#{$1}>>"
148222
end
149223
}
150224
File.open(filename, "w") {|file| file.puts new_contents }

0 commit comments

Comments
 (0)