-
Notifications
You must be signed in to change notification settings - Fork 368
/
Rakefile
210 lines (177 loc) · 5.36 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
# frozen_string_literal: true
require 'bundler'
require 'term/ansicolor'
require 'pathname'
require 'logger'
require './lib/dpl/version'
require 'highline'
require 'faraday'
include Term::ANSIColor
def cli
@cli ||= HighLine.new
end
@ready = false
def logger
@logger ||= Logger.new($stdout)
end
def top
@top ||= Pathname.new File.expand_path(File.dirname(__FILE__))
end
def gem_version
ENV['DPL_VERSION'] || Dpl::VERSION
end
def confirm(verb = 'release')
unless @ready
answer = cli.ask "Ready to #{verb} `dpl` version #{gem_version}? (y/n)"
if answer !~ /^y/i
abort red("Aborting #{verb}")
end
@ready = true
end
end
def dpl_bin
File.join(Gem.bindir, 'dpl')
end
gemspecs = FileList[File.join(top, 'dpl-*.gemspec')]
providers = gemspecs.map { |f| /dpl-(?<provider>.*)\.gemspec/ =~ f && provider }
desc 'Build dpl gem'
file "dpl-#{gem_version}.gem" do
logger.info green('Building dpl gem')
ruby '-S gem build dpl.gemspec'
end
desc 'Install dpl gem'
file dpl_bin => "dpl-#{gem_version}.gem" do
logger.info green('Installing dpl gem')
ruby "-S gem install dpl-#{gem_version}.gem"
end
task default: [:spec, Rake::FileTask[dpl_bin]] do
Rake::Task['spec_providers'].invoke
Rake::Task['check_providers'].invoke
end
desc 'Run spec on all providers'
task :spec_providers do
providers.each do |provider|
Rake::Task["spec-#{provider}"].invoke
end
end
desc 'Check all provider gems install correctly'
task :check_providers do
providers.each do |provider|
Rake::Task["check-#{provider}"].invoke
end
end
desc 'Build all gems'
task build: "dpl-#{gem_version}.gem" do
providers.each do |provider|
Rake::Task["dpl-#{provider}-#{gem_version}.gem"].invoke
end
end
desc 'Uninstall all gems'
task :uninstall do
providers.each do |provider|
Rake::Task["uninstall-#{provider}"].invoke
end
logger.info red('Uninstalling dpl')
sh 'gem uninstall -aIx dpl'
end
desc 'Release all gems'
task :release do
confirm
released = []
providers.each do |provider|
until released.include? provider
logger.info "checking dpl-#{provider}"
cli = Faraday.new url: 'https://rubygems.org'
begin
response = cli.get("/api/v2/rubygems/dpl-#{provider}/versions/#{gem_version}.json")
if response.success?
released << provider
logger.info green("dpl-#{provider} #{gem_version} exists")
next
else
begin
if Rake::Task["release-#{provider}"].invoke
released << provider
end
rescue StandardError
Rake::Task["release-#{provider}"].reenable
end
end
rescue Faraday::Error
logger.info yellow('connection failed. retrying')
retry
end
end
end
logger.info green("Pushing dpl-#{gem_version}.gem")
sh "gem push dpl-#{gem_version}.gem"
end
desc 'Yank all gems'
task :yank, [:version] do |_t, args|
version = args.version
confirm 'yank'
logger.info green("Yanking `dpl` version #{version}")
sh "gem yank dpl -v #{version}"
providers.each do |provider|
Rake::Task["yank-#{provider}"].invoke
end
end
task :deep_clean do
Rake::Task[:clean].invoke
sh 'git clean -dfx'
end
task :clean do
rm_rf 'stubs'
rm_rf 'vendor'
rm_rf 'dpl-*.gem'
Rake::Task[:uninstall].invoke
end
desc 'Run dpl specs'
task :spec do
ruby '-S rspec spec/cli_spec.rb spec/provider_spec.rb'
end
providers.each do |provider|
desc "Write Gemfile-#{provider}"
file "Gemfile-#{provider}" do |t|
gemfile = top + t.name
logger.info green("Writing #{gemfile}")
gemfile.write %(source 'https://rubygems.org'\ngemspec :name => "dpl-#{provider}"\n)
end
desc %(Run dpl-#{provider} specs)
task "spec-#{provider}", [:lines] => [Rake::FileTask[dpl_bin], "Gemfile-#{provider}"] do |_t, args|
tail = args.lines ? ":#{args.lines}" : ''
sh 'rm -f $HOME/.npmrc'
logger.info green("Running `bundle install` for #{provider}")
sh 'bash', '-cl', "bundle install --gemfile=Gemfile-#{provider} --path=vendor/cache/dpl-#{provider} --retry=3 --binstubs=stubs"
logger.info green("Running specs for #{provider}")
sh "env BUNDLE_GEMFILE=Gemfile-#{provider} ./stubs/rspec spec/provider/#{provider}_spec.rb#{tail}"
end
desc "Build dpl-#{provider} gem"
file "dpl-#{provider}-#{gem_version}.gem" do
logger.info green("Building dpl-#{provider} gem")
ruby "-S gem build --silent dpl-#{provider}.gemspec"
end
desc "Test dpl-#{provider} gem"
task "check-#{provider}" => [Rake::FileTask[dpl_bin], "dpl-#{provider}-#{gem_version}.gem"] do
logger.info green("Installing dpl-#{provider} gem")
sh "gem install --no-post-install-message dpl-#{provider}-#{gem_version}.gem"
logger.info green("Testing dpl-#{provider} loads correctly")
ruby "-S dpl --provider=#{provider} --stage=init"
end
desc "Uninstall dpl-#{provider}"
task "uninstall-#{provider}" do
logger.info red("Uninstalling dpl-#{provider}")
sh "gem uninstall -aIx dpl-#{provider}"
end
desc "Release dpl-#{provider} gem"
task "release-#{provider}" => "dpl-#{provider}-#{gem_version}.gem" do
confirm
logger.info green("Pushing dpl-#{provider}-#{gem_version}.gem")
sh "gem push dpl-#{provider}-#{gem_version}.gem"
end
desc "Yank dpl-#{provider}"
task "yank-#{provider}" do
logger.info green("Yanking dpl-#{provider} version #{gem_version}")
sh "gem yank dpl-#{provider} -v #{gem_version}"
end
end