Surface failures from nested rake/shell tasks (#17310)

Previously when rake would shell out the output would be lost. This
made debugging CI logs difficult. This commit updates the stack with
improved message surfacing on error.
This commit is contained in:
Cas Donoghue 2025-03-13 15:20:38 -07:00 committed by GitHub
parent e748488e4a
commit 0d931a502a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 35 additions and 7 deletions

View file

@ -125,12 +125,34 @@ namespace "artifact" do
result
end
# execute Kernel#system call,checking the exist status of the executed command and eventually reporting as exception
##
# @override safe_system([env,] command... [,options])
# execute Kernel#system call,checking the exit status of the executed command and eventually reporting as exception
def safe_system(*args)
if !system(*args)
status = $?
command = args.dup # avoid mutating input for reporting
env = command.size > 1 && command.first.kind_of?(Hash) ? command.shift : {}
options = command.size > 1 && command.last.kind_of?(Hash) ? command.pop : {}
fail("unsupported options #{options}") unless options.empty?
# Normalize command to a single string from either a multi-word string
# or an array of individual words
command = command.size > 1 ? Shellwords.join(command.map(&:to_s)) : command.first.to_s
# prepend the environment
env.each do |k,v|
command.prepend("#{Shellwords.escape(k.to_s)}=#{Shellwords.escape(v.to_s)} ")
end
output = `#{command} 2>&1`
status = $?
if !status.success?
puts "Command failed: #{args.inspect}"
puts "Output: #{output}"
raise "Got exit status #{status.exitstatus} attempting to execute #{args.inspect}!"
end
true
end
desc "Generate rpm, deb, tar and zip artifacts"

View file

@ -159,10 +159,16 @@ void rake(File projectDir, File buildDir, String task, String... args) {
jruby.runScriptlet("require 'rake'; require 'time'")
def rakeArgs = args ? "'${args.join("','")}'" : ""
jruby.runScriptlet("""
rake = Rake.application
rake.init
rake.load_rakefile
rake['${task}'].invoke(${rakeArgs})
begin
rake = Rake.application
rake.init
rake.load_rakefile
rake['${task}'].invoke(${rakeArgs})
rescue => e
puts "Rake task error: #{e.class}: #{e.message}"
puts "Backtrace: #{e.backtrace.join("\\n")}"
raise e
end
"""
)
}