1
1
# coding: utf-8
2
2
require 'octokit'
3
+ require 'github_changelog_generator'
3
4
4
5
def exec_or_raise ( command )
5
6
puts `#{ command } `
@@ -8,42 +9,95 @@ def exec_or_raise(command)
8
9
end
9
10
end
10
11
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
+
11
42
namespace :book do
12
43
desc 'build basic book formats'
13
44
task :build do
14
45
15
46
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 }
17
60
18
61
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"
21
64
22
65
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"
25
68
26
- exec_or_raise ( "epubcheck progit .epub" )
69
+ exec_or_raise ( "epubcheck #{ progit_v } .epub" )
27
70
28
71
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"
31
76
32
77
repo = ENV [ 'TRAVIS_REPO_SLUG' ]
33
78
puts "Converting to PDF... (this one takes a while)"
34
79
if ( repo == "progit/progit2-zh" )
35
80
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" )
37
91
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" )
39
93
end
40
- puts " -- PDF output at progit .pdf"
94
+ puts " -- PDF output at #{ progit_v } .pdf"
41
95
end
42
96
43
97
desc 'tag the repo with the latest version'
44
98
task :tag do
45
99
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' ) )
47
101
repo = ENV [ 'TRAVIS_REPO_SLUG' ]
48
102
@octokit = Octokit ::Client . new ( :access_token => api_token )
49
103
begin
@@ -53,14 +107,31 @@ namespace :book do
53
107
end
54
108
new_patchlevel = last_version . split ( '.' ) [ -1 ] . to_i + 1
55
109
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
62
133
else
63
- p 'This only runs on a commit to master '
134
+ p 'No interaction with GitHub '
64
135
end
65
136
end
66
137
@@ -109,7 +180,7 @@ namespace :book do
109
180
chap = "ch#{ num } -#{ title } "
110
181
end
111
182
Dir [ File . join [ "book" , "#{ num } -#{ title } " , "*.asc" ] ] . map { |filename |
112
- File . read ( filename ) . scan ( /\[ \[ (. *?)\] \] / )
183
+ File . read ( filename ) . scan ( /\[ \[ ([_a-z0-9] *?)\] \] / )
113
184
} . flatten . each { |ref |
114
185
headrefs [ ref ] = "#{ chap } "
115
186
}
@@ -127,8 +198,8 @@ namespace :book do
127
198
p files
128
199
files . each { |filename |
129
200
content = File . read ( filename )
130
- new_contents = content . gsub ( /\[ \[ (. *?)\] \] / , '[[r\1]]' ) . gsub (
131
- "→" , "→" ) . gsub ( /<<(. *?)>>/ ) { |match |
201
+ new_contents = content . gsub ( /\[ \[ ([_a-z0-9] *?)\] \] / , '[[r\1]]' ) . gsub (
202
+ "→" , "→" ) . gsub ( /<<([_a-z0-9] *?)>>/ ) { |match |
132
203
ch = crossrefs [ $1]
133
204
h = headrefs [ $1]
134
205
# p " #{match} -> #{ch}, #{h}"
@@ -145,6 +216,9 @@ namespace :book do
145
216
else
146
217
"<<#{ h } ##{ h } >>"
147
218
end
219
+ else
220
+ p "could not match xref #{ $1} "
221
+ "<<#{ $1} >>"
148
222
end
149
223
}
150
224
File . open ( filename , "w" ) { |file | file . puts new_contents }
0 commit comments