forked from apache/whimsy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
217 lines (184 loc) · 5.41 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
211
212
213
214
215
216
217
# Need relative path for CI such as Travis
lib = File.expand_path('../' * 3 + 'lib', __dir__)
$LOAD_PATH.unshift lib unless $LOAD_PATH.include? lib
# Remove world writable directories that Travis may insert into the PATH,
# as these cause security errors during testing
# ENV['PATH'] = ENV['PATH'].split(File::PATH_SEPARATOR).
# reject {|path| File.world_writable? path}.join(File::PATH_SEPARATOR)
require 'whimsy/asf/config'
require 'rspec/core/rake_task'
raketask = RSpec::Core::RakeTask.new(:spec)
rspec_opts = ENV['RSPEC_OPTS']
raketask.rspec_opts = rspec_opts if rspec_opts
task :default => :spec
task :spec => 'test:setup'
task :test => :spec
## Run system and abort if it fails
def system!(*args)
system(*args) or raise "system(#{args}) failed!"
end
# setup authentication
task :auth do
require 'etc'
require 'io/console'
require 'base64'
user = ENV['USER'] || ETC.getlogin
STDOUT.write "Enter password for #{user}: "
password = STDIN.noecho(&:gets).chomp
ENV['HTTP_AUTHORIZATION'] = "Basic #{Base64.encode64("#{user}:#{password}")}"
STDOUT.puts
end
task :server => [:bundle, :listen] do
ENV['DOCUMENT_ROOT'] = File.expand_path('../..', Dir.pwd)
ENV['RACK_ENV']='development'
ENV['OBJC_DISABLE_INITIALIZE_FORK_SAFETY']='YES' if RUBY_PLATFORM =~ /darwin/
at_exit {sleep 0.5}
sh 'bundle exec passenger start'
end
namespace :server do
task :test => :work do
ENV['DOCUMENT_ROOT'] = File.expand_path('../..', Dir.pwd)
ENV['RACK_ENV']='test'
ENV['USER']='test'
require 'bundler'
Bundler.require(:default, :test)
require 'wunderbar/listen'
end
end
task "touch" do
sh 'touch', File.expand_path('../tmp/restart.txt', __FILE__)
end
file 'package-lock.json' => 'package.json' do
sh 'npm install'
sh 'touch package-lock.json'
sh 'npm audit fix --force' # as advised in GH action log
end
file 'test/work' do
mkdir_p 'test/work'
end
file 'test/work/repository' => 'test/work' do
unless File.exist? 'test/work/repository/format'
system! 'svnadmin create test/work/repository'
end
end
file 'test/work/board' => 'test/work/repository' do
Dir.chdir('test/work') do
rm_rf 'board' if File.exist? 'board'
system! "svn co file:///#{Dir.pwd}/repository board"
cp Dir['../data/*.txt'], 'board'
Dir.chdir('board') {system! 'svn add *.txt; svn commit -m "initial commit"'}
end
end
testfiles = %w(board_minutes_2015_01_21 board_minutes_2015_02_18 test)
testfiles.each do |testfile|
file "test/work/data/#{testfile}.yml" do
mkdir_p 'test/work/data' unless File.exist? 'test/work/data'
cp "test/#{testfile}.yml", "test/work/data/#{testfile}.yml"
end
end
task :reset do
testfiles.each do |testfile|
if File.exist? "test/work/data/#{testfile}.yml"
if
IO.read("test/#{testfile}.yml") !=
IO.read("test/work/data/#{testfile}.yml")
then
rm "test/work/data/#{testfile}.yml"
end
end
end
if
Dir['test/work/board/*'].any? do |file|
base = "test/data/#{File.basename file}"
not File.exist?(base) or IO.read(base) != IO.read(file)
end
then
rm_rf 'test/work/board'
end
unless Dir.exist? 'test/work/board'
rm_rf 'test/work/repository'
end
end
task :work => ['test/work/board',
*testfiles.map {|testfile| "test/work/data/#{testfile}.yml"}]
namespace :test do
task :setup => [:clean, :reset, :work, 'package-lock.json']
task :server => 'server:test'
task :stress => :setup do
ruby 'test/stresstest.rb'
end
end
task :clobber do
rm_rf 'test/work'
end
task :update do
# update agenda application
Dir.chdir File.dirname(__FILE__) do
puts "#{File.dirname(File.realpath(__FILE__))}:"
system! 'git pull'
end
# update libs
if File.exist? "#{ENV['HOME']}/.whimsy"
libs = YAML.load_file("#{ENV['HOME']}/.whimsy")[:lib] || []
libs.each do |lib|
puts "\n#{lib}:"
if not File.exist? lib
puts 'not found'
next
end
# determine repository type
repository = :none
parent = File.realpath(lib)
while repository == :none and parent != '/'
if File.exist? File.join(parent, '.svn')
repository = :svn
elsif File.exist? File.join(parent, '.git')
repository = :git
else
parent = File.dirname(parent)
end
end
# update repository
Dir.chdir lib do
system! 'svn up' if repository == :svn
system! 'git pull' if repository == :git
end
end
end
# update gems
puts "\nbundle update:"
system! 'bundle update'
end
namespace :svn do
task :update do
ASF::Config.get(:svn).each do |svn|
if Dir.exist? svn
puts "\n#{svn}:"
Dir.chdir(svn) {system! 'svn up'}
end
end
end
end
task :bundle => 'Gemfile.lock' do
require 'bundler'
Bundler.require(:default, :development)
end
# restart server when files update
task :listen => :bundle do
dirs = [
File.expand_path('..', File.realpath(__FILE__)),
File.expand_path('../../../../lib', File.realpath(__FILE__))
]
listener = Listen.to(*dirs) do |modified, added, removed|
puts "detected update: #{(modified + added + removed).join(', ')}"
FileUtils.touch "#{dirs.first}/tmp/restart.txt"
end
listener.ignore /~$/
listener.ignore /^\..*\.sw\w$/
listener.ignore /passenger.\d+\.(log|pid(\.lock)?)$/
listener.start
end
# cleanup
require 'rake/clean'
CLEAN.include 'passenger.3000.*', 'test/work', 'public/assets'
CLOBBER.include 'node_modules', 'package-lock.json'