-
-
Notifications
You must be signed in to change notification settings - Fork 535
Expand file tree
/
Copy pathsetup
More file actions
executable file
·218 lines (176 loc) · 4.99 KB
/
setup
File metadata and controls
executable file
·218 lines (176 loc) · 4.99 KB
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
218
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'optparse'
require 'fileutils'
require 'pathname'
class SetupScript
WORKSPACE_FOLDERS = %w[
.
spec/apps/rails-mini
sentry-ruby
sentry-rails
sentry-sidekiq
sentry-delayed_job
sentry-resque
sentry-opentelemetry
].freeze
def initialize
@options = {
only_folders: [],
only_bundle: false,
only_npm: false,
with_foreman: false
}
@workspace_root = '/workspace/sentry'
end
def run(args)
parse_options(args)
Dir.chdir(@workspace_root)
if should_run_bundle?
cleanup_ruby_lsp_directories
update_rubygems_and_bundler
install_bundle_dependencies
install_foreman_gem if @options[:with_foreman]
end
if should_run_npm?
install_npm_dependencies
end
puts "✅ Post-create setup completed!"
end
private
def parse_options(args)
parser = OptionParser.new do |opts|
opts.banner = "Usage: setup.rb [options]"
opts.on("--only FOLDERS", Array, "Only process specified folders (comma-separated)") do |folders|
@options[:only_folders] = folders
end
opts.on("--only-bundle", "Only run bundle operations (skip npm)") do
@options[:only_bundle] = true
end
opts.on("--only-npm", "Only run npm operations (skip bundle)") do
@options[:only_npm] = true
end
opts.on("--with-foreman", "Install foreman gem (default: false)") do
@options[:with_foreman] = true
end
opts.on("-h", "--help", "Show this help message") do
puts opts
exit
end
end
parser.parse!(args)
if @options[:only_bundle] && @options[:only_npm]
puts "❌ Error: --only-bundle and --only-npm are mutually exclusive"
exit 1
end
end
def should_run_bundle?
!@options[:only_npm]
end
def should_run_npm?
!@options[:only_bundle]
end
def target_folders
return @options[:only_folders] unless @options[:only_folders].empty?
WORKSPACE_FOLDERS
end
def all_folders
target_folders
end
def cleanup_ruby_lsp_directories
puts "🧹 Cleaning up .ruby-lsp directories..."
all_folders.each do |folder|
ruby_lsp_path = File.join(folder, '.ruby-lsp')
if Dir.exist?(ruby_lsp_path)
puts " Removing #{folder}/.ruby-lsp"
FileUtils.rm_rf(ruby_lsp_path)
end
end
end
def install_bundle_dependencies
puts "📦 Installing bundle dependencies for workspace folders..."
target_folders.each do |folder|
folder_path = File.join(@workspace_root, folder)
gemfile_path = File.join(folder_path, 'Gemfile')
if Dir.exist?(folder_path) && File.exist?(gemfile_path)
Dir.chdir(folder_path) do
puts " Installing dependencies for #{folder_path}..."
unless system("[ -f Gemfile.lock ] && rm Gemfile.lock; bundle install")
puts "❌ Bundle install failed for #{folder}"
exit 1
end
end
Dir.chdir(@workspace_root)
else
puts " Skipping #{folder} (no Gemfile found or directory doesn't exist)"
end
end
end
def update_rubygems_and_bundler
puts "📦 Updating RubyGems and Bundler..."
if RUBY_VERSION >= "3.0"
unless system("sudo gem update --system --silent")
puts "❌ RubyGems update failed"
exit 1
end
else
unless system("sudo gem update --silent --system 3.4.22")
puts "❌ RubyGems update failed"
exit 1
end
# sentry-sidekiq does not bundle with Bundler 2.5.x that ships with RubyGems 3.4.22
unless system("sudo gem install bundler -v 2.4.22")
puts "❌ Bundler installation failed"
exit 1
end
end
end
def install_foreman_gem
unless system('gem install foreman')
puts "❌ Foreman gem installation failed"
exit 1
end
end
def install_npm_dependencies
svelte_mini_path = File.join(@workspace_root, 'spec/apps/svelte-mini')
if Dir.exist?(svelte_mini_path)
Dir.chdir(svelte_mini_path) do
unless system('npm install')
puts "❌ npm install failed for svelte-mini"
exit 1
end
end
else
puts "❌ Svelte mini app directory not found: #{svelte_mini_path}"
exit 1
end
end
def run_with_spinner(message)
print "#{message} "
spinner_chars = %w[- \\ | /]
spinner_index = 0
spinner_running = true
spinner_thread = Thread.new do
while spinner_running
print "\r#{message} #{spinner_chars[spinner_index]}"
spinner_index = (spinner_index + 1) % spinner_chars.length
sleep 0.1
end
end
# Run the actual command
success = yield
# Stop spinner
spinner_running = false
spinner_thread.join
if success
puts "\r#{message} ✅"
else
puts "\r#{message} ❌"
puts "❌ Command failed. Please check for missing dependencies or run manually."
exit 1
end
end
end
if __FILE__ == $0
SetupScript.new.run(ARGV)
end