"Fossies" - the Fresh Open Source Software Archive 
Member "discourse-2.8.3/lib/tasks/docker.rake" (14 Apr 2022, 9969 Bytes) of package /linux/www/discourse-2.8.3.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ruby source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "docker.rake":
2.7.13_vs_2.8.0.
1 # frozen_string_literal: true
2
3 # rake docker:test is designed to be used inside the discourse/docker_test image
4 # running it anywhere else will likely fail
5 #
6 # Environment Variables (specific to this rake task)
7 # => SKIP_LINT set to 1 to skip linting (eslint and rubocop)
8 # => SKIP_TESTS set to 1 to skip all tests
9 # => SKIP_CORE set to 1 to skip core tests (rspec and qunit)
10 # => SKIP_PLUGINS set to 1 to skip plugin tests (rspec and qunit)
11 # => SKIP_INSTALL_PLUGINS comma separated list of plugins you want to skip installing
12 # => INSTALL_OFFICIAL_PLUGINS set to 1 to install all core plugins before running tests
13 # => RUBY_ONLY set to 1 to skip all qunit tests
14 # => JS_ONLY set to 1 to skip all rspec tests
15 # => SINGLE_PLUGIN set to plugin name to only run plugin-specific rspec tests (you'll probably want to SKIP_CORE as well)
16 # => BISECT set to 1 to run rspec --bisect (applies to core rspec tests only)
17 # => RSPEC_SEED set to seed to use for rspec tests (applies to core rspec tests only)
18 # => PAUSE_ON_TERMINATE set to 1 to pause prior to terminating redis and pg
19 # => JS_TIMEOUT set timeout for qunit tests in ms
20 # => WARMUP_TMP_FOLDER runs a single spec to warmup the tmp folder and obtain accurate results when profiling specs.
21 # => EMBER_CLI set to 1 to run JS tests using the Ember CLI
22 # => EMBER_CLI_BROWSERS comma separated list of browsers to test against. Options are Chrome, Firefox, and Headless Firefox.
23 #
24 # Other useful environment variables (not specific to this rake task)
25 # => COMMIT_HASH used by the discourse_test docker image to load a specific commit of discourse
26 # this can also be set to a branch, e.g. "origin/tests-passed"
27 #
28 # Example usage:
29 # Run all core and plugin tests:
30 # docker run discourse/discourse_test:release
31 # Run only rspec tests:
32 # docker run -e RUBY_ONLY=1 discourse/discourse_test:release
33 # Run all plugin tests (with a plugin mounted from host filesystem):
34 # docker run -e SKIP_CORE=1 -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release
35 # Run tests for a specific plugin (with a plugin mounted from host filesystem):
36 # docker run -e SKIP_CORE=1 SINGLE_PLUGIN='my-awesome-plugin' -v $(pwd)/my-awesome-plugin:/var/www/discourse/plugins/my-awesome-plugin discourse/discourse_test:release
37
38 def run_or_fail(command)
39 log(command)
40 pid = Process.spawn(command)
41 Process.wait(pid)
42 $?.exitstatus == 0
43 end
44
45 def run_or_fail_prettier(*patterns)
46 if patterns.any? { |p| Dir[p].any? }
47 patterns = patterns.map { |p| "'#{p}'" }.join(' ')
48 run_or_fail("yarn prettier --list-different #{patterns}")
49 else
50 puts "Skipping prettier. Pattern not found."
51 true
52 end
53 end
54
55 def log(message)
56 puts "[#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}] #{message}"
57 end
58
59 desc 'Run all tests (JS and code in a standalone environment)'
60 task 'docker:test' do
61 begin
62 @good = true
63
64 unless ENV['SKIP_LINT']
65 @good &&= run_or_fail("yarn install")
66 puts "Running linters/prettyfiers"
67 puts "eslint #{`yarn eslint -v`}"
68 puts "prettier #{`yarn prettier -v`}"
69
70 if ENV["SINGLE_PLUGIN"]
71 @good &&= run_or_fail("bundle exec rubocop --parallel plugins/#{ENV["SINGLE_PLUGIN"]}")
72 @good &&= run_or_fail("bundle exec ruby script/i18n_lint.rb plugins/#{ENV["SINGLE_PLUGIN"]}/config/locales/{client,server}.en.yml")
73 @good &&= run_or_fail("yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins/#{ENV['SINGLE_PLUGIN']}")
74
75 puts "Listing prettier offenses in #{ENV['SINGLE_PLUGIN']}:"
76 @good &&= run_or_fail_prettier("plugins/#{ENV['SINGLE_PLUGIN']}/**/*.scss", "plugins/#{ENV['SINGLE_PLUGIN']}/**/*.{js,es6}")
77 else
78 @good &&= run_or_fail("bundle exec rake plugin:update_all") unless ENV["SKIP_PLUGINS"]
79 @good &&= run_or_fail("bundle exec rubocop --parallel") unless ENV["SKIP_CORE"]
80 @good &&= run_or_fail("yarn eslint app/assets/javascripts") unless ENV["SKIP_CORE"]
81 @good &&= run_or_fail("yarn eslint --ext .js,.js.es6 --no-error-on-unmatched-pattern plugins") unless ENV["SKIP_PLUGINS"]
82
83 @good &&= run_or_fail('bundle exec ruby script/i18n_lint.rb "config/locales/{client,server}.en.yml"') unless ENV["SKIP_CORE"]
84 @good &&= run_or_fail('bundle exec ruby script/i18n_lint.rb "plugins/**/locales/{client,server}.en.yml"') unless ENV["SKIP_PLUGINS"]
85
86 unless ENV["SKIP_CORE"]
87 puts "Listing prettier offenses in core:"
88 @good &&= run_or_fail('yarn prettier --list-different "app/assets/stylesheets/**/*.scss" "app/assets/javascripts/**/*.js"')
89 end
90
91 unless ENV["SKIP_PLUGINS"]
92 puts "Listing prettier offenses in plugins:"
93 @good &&= run_or_fail('yarn prettier --list-different "plugins/**/assets/stylesheets/**/*.scss" "plugins/**/assets/javascripts/**/*.{js,es6}"')
94 end
95 end
96 end
97
98 unless ENV['SKIP_TESTS']
99 puts "Cleaning up old test tmp data in tmp/test_data"
100 `rm -fr tmp/test_data && mkdir -p tmp/test_data/redis && mkdir tmp/test_data/pg`
101
102 puts "Starting background redis"
103 @redis_pid = Process.spawn('redis-server --dir tmp/test_data/redis')
104
105 puts "Initializing postgres"
106 system("script/start_test_db.rb --skip-run", exception: true)
107
108 puts "Starting postgres"
109 @pg_pid = Process.spawn("script/start_test_db.rb --skip-setup --exec")
110
111 ENV["RAILS_ENV"] = "test"
112 # this shaves all the creation of the multisite db off
113 # for js tests
114 ENV["SKIP_MULTISITE"] = "1" if ENV["JS_ONLY"]
115
116 @good &&= run_or_fail("bundle exec rake db:create")
117
118 if ENV['USE_TURBO']
119 @good &&= run_or_fail("bundle exec rake parallel:create")
120 end
121
122 if ENV["INSTALL_OFFICIAL_PLUGINS"]
123 @good &&= run_or_fail("bundle exec rake plugin:install_all_official")
124 end
125
126 if ENV["UPDATE_ALL_PLUGINS"]
127 @good &&= run_or_fail("bundle exec rake plugin:update_all")
128 end
129
130 if skip_install = ENV["SKIP_INSTALL_PLUGINS"]
131 skip_install.split(",").map(&:strip).each do |plugin|
132 puts "[SKIP_INSTALL_PLUGINS] Removing #{plugin}"
133 `rm -fr plugins/#{plugin}`
134 end
135 end
136
137 command_prefix =
138 if ENV["SKIP_PLUGINS"]
139 # Make sure not to load plugins. bin/rake will add LOAD_PLUGINS=1 automatically unless we set it to 0 explicitly
140 "LOAD_PLUGINS=0 "
141 else
142 "LOAD_PLUGINS=1 "
143 end
144
145 @good &&= run_or_fail("#{command_prefix}bundle exec rake db:migrate")
146
147 if ENV['USE_TURBO']
148 @good &&= run_or_fail("#{command_prefix}bundle exec rake parallel:migrate")
149 end
150
151 unless ENV["JS_ONLY"]
152 if ENV['WARMUP_TMP_FOLDER']
153 run_or_fail('bundle exec rspec ./spec/requests/groups_controller_spec.rb')
154 end
155
156 unless ENV["SKIP_CORE"]
157 params = []
158
159 unless ENV['USE_TURBO']
160 params << "--profile"
161 params << "--fail-fast"
162 if ENV["BISECT"]
163 params << "--bisect"
164 end
165 if ENV["RSPEC_SEED"]
166 params << "--seed #{ENV["RSPEC_SEED"]}"
167 end
168 end
169
170 if ENV['PARALLEL']
171 parts = ENV['PARALLEL'].split("/")
172 total = parts[1].to_i
173 subset = parts[0].to_i - 1
174
175 spec_partials = Dir["spec/**/*_spec.rb"].sort.in_groups(total, false)
176 # quick and dirty load balancing
177 if (spec_partials.count > 3)
178 spec_partials[0].concat(spec_partials[total - 1].shift(30))
179 spec_partials[1].concat(spec_partials[total - 2].shift(30))
180 end
181
182 params << spec_partials[subset].join(' ')
183
184 puts "Running spec subset #{subset + 1} of #{total}"
185 end
186
187 if ENV['USE_TURBO']
188 @good &&= run_or_fail("bundle exec ./bin/turbo_rspec --verbose #{params.join(' ')}".strip)
189 else
190 @good &&= run_or_fail("bundle exec rspec #{params.join(' ')}".strip)
191 end
192 end
193
194 unless ENV["SKIP_PLUGINS"]
195 if ENV["SINGLE_PLUGIN"]
196 @good &&= run_or_fail("bundle exec rake plugin:spec['#{ENV["SINGLE_PLUGIN"]}']")
197 else
198 fail_fast = "RSPEC_FAILFAST=1" unless ENV["SKIP_FAILFAST"]
199 @good &&= run_or_fail("#{fail_fast} bundle exec rake plugin:spec")
200 end
201 end
202 end
203
204 unless ENV["RUBY_ONLY"]
205 js_timeout = ENV["JS_TIMEOUT"].presence || 900_000 # 15 minutes
206
207 unless ENV["SKIP_CORE"]
208 @good &&= run_or_fail("bundle exec rake qunit:test['#{js_timeout}']")
209 @good &&= run_or_fail("bundle exec rake qunit:test['#{js_timeout}','/wizard/qunit']")
210 end
211
212 unless ENV["SKIP_PLUGINS"]
213 if ENV["SINGLE_PLUGIN"]
214 @good &&= run_or_fail("bundle exec rake plugin:qunit['#{ENV['SINGLE_PLUGIN']}','#{js_timeout}']")
215 else
216 @good &&= run_or_fail("bundle exec rake plugin:qunit['*','#{js_timeout}']")
217 end
218 end
219
220 if ENV["EMBER_CLI"]
221 Dir.chdir("#{Rails.root}/app/assets/javascripts/discourse") do # rubocop:disable Discourse/NoChdir
222 browsers = ENV["EMBER_CLI_BROWSERS"] || 'Chrome'
223 @good &&= run_or_fail("yarn install")
224 @good &&= run_or_fail("yarn ember test --launch #{browsers}")
225 end
226 end
227 end
228 end
229 ensure
230 puts "Terminating"
231
232 if ENV['PAUSE_ON_TERMINATE']
233 puts "Pausing prior to termination"
234 sleep
235 end
236
237 Process.kill("TERM", @redis_pid) if @redis_pid
238 Process.kill("TERM", @pg_pid) if @pg_pid
239 Process.wait @redis_pid if @redis_pid
240 Process.wait @pg_pid if @pg_pid
241 end
242
243 exit 1 unless @good
244 end