-
Notifications
You must be signed in to change notification settings - Fork 87
/
Rakefile
225 lines (177 loc) Β· 5.39 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
require "bundler/gem_tasks"
require "rake/testtask"
if ENV["VSCODE_CWD"]
require "minitest"
Minitest.seed = Time.now.to_i
end
Rake::TestTask.new(:test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList['test/**/*_test.rb']
end
task :default => :test
namespace :test do
desc "Run output test"
task :output do
sh "ruby", "bin/output_test.rb"
end
end
Rake::Task[:release].enhance do
Rake::Task[:"release:note"].invoke
Rake::Task[:"release:github"].invoke
Rake::Task[:"release:release-prs"].invoke
end
desc "Generate changelog template from GH pull requests"
task :changelog do
major, minor, patch, pre = Steep::VERSION.split(".", 4)
major = major.to_i
minor = minor.to_i
patch = patch.to_i
if patch == 0
milestone = "Steep #{major}.#{minor}"
else
milestone = "Steep #{major}.#{minor}.x"
end
puts "π Finding pull requests that is associated to milestone `#{milestone}`..."
command = [
"gh",
"pr",
"list",
"--json",
"url,title,number",
"--search" ,
"milestone:\"#{milestone}\" is:merged sort:updated-desc -label:Released"
]
require "open3"
output, status = Open3.capture2(*command)
raise status.inspect unless status.success?
require "json"
json = JSON.parse(output, symbolize_names: true)
unless json.empty?
puts
json.each do |line|
puts "* #{line[:title]} ([##{line[:number]}](#{line[:url]}))"
end
else
puts " (π€ There is no *unreleased* pull request associated to the milestone.)"
end
end
namespace :release do
desc "Ensure release note"
task :note do
version = Gem::Version.new(Steep::VERSION)
major, minor, patch, pre = Steep::VERSION.split(".", 4)
major = major.to_i
minor = minor.to_i
patch = patch.to_i
wiki_url = "https://github.com/soutaro/steep/wiki/Release-Note-#{major}.#{minor}"
puts "π§ Checking if Release note page already exists..."
unless `curl --silent -o/dev/null --head #{wiki_url} -w '%{http_code}'` == "200"
pre_flag = version.prerelease? ? " --pre" : ""
pre_requirement = version.prerelease? ? ", '~> #{major}.#{minor}.#{patch}.#{pre}'" : ""
puts "----"
puts <<~PREFIX if patch
**The latest version of Steep #{major}.#{minor} is `#{pre}`.**
PREFIX
puts <<~TEMPLATE
Some of the highlights in Steep #{major}.#{minor} are:
* New feature 1 (URL)
* New feature 2 (URL)
* New feature 3 (URL)
You can install it with `$ gem install steep#{pre_flag}` or using Bundler.
```rb
gem 'steep', require: false#{pre_requirement}
```
See the [CHANGELOG](https://github.com/soutaro/steep/blob/master/CHANGELOG.md) for the details.
## New feature 1
## New feature 2
## New feature 3
## Diagnostics updates
## Updating Steep
TEMPLATE
puts "----"
puts
puts " β©οΈ Create the release note with the template: #{wiki_url}"
else
if patch == 0 || version.prerelease?
puts " β©οΈ Open the release note and update it at: #{wiki_url}"
else
puts " β
Release note is ready!"
end
end
puts
end
desc "Create GitHub release automatically"
task :github do
version = Gem::Version.new(Steep::VERSION)
major, minor, patch, *_ = Steep::VERSION.split(".")
major = major.to_i
minor = minor.to_i
patch = patch.to_i
puts "βοΈ Making a draft release on GitHub..."
content = File.read(File.join(__dir__, "CHANGELOG.md"))
changelog = content.scan(/^## \d.*?(?=^## \d)/m)[0]
changelog = changelog.sub(/^.*\n^.*\n/, "").rstrip
notes = <<NOTES
[Release note](https://github.com/soutaro/steep/wiki/Release-Note-#{major}.#{minor})
#{changelog}
NOTES
command = [
"gh",
"release",
"create",
"--draft",
"v#{Steep::VERSION}",
"--title=#{Steep::VERSION}",
"--notes=#{notes}"
]
if version.prerelease?
command << "--prerelease"
end
require "open3"
output, status = Open3.capture2(*command)
if status.success?
puts " β©οΈ Done! Open #{output.chomp} and publish the release!"
puts
end
end
desc "Add `Released` labels to pull requests associated to the version"
task "release-prs" do
major, minor, patch, pre = Steep::VERSION.split(".", 4)
major = major.to_i
minor = minor.to_i
patch = patch.to_i
if patch == 0
milestone = "Steep #{major}.#{minor}"
else
milestone = "Steep #{major}.#{minor}.x"
end
if pre =~ /dev/
puts "π Skipping `Released` tags because `dev` release: `#{pre}`"
next
end
puts "π Finding pull requests that is associated to milestone `#{milestone}`..."
command = [
"gh",
"pr",
"list",
"--json",
"url,title,number",
"--search" ,
"milestone:\"#{milestone}\" is:merged sort:updated-desc -label:Released"
]
require "open3"
output, status = Open3.capture2(*command)
raise status.inspect unless status.success?
require "json"
json = JSON.parse(output, symbolize_names: true)
puts " β
Found #{json.size} PRs..."
json.each do |pr|
puts "π§ Updating #{pr[:url]}..."
output, status = Open3.capture2("gh", "pr", "edit", pr[:number].to_s, "--add-label", "Released")
raise status.inspect unless status.success?
puts " β
Done!"
sleep 0.5
end
end
end