-
Notifications
You must be signed in to change notification settings - Fork 88
/
Rakefile
107 lines (85 loc) · 3.08 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
require 'bundler'
Bundler::GemHelper.install_tasks
desc 'Run all specs'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = (ENV['CI'] == 'true')
end
task default: :spec
class Releaser
def initialize(options = {})
@project_name = options.delete(:project_name) { raise 'project_name is needed!' }
@gem_name = options.delete(:gem_name) { raise 'gem_name is needed!' }
@github_repo = options.delete(:github_repo) { raise 'github_repo is needed!' }
@version = options.delete(:version) { raise 'version is needed!' }
end
def full
rubygems
github
end
def rubygems
input = ''
begin
puts "Release #{@project_name} #{@version} to RubyGems? (y/n)"
input = STDIN.gets.chomp.downcase
end while !%w[y n].include?(input)
exit if input == 'n'
Rake::Task['release'].invoke
end
def github
require 'gems'
if @version != Gems.info(@gem_name)['version']
puts "#{@project_name} #{@version} is not yet released."
puts "Please release it first with: rake release:gem"
exit
end
tags = `git ls-remote --tags origin`.split("\n")
unless tags.find { |tag| tag =~ /v#{@version}$/ }
puts "The tag v#{@version} has not yet been pushed."
puts "Please push it first with: rake release:gem"
exit
end
require 'octokit'
gh_client = Octokit::Client.new(netrc: true)
gh_releases = gh_client.releases(@github_repo)
tag_name = "v#{@version}"
if gh_release = gh_releases.find { |r| r.tag_name == tag_name && r.draft == true }
input = ''
puts "Draft release for #{tag_name}:\n"
puts gh_release.body
puts "\n-------------------------\n\n"
begin
puts "Would you like to publish this GitHub release now? (y/n)"
input = STDIN.gets.chomp.downcase
end while !%w[y n].include?(input)
exit if input == 'n'
if gh_client.update_release(gh_release.rels[:self].href, draft: false)
gh_release = gh_client.releases(@github_repo).find { |r| r.tag_name == tag_name && r.draft == false }
puts "GitHub release #{tag_name} has been published!"
puts "\nPlease enjoy and spread the word!"
puts "Lack of inspiration? Here's a tweet you could improve:\n\n"
puts "Just released #{@project_name} #{@version}! #{gh_release.rels[:html].href}"
else
puts "GitHub release #{tag_name} couldn't be published!"
end
end
end
end
PROJECT_NAME = 'Guard::Minitest'
CURRENT_VERSION = Guard::MinitestVersion::VERSION
def releaser
$releaser ||= Releaser.new(project_name: PROJECT_NAME, gem_name: 'guard-minitest',
github_repo: 'guard/guard-minitest', version: CURRENT_VERSION)
end
namespace :release do
desc "Push #{PROJECT_NAME} #{CURRENT_VERSION} to RubyGems and publish its GitHub release"
task full: ['release:gem', 'release:github']
desc "Push #{PROJECT_NAME} #{CURRENT_VERSION} to RubyGems"
task :gem do
releaser.rubygems
end
desc "Publish #{PROJECT_NAME} #{CURRENT_VERSION} GitHub release"
task :github do
releaser.github
end
end