-
Notifications
You must be signed in to change notification settings - Fork 0
/
common.rake
87 lines (72 loc) · 2 KB
/
common.rake
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
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = %w(-fs --color)
t.pattern = 'spec/**/*_spec.rb'
end
task default: :spec
def prompt(prompt_string = 'Proceed')
loop do
print "#{prompt_string}? (y/n) "
response = STDIN.gets.chomp
return if response =~ /\A\s*(ye?)s?\s*\z/i
exit if response =~ /\A\s*no?\s*\z/i
end
end
# Like `Kernel#system`, but complains noisily in the event of an error.
def system!(*args)
system *args
unless $?.success?
raise "command #{args.inspect} failed with exit status #{$?.exitstatus}"
end
end
RELEASE_PREREQS = %i[
require_bundle
require_clean_worktree
require_gerrit_annotations
]
task :require_bundle do
system! 'bundle check'
end
task :require_clean_worktree do
system 'git diff --quiet'
if !$?.success? && !ENV['ALLOW_DIRTY_WORKTREE']
raise 'worktree is dirty (set ALLOW_DIRTY_WORKTREE=1 to force)'
end
end
task :require_gerrit_annotations do
required_annotations = [
%r{^ {4}Change-Id: I[0-9a-f]{40}$},
%r{^ {4}Reviewed-on: https://gerrit\.causes\.com/\d{5,}$},
%r{^ {4}Reviewed-by: .+ <.+@.+>$},
%r{^ {4}Tested-by: .+ <.+@.+>$},
]
head = `git log -1`
unless required_annotations.all? { |regexp| head =~ regexp }
raise 'required Gerrit annotations missing (was commit not cherry-picked?)'
end
end
gem = "#{@gem}-#{@version}.gem"
file gem do
system "gem build #{@gem}.gemspec"
end
desc "build #{@gem} gem (#{gem})"
task build: gem
desc "push #{@gem} gem (#{gem}) to RubyGems"
task push: [gem] + RELEASE_PREREQS do
prompt "Push #{@gem} to RubyGems"
system "gem push #{gem}"
end
tag = "#{@gem}/v#{@version}"
desc "tag #{@gem} release (#{tag})"
task tag: RELEASE_PREREQS do
system 'git log -1'
puts
message = "#{@version} release"
prompt "Tag current HEAD (shown above) with #{tag} (#{message})"
system! "git tag #{tag} -m '#{message}'"
puts
system 'git remote show -n origin'
puts
prompt "Push tags to origin (shown above)"
system! 'git push origin --tags'
end