-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Output HTML artifact containing all failures:
Buildkite annotations, which this plugin creates, are limited to 100KB, and this plugin has a sophisticated algorithm for truncating the annotation to only the number of failures that would generate a Markdown-formatted annotation of less than that size. With stacktraces, that number can be as low as 15 failures: a small fraction of what a change to a large monorepo can cause. This change causes the plugin to also upload an artifact containing the HTML-ified non-truncated Markdown output, and link to that artifact from the annotation if the annotation has been truncated. This requires a refactor: Truncater now knows nothing about Formatter or Markdown; it only handles the truncation algorithm on the strings returned by a block. Much of the logic to wire Truncater and Formatters together has been moved to a new Processor class (this name was too similar to "Runner", so I renamed that to "Main"). This makes each class a bit more cohesive: Truncater only handles string truncation, Processor hands off the result of Formatter to Truncater, and Main writes the result of Processor to annotations and artifacts. Also: - I repurposed the `test_layout` template to also wrap the artifact, making the appearance similar to the annotation within Buildkite's UI. - There's now a mixin for classes that want to reraise-or-log, depending on the result of a `fail_on_error` method, and any error can now be accompanied by a "diagnostics" JSON object. - We now have a runtime dependency on a Markdown-to-HTML converter, so I switched to Kramdown, which is pure Ruby. The current minimal Dockerfile doesn't have the tools to compile C extensions.
- Loading branch information
Showing
18 changed files
with
246 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
module TestSummaryBuildkitePlugin | ||
module ErrorHandler | ||
def handle_error(err, diagnostics = nil) | ||
if fail_on_error | ||
raise err | ||
else | ||
Utils.log_error(err, diagnostics) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# frozen_string_literal: true | ||
|
||
module TestSummaryBuildkitePlugin | ||
class Processor | ||
include ErrorHandler | ||
|
||
attr_reader :formatter_options, :max_size, :output_path, :inputs, :fail_on_error | ||
|
||
def initialize(formatter_options:, max_size:, output_path:, inputs:, fail_on_error:) | ||
@formatter_options = formatter_options | ||
@max_size = max_size | ||
@output_path = output_path | ||
@inputs = inputs | ||
@fail_on_error = fail_on_error | ||
@_formatters = {} | ||
end | ||
|
||
def truncated_markdown | ||
@truncated_markdown ||= begin | ||
truncater = Truncater.new( | ||
max_size: max_size, | ||
max_truncate: inputs.map(&:failures).map(&:count).max | ||
) do |truncate| | ||
inputs_markdown(truncate) | ||
end | ||
|
||
truncater.markdown | ||
rescue StandardError => e | ||
handle_error(e, diagnostics) | ||
HamlRender.render('truncater_exception', {}) | ||
end | ||
end | ||
|
||
def inputs_markdown(truncate = nil) | ||
inputs.map { |input| input_markdown(input, truncate) }.compact.join("\n\n") | ||
end | ||
|
||
private | ||
|
||
def input_markdown(input, truncate) | ||
formatter(input).markdown(truncate) | ||
rescue StandardError => e | ||
handle_error(e) | ||
end | ||
|
||
def formatter(input) | ||
@_formatters[input] ||= Formatter.create(input: input, output_path: output_path, options: formatter_options) | ||
end | ||
|
||
def diagnostics | ||
{ | ||
formatter: formatter_options, | ||
inputs: inputs.map do |input| | ||
{ | ||
type: input.class, | ||
failure_count: input.failures.count, | ||
markdown_bytesize: input_markdown(input, nil)&.bytesize | ||
} | ||
end | ||
} | ||
end | ||
end | ||
end |
Oops, something went wrong.