DEV: Extensively use exception: true in system() (#25911)

Specifically fixes a bug in smoke-test where it would just move on after failing to install latest js dependencies with yarn.
This commit is contained in:
Jarek Radosz 2024-02-27 11:33:28 +01:00 committed by GitHub
parent b337ae5ae9
commit 3736d66f17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 27 additions and 17 deletions

View File

@ -2,7 +2,7 @@
desc "ensure the asynchronously-created post_search_data index is present"
task "annotate" => :environment do |task, args|
raise if !system "bin/annotate --models"
system("bin/annotate --models", exception: true)
STDERR.puts "Annotate executed successfully"
non_core_plugins =
@ -27,9 +27,12 @@ task "annotate:clean" => :environment do |task, args|
db = TemporaryDb.new
db.start
db.with_env do
raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/rake db:migrate"
raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/rake annotate:ensure_all_indexes"
raise if !system "RAILS_ENV=test LOAD_PLUGINS=0 bin/annotate --models --model-dir app/models"
system("RAILS_ENV=test LOAD_PLUGINS=0 bin/rake db:migrate", exception: true)
system("RAILS_ENV=test LOAD_PLUGINS=0 bin/rake annotate:ensure_all_indexes", exception: true)
system(
"RAILS_ENV=test LOAD_PLUGINS=0 bin/annotate --models --model-dir app/models",
exception: true,
)
end
STDERR.puts "Annotate executed successfully"
ensure

View File

@ -27,7 +27,10 @@ end
task "db:environment:set" => [:load_config] do |_, args|
if MultisiteTestHelpers.load_multisite?
system("RAILS_ENV=test RAILS_DB=discourse_test_multisite rake db:environment:set")
system(
"RAILS_ENV=test RAILS_DB=discourse_test_multisite rake db:environment:set",
exception: true,
)
end
end
@ -56,7 +59,7 @@ end
task "db:drop" => [:load_config] do |_, args|
if MultisiteTestHelpers.create_multisite?
system("RAILS_DB=discourse_test_multisite RAILS_ENV=test rake db:drop")
system("RAILS_DB=discourse_test_multisite RAILS_ENV=test rake db:drop", exception: true)
end
end
@ -266,7 +269,7 @@ task "db:migrate" => %w[
end
if !Discourse.is_parallel_test? && MultisiteTestHelpers.load_multisite?
system("RAILS_DB=discourse_test_multisite rake db:migrate")
system("RAILS_DB=discourse_test_multisite rake db:migrate", exception: true)
end
end

View File

@ -46,7 +46,7 @@ def write_template(path, task_name, template)
File.write(output_path, "#{header}\n\n#{template}")
puts "#{basename} created"
`yarn run prettier --write #{output_path}`
system("yarn run prettier --write #{output_path}", exception: true)
puts "#{basename} prettified"
end
@ -59,7 +59,7 @@ def write_hbs_template(path, task_name, template)
basename = File.basename(path)
output_path = "#{Rails.root}/app/assets/javascripts/#{path}"
File.write(output_path, "#{header}\n#{template}")
`yarn run prettier --write #{output_path}`
system("yarn run prettier --write #{output_path}", exception: true)
puts "#{basename} created"
end
@ -203,8 +203,7 @@ end
task "javascript:update" => "clean_up" do
require "uglifier"
yarn = system("yarn install")
abort('Unable to run "yarn install"') unless yarn
system("yarn install", exception: true)
versions = {}
start = Time.now

View File

@ -17,7 +17,7 @@ task "qunit:test", %i[timeout qunit_path filter] do |_, args|
report_requests = ENV["REPORT_REQUESTS"] == "1"
system("yarn install")
system("yarn install", exception: true)
# ensure we have this port available
def port_available?(port)
@ -108,7 +108,13 @@ task "qunit:test", %i[timeout qunit_path filter] do |_, args|
if qunit_path
# Bypass `ember test` - it only works properly for the `/tests` path.
# We have to trigger a `build` manually so that JS is available for rails to serve.
system("yarn", "ember", "build", chdir: "#{Rails.root}/app/assets/javascripts/discourse")
system(
"yarn",
"ember",
"build",
chdir: "#{Rails.root}/app/assets/javascripts/discourse",
exception: true,
)
env["THEME_TEST_PAGES"] = if ENV["THEME_IDS"]
ENV["THEME_IDS"]

View File

@ -10,7 +10,7 @@ task "smoke:test" do
abort err.message
end
system("yarn install")
system("yarn install", exception: true)
url = ENV["URL"]
if !url

View File

@ -9,8 +9,7 @@ def library_src
end
task "svgicons:update" do
yarn = system("yarn install")
abort('Unable to run "yarn install"') unless yarn
system("yarn install", exception: true)
dependencies = [{ source: "@fortawesome/fontawesome-free/sprites", destination: "fontawesome" }]

View File

@ -1,7 +1,7 @@
# frozen_string_literal: true
RSpec.describe "Migrations::Import" do
subject(:cli) { system "migrations/import" }
subject(:cli) { system("migrations/import", exception: true) }
it "works" do
expect { cli }.to output(