File tree Expand file tree Collapse file tree 1 file changed +19
-1
lines changed
Expand file tree Collapse file tree 1 file changed +19
-1
lines changed Original file line number Diff line number Diff line change 55
66# Setup
77
8+ require "open3"
9+
810puts "::group::Installing Rubocop gems"
911
1012if ENV . fetch ( "RUBOCOP_GEM_VERSIONS" ) . downcase == "gemfile"
5557 command = "#{ rubocop_command } #{ changed_ruby_files . map ( &:path ) . join ( ' ' ) } --format json --force-exclusion #{ ARGV . join ( ' ' ) } "
5658
5759 puts "Running rubocop with: #{ command } "
58- JSON . parse ( `#{ command } ` ) . fetch ( "files" )
60+ stdout , stderr , status = Open3 . capture3 ( command )
61+
62+ if status . success?
63+ puts "Rubocop finished successfully"
64+ else
65+ puts "Rubocop failed with status #{ status . exitstatus } "
66+ puts "Rubocop output:\n #{ stdout } " unless stdout . empty?
67+ puts "Rubocop error output:\n #{ stderr } " unless stderr . empty?
68+ end
69+
70+ # In case --debug is passed to rubocop, the output is not valid JSON so we have to substring it
71+ json_start = stdout . index ( "{" )
72+ json_end = stdout . rindex ( "}" )
73+
74+ abort "ERROR: No JSON found in rubocop output" unless json_start && json_end
75+
76+ JSON . parse ( stdout [ json_start ..json_end ] ) . fetch ( "files" )
5977 else
6078 puts "No changed Ruby files, skipping rubocop"
6179
You can’t perform that action at this time.
0 commit comments