Skip to content

Commit

Permalink
Merge pull request #37721 from jhawthorn/fix_ci3
Browse files Browse the repository at this point in the history
Fix yarn issues on CI
  • Loading branch information
jhawthorn authored and kamipo committed Nov 16, 2019
1 parent da8c964 commit 25b35fd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
7 changes: 2 additions & 5 deletions railties/test/application/assets_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ def teardown
def precompile!(env = nil)
with_env env.to_h do
quietly do
precompile_task = "bin/rails assets:precompile --trace 2>&1"
output = Dir.chdir(app_path) { %x[ #{precompile_task} ] }
assert $?.success?, output
output
rails ["assets:precompile", "--trace"]
end
end
end
Expand All @@ -37,7 +34,7 @@ def with_env(env)

def clean_assets!
quietly do
assert Dir.chdir(app_path) { system("bin/rails assets:clobber") }
rails ["assets:clobber"]
end
end

Expand Down
30 changes: 25 additions & 5 deletions railties/test/isolation/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -502,28 +502,48 @@ class ActiveSupport::TestCase
Module.new do
extend TestHelpers::Paths

def self.sh(cmd)
output = `#{cmd}`
raise "Command #{cmd.inspect} failed. Output:\n#{output}" unless $?.success?
end

# Build a rails app
FileUtils.rm_rf(app_template_path)
FileUtils.mkdir_p(app_template_path)

`#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc --skip-webpack-install`
sh "#{Gem.ruby} #{RAILS_FRAMEWORK_ROOT}/railties/exe/rails new #{app_template_path} --skip-bundle --skip-listen --no-rc --skip-webpack-install --quiet"
File.open("#{app_template_path}/config/boot.rb", "w") do |f|
f.puts "require 'rails/all'"
end

unless File.exist?("#{RAILS_FRAMEWORK_ROOT}/actionview/lib/assets/compiled/rails-ujs.js")
Dir.chdir("#{RAILS_FRAMEWORK_ROOT}/actionview") { `yarn build` }
Dir.chdir("#{RAILS_FRAMEWORK_ROOT}/actionview") do
sh "yarn build"
end
end

assets_path = "#{RAILS_FRAMEWORK_ROOT}/railties/test/isolation/assets"
unless Dir.exist?("#{assets_path}/node_modules")
Dir.chdir(assets_path) { `yarn install` }
Dir.chdir(assets_path) do
sh "yarn install"
end
end
FileUtils.cp("#{assets_path}/package.json", "#{app_template_path}/package.json")

# Fix relative file paths
package_json = File.read("#{assets_path}/package.json")
package_json.gsub!(%r{"file:(\.\./[^"]+)"}) do
path = Pathname.new($1).expand_path(assets_path).relative_path_from(Pathname.new(app_template_path))
"\"file:#{path}\""
end
File.write("#{app_template_path}/package.json", package_json)

FileUtils.cp("#{assets_path}/config/webpacker.yml", "#{app_template_path}/config/webpacker.yml")
FileUtils.cp_r("#{assets_path}/config/webpack", "#{app_template_path}/config/webpack")
FileUtils.ln_s("#{assets_path}/node_modules", "#{app_template_path}/node_modules")
FileUtils.chdir(app_template_path) { `bin/rails webpacker:binstubs` }
FileUtils.chdir(app_template_path) do
sh "yarn install"
sh "bin/rails webpacker:binstubs"
end

# Fake 'Bundler.require' -- we run using the repo's Gemfile, not an
# app-specific one: we don't want to require every gem that lists.
Expand Down

0 comments on commit 25b35fd

Please sign in to comment.