forked from heroku/legacy-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
205 lines (168 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
194
195
196
197
198
199
200
201
202
203
204
205
require "rubygems"
PROJECT_ROOT = File.expand_path("..", __FILE__)
$:.unshift "#{PROJECT_ROOT}/lib"
require "heroku/version"
require "rspec/core/rake_task"
desc "Run all specs"
RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = true
end
task :default => :spec
## dist
require "erb"
require "fileutils"
require "tmpdir"
def assemble(source, target, perms=0644)
FileUtils.mkdir_p(File.dirname(target))
File.open(target, "w") do |f|
f.puts ERB.new(File.read(source)).result(binding)
end
File.chmod(perms, target)
end
def assemble_distribution(target_dir=Dir.pwd)
distribution_files.each do |source|
target = source.gsub(/^#{project_root}/, target_dir)
FileUtils.mkdir_p(File.dirname(target))
FileUtils.cp(source, target)
end
end
GEM_BLACKLIST = %w( bundler heroku )
def assemble_gems(target_dir=Dir.pwd)
lines = %x{ bundle show }.strip.split("\n")
raise "error running bundler" unless $?.success?
%x{ env BUNDLE_WITHOUT="development:test" bundle show }.split("\n").each do |line|
if line =~ /^ \* (.*?) \((.*?)\)/
next if GEM_BLACKLIST.include?($1)
puts "vendoring: #{$1}-#{$2}"
gem_dir = %x{ bundle show #{$1} }.strip
FileUtils.mkdir_p "#{target_dir}/vendor/gems"
%x{ cp -R "#{gem_dir}" "#{target_dir}/vendor/gems" }
end
end.compact
end
def beta?
Heroku::VERSION.to_s =~ /pre/
end
def clean(file)
rm file if File.exists?(file)
end
def distribution_files(type=nil)
require "heroku/distribution"
base_files = Heroku::Distribution.files
type_files = type ?
Dir[File.expand_path("../dist/resources/#{type}/**/*", __FILE__)] :
[]
#base_files.concat(type_files)
base_files
end
def mkchdir(dir)
FileUtils.mkdir_p(dir)
Dir.chdir(dir) do |dir|
yield(File.expand_path(dir))
end
end
def pkg(filename)
FileUtils.mkdir_p("pkg")
File.expand_path("../pkg/#{filename}", __FILE__)
end
def project_root
File.dirname(__FILE__)
end
def resource(name)
File.expand_path("../dist/resources/#{name}", __FILE__)
end
def s3_connect
return if @s3_connected
require "aws/s3"
unless ENV["HEROKU_RELEASE_ACCESS"] && ENV["HEROKU_RELEASE_SECRET"]
puts "please set HEROKU_RELEASE_ACCESS and HEROKU_RELEASE_SECRET in your environment"
exit 1
end
AWS::S3::Base.establish_connection!(
:access_key_id => ENV["HEROKU_RELEASE_ACCESS"],
:secret_access_key => ENV["HEROKU_RELEASE_SECRET"]
)
@s3_connected = true
end
def store(package_file, filename, bucket="assets.heroku.com")
s3_connect
puts "storing: #{filename}"
AWS::S3::S3Object.store(filename, File.open(package_file), bucket, :access => :public_read)
end
def tempdir
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
yield(dir)
end
end
end
def version
require "heroku/version"
Heroku::VERSION
end
Dir[File.expand_path("../dist/**/*.rake", __FILE__)].each do |rake|
import rake
end
def poll_ci
require("vendor/heroku/okjson")
require("net/http")
data = Heroku::OkJson.decode(Net::HTTP.get("travis-ci.org", "/heroku/heroku.json"))
case data["last_build_status"]
when nil
print(".")
sleep(1)
poll_ci
when 0
puts("SUCCESS")
when 1
puts("FAILURE")
end
end
desc("Check current ci status and/or wait for build to finish.")
task "ci" do
poll_ci
end
desc("open jenkins")
task "jenkins" do
`open http://dx-jenkins.herokai.com`
end
desc("Create a new changelog article")
task "changelog" do
changelog = <<-CHANGELOG
Heroku CLI v#{version} released with
A new version of the Heroku CLI is available with
See the [CLI changelog](https://github.com/heroku/heroku/blob/master/CHANGELOG) for details and update by using \\`heroku update\\`.
CHANGELOG
`echo "#{changelog}" | pbcopy`
`open http://devcenter.heroku.com/admin/changelog_items/new`
end
desc("Release the latest version")
task "release" => ["gem:release", "jenkins", "tgz:release", "zip:release"] do
puts("Released v#{version}")
end
desc("Display statistics")
task "stats" do
require "heroku/command"
Dir[File.join(File.dirname(__FILE__), 'lib', 'heroku', 'command', '*.rb')].each do |file|
require(file)
end
commands, namespaces = Hash.new {|hash, key| hash[key] = 0}, []
Heroku::Command.commands.keys.each do |key|
data = key.split(':')
unless data.first == data.last
commands[data.last] += 1
end
namespaces |= [data.first]
end
puts "#{namespaces.length} Namespaces:"
puts "#{namespaces.join(', ')}"
puts
puts "#{commands.keys.length} Commands:"
max = commands.values.max
max.downto(0).each do |count|
keys = commands.keys.select {|key| commands[key] == count}
unless keys.empty?
puts("#{count}x #{keys.join(', ')}")
end
end
end