-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
191 lines (162 loc) · 5.22 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
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
require "rubocop/rake_task"
require "rspec/core/rake_task"
require File.expand_path("../lib/nginxtra/version.rb", __FILE__)
def system_exec(cmd)
puts "Executing: #{cmd}"
results = `#{cmd}`
puts results unless results.strip.empty?
end
module Nginxtra
class Gem
class << self
def dependencies
{ thor: "~> 0.16" }
end
def to_s
"nginxtra-#{Nginxtra::Version}.gem"
end
end
end
end
def update_version(next_version)
puts "Generating version.rb"
File.write File.expand_path("../lib/nginxtra/version.rb", __FILE__), %{module Nginxtra
class Version
class << self
def to_a
to_s.split(".").map(&:to_i)
end
def to_s
"#{next_version}"
end
end
end
end
}
load File.expand_path("../lib/nginxtra/version.rb", __FILE__)
Rake::Task[:generate].execute
end
def update_nginx
doc = Nokogiri::HTML(open("http://nginx.org/en/download.html"))
stable_node = doc.search "[text()*='Stable version']"
if stable_node.size != 1
puts "Could not find just 1 'Stable version' node, found #{stable_node.size}"
return
end
results = doc.search("[text()*='Stable version']").first.parent.next.search("a").select { |x| x.attr("href") =~ %r{/nginx-\d+\.\d+\.\d+\.tar\.gz$} }
if results.size != 1
puts "Could not find just 1 link for the nginx-VERSION.tar.gz download, found #{results.size}"
return
end
path = results.first.attr "href"
unless path =~ %r{^/(?:.*/)?nginx-(\d+\.\d+\.\d+)\.tar\.gz$}
puts "Unexpected path style, expected /something, got: '#{path}'"
return
end
next_version = Regexp.last_match[1]
filename = "nginx-#{next_version}.tar.gz"
full_output_path = File.expand_path "../#{filename}", __FILE__
if File.exist? full_output_path
puts "Skipping already downloaded file"
else
url = "http://nginx.org#{path}"
puts "Downloading from #{url}"
open url do |download|
File.open full_output_path, "w" do |out|
out.write download.read
end
end
end
vendor_path = File.expand_path "../vendor", __FILE__
nginx_path = File.join vendor_path, "nginx"
extracted_dir = File.expand_path "../vendor/nginx-#{next_version}", __FILE__
system_exec "git rm -r #{nginx_path}"
system_exec "mkdir #{vendor_path}"
system_exec "tar -C #{vendor_path} -xz -f #{full_output_path}"
system_exec "mv #{extracted_dir} #{nginx_path}"
system_exec "git add #{nginx_path}"
update_version "#{next_version}.#{Nginxtra::Version.to_a[-1]}"
end
task default: :install
task :update_nginx do
gem "nokogiri"
require "nokogiri"
require "open-uri"
update_nginx
end
task :increment_version do
parts = Nginxtra::Version.to_a
parts[-1] += 1
next_version = parts.join "."
update_version next_version
end
task :decrement_version do
parts = Nginxtra::Version.to_a
parts[-1] -= 1
next_version = parts.join "."
update_version next_version
end
task :generate do
puts "Generating nginxtra.gemspec"
File.write File.expand_path("../nginxtra.gemspec", __FILE__), %(# Note: This gemspec generated by the Rakefile
require "rubygems/package_task"
Gem::Specification.new do |s|
s.name = "nginxtra"
s.version = "#{Nginxtra::Version}"
s.summary = "Wrapper of nginx for easy install and use."
s.description = "This gem is intended to provide an easy to use configuration file that will automatically be " \\
"used to compile nginx and configure the configuration."
s.author = "Mike Virata-Stone"
s.email = "mike@virata-stone.com"
s.license = "nginx"
s.files = FileList["bin/**/*", "lib/**/*", "templates/**/*", "vendor/**/*"]
s.require_path = "lib"
s.bindir = "bin"
s.executables = %w(nginxtra nginxtra_rails)
s.homepage = "https://github.com/smellsblue/nginxtra"
s.add_runtime_dependency "thor", "#{Nginxtra::Gem.dependencies[:thor]}"
s.add_development_dependency "nokogiri", "~> 1.6"
s.add_development_dependency "rake", "~> 10.0"
s.add_development_dependency "rspec", "~> 3.3"
s.add_development_dependency "rubocop", "~> 0.38.0"
end
)
puts "Generating bin/nginxtra"
File.write File.expand_path("../bin/nginxtra", __FILE__), %(#!/usr/bin/env ruby
require "rubygems"
gem "nginxtra", "= #{Nginxtra::Version}"
gem "thor", "#{Nginxtra::Gem.dependencies[:thor]}"
require "nginxtra"
Nginxtra::CLI.start
)
puts "Generating bin/nginxtra_rails"
File.write File.expand_path("../bin/nginxtra_rails", __FILE__), %(#!/usr/bin/env ruby
require "rubygems"
gem "nginxtra", "= #{Nginxtra::Version}"
gem "thor", "#{Nginxtra::Gem.dependencies[:thor]}"
require "nginxtra"
Nginxtra::Rails::CLI.start
)
end
task build: :generate do
puts "Building nginxtra"
system_exec "gem build nginxtra.gemspec"
end
task install: :build do
puts "Installing nginxtra"
system_exec "gem install --no-ri --no-rdoc #{Nginxtra::Gem}"
end
task :tag do
puts "Tagging nginxtra"
system_exec "git tag -a #{Nginxtra::Version} -m 'Version #{Nginxtra::Version}' && git push --tags"
end
task push: :build do
puts "Pushing nginxtra"
system_exec "gem push #{Nginxtra::Gem}"
end
RuboCop::RakeTask.new
desc "Run specs"
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = %w(--color)
end