This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Rakefile
193 lines (146 loc) · 4.6 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
# frozen_string_literal: true
require "rubygems"
require 'rspec/core/rake_task'
REPO = 'cerner/splunk-pickaxe'
RSpec::Core::RakeTask.new(:test) do |t|
t.rspec_opts = '--format documentation'
end
task :default => [:test]
task :release do
intialize_octokit
puts "Releasing the gem ..."
spec = Gem::Specification::load("splunk-pickaxe.gemspec")
version = spec.version.to_s
# Update change log
puts "Updating change log ..."
update_change_log version
puts "Change log updated!"
puts "Publishing the gem ..."
run_command 'gem build splunk-pickaxe.gemspec'
run_command "gem push splunk-pickaxe-#{version}.gem"
run_command "rm -f splunk-pickaxe-#{version}.gem"
puts "Gem published!"
puts "Creating git tag ..."
run_command "git tag #{version}"
run_command "git push origin #{version}"
puts "Git tag created!"
puts "Updating to next version ..."
update_version version
puts "Version updated!"
puts "Gem released!"
end
task :build_change_log do
intialize_octokit
closed_milestones = @octokit.milestones REPO, {:state => "closed"}
version_to_milestone = Hash.new
versions = Array.new
closed_milestones.each do |milestone|
version = Gem::Version.new(milestone.title)
version_to_milestone.store version, milestone
versions.push version
end
versions = versions.sort.reverse
change_log = File.open('CHANGELOG.md', 'w')
begin
change_log.write "Change Log\n"
change_log.write "==========\n"
change_log.write "\n"
versions.each do |version|
milestone = version_to_milestone[version]
change_log.write generate_milestone_markdown(milestone)
change_log.write "\n"
end
ensure
change_log.close
end
end
def intialize_octokit
require 'octokit'
if ENV['GITHUB_API_TOKEN']
@octokit = Octokit::Client.new(:access_token => ENV['GITHUB_API_TOKEN'])
else
@octokit = Octokit::Client.new
end
end
def update_change_log version
change_log_lines = IO.read(File.join(File.dirname(__FILE__), 'CHANGELOG.md')).split("\n")
change_log = File.open('CHANGELOG.md', 'w')
begin
# Keep change log title
change_log.write change_log_lines.shift
change_log.write "\n"
change_log.write change_log_lines.shift
change_log.write "\n"
change_log.write "\n"
# Write new milestone info
change_log.write generate_milestone_markdown(milestone(version))
# Add previous change log info
change_log_lines.each do |line|
change_log.write line
change_log.write "\n"
end
ensure
change_log.close
end
run_command "git add CHANGELOG.md"
run_command "git commit -m 'Added #{version} to change log'"
run_command "git push origin HEAD"
end
def generate_milestone_markdown milestone
strings = Array.new
title = "[#{milestone.title} - #{milestone.updated_at.strftime("%m-%d-%Y")}](https://github.com/#{REPO}/issues?milestone=#{milestone.number}&state=closed)"
strings.push "#{title}"
strings.push "-" * title.length
strings.push ""
issues = @octokit.issues REPO, {:milestone => milestone.number, :state => "closed"}
issues.each do |issue|
strings.push " * [#{issue_type issue}] [Issue-#{issue.number}](https://github.com/#{REPO}/issues/#{issue.number}) : #{issue.title}"
end
strings.push ""
strings.join "\n"
end
def milestone version
closedMilestones = @octokit.milestones REPO, {:state => "closed"}
closedMilestones.each do |milestone|
if milestone["title"] == version
return milestone
end
end
openMilestones = @octokit.milestones REPO
openMilestones.each do |milestone|
if milestone["title"] == version
return milestone
end
end
raise "Unable to find milestone with title [#{version}]"
end
def issue_type issue
labels = Array.new
issue.labels.each do |label|
labels.push label.name.capitalize
end
labels.join "/"
end
def run_command command
output = `#{command}`
unless $?.success?
raise "Command : [#{command}] failed.\nOutput : \n#{output}"
end
end
def update_version version
version_splits = version.split('.')
# Bump minor version up one
version_splits[1] = (version_splits[1].to_i + 1).to_s
# Ensure fix version is reset
version_splits[2] = 0
next_version = version_splits.join('.')
version_rb = IO.read('lib/splunk/pickaxe/version.rb')
new_version_rb = version_rb
.split("\n")
.map{|line| line.include?('VERSION =') ? " VERSION = '#{next_version}'" : line }
.join("\n")
File.write('lib/splunk/pickaxe/version.rb', new_version_rb)
run_command "git add lib/splunk/pickaxe/version.rb"
run_command "git commit -m 'Updated version to #{next_version}'"
run_command "git push origin HEAD"
end