Coder Social home page Coder Social logo

lelia / test-summary-buildkite-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bugcrowd/test-summary-buildkite-plugin

0.0 0.0 0.0 1.96 MB

Buildkite plugin to summarise all test failures as an annotation

License: MIT License

Ruby 91.62% Shell 2.91% HTML 4.83% Dockerfile 0.63%

test-summary-buildkite-plugin's Introduction

Test Summary Buildkite Plugin

A Buildkite plugin that adds a single annotation for all your test failures using buildkite-agent annotate.

Supported formats:

  • JUnit
  • Checkstyle
  • TAP^
  • Plain text files with one failure per line

^ Current TAP support is fairly limited. If you have an example TAP file that is not being interpreted correctly, feel free to open an issue or pull request.

Example

Upload test results as artifacts using any supported format. If you include the $BUILDKITE_JOB_ID in the path, a link to the build will be included in the annotation. Some examples:

steps:
  - label: rspec
    command: rspec
    parallelism: 10
    # With spec_helper.rb:
    # RSpec.configure do |config|
    #   config.add_formatter('RspecJunitFormatter', "artifacts/rspec-#{ENV['BUILDKITE_JOB_ID']}.xml")
    # end
    artifact_paths: "artifacts/*"

  - label: eslint
    command: yarn run eslint -f checkstyle -o artifacts/eslint.xml
    artifact_paths: "artifacts/*"

  - label: ava
    command: bash -c "yarn --silent test --tap > artifacts/ava.tap"
    artifact_paths: "artifacts/*"

  - label: rubocop
    # The emacs format is plain text with one failure per line
    command: rubocop -f emacs -o artifacts/rubocop.txt
    artifact_paths: "artifacts/*"

Wait for all the tests to finish:

  - wait: ~
    continue_on_failure: true

Add a build step using the test-summary plugin:

  - label: annotate
    plugins:
      - bugcrowd/test-summary#v1.10.0:
          inputs:
            - label: rspec
              artifact_path: artifacts/rspec*
              type: junit
            - label: eslint
              artifact_path: artifacts/eslint.xml
              type: checkstyle
            - label: ava
              artifact_path: artifacts/ava.tap
              type: tap
            - label: rubocop
              artifact_path: artifacts/rubocop.txt
              type: oneline
          formatter:
            type: details
          context: test-summary

See buildkite annotation of all the failures. There are some example annotations included below.

Configuration

Inputs

The plugin takes a list of input sources. Each input source has:

  • label: the name used in the heading to identify the test group.
  • artifact_path: a glob used to download one or more artifacts.
  • type: one of junit, checkstyle, tap or oneline.
  • encoding: The file encoding to use. Defaults to UTF-8.
  • strip_colors: Remove ANSI color escape sequences. Defaults to false.
  • crop: (oneline type only) Number of lines to crop from the start and end of the file, to get around default headers and footers. Eg:
crop:
  start: 3
  end: 2
  • job_id_regex: Ruby regular expression to extract the job_id from the artifact path. It must contain a named capture with the name job_id. Defaults to (?<job_id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}).

Junit specific options:

  • summary: Customise how the summary is generated. Includes:
    • format: A ruby format string for converting the junit xml attributes into a summary. All attributes are available in <element>.<attr-name> format.
    • details_regex: A ruby regular expression, run over the body text of each failure. Any named captures generated by this regex will be available to the format string. This is useful if some information is only available in the contents of the failure. Eg:
summary:
  format: '%{testsuites.name}: %{testsuite.name}: %{testcase.classname}: %{failure.message}%{error.message}'
summary:
  format: '%{location}: %{testcase.name}'
  details_regex: '(?<location>\S+:\d+)'
  • message: Set this to false if the failure message attribute is not worth showing in the annotation. Defaults to true.
  • details: Set this to false if the body of the failure is not worth showing in the annotation. Defaults to true.

Formatter

There are two formatter types, summary and details.

The summary formatter includes a single line for each failure.

example summary annotation

The details formatter includes extra information about the failure in an accordion (if available). This is the default option.

example details annotation

Other formatter options are:

  • show_first: The number of failures to show before hiding the rest inside an accordion. If set to zero, all failures will be hidden by default. If set to a negative number, all failures will be shown. Defaults to 20.

Other options

  • context: The Buildkite annotation context. Defaults to test-summary.
  • style: Set the annotation style. Defaults to error.
  • fail_on_error: Whether the command should return non-zero exit status on failure. Defaults to false so failing to annotate a build does not cause the entire pipeline to fail.

Truncation

Buildkite has a maximum annotation size of 100 kilobytes. If there are too many failures to fit within this limit, the plugin will truncate the failures for each input.

Developing

To run the tests:

docker-compose run --rm test rspec

If you have ruby set up, you can just run:

bundle install
rspec

To generate sample markdown and HTML based on the files in spec/sample_artifacts:

bin/run-dev

Note: The sample HTML files use hardcoded references to buildkite assets. If the page is not displaying correctly, try updating the css files in templates/test_layout.html.haml based on what buildkite is currently serving.

test-summary-buildkite-plugin's People

Contributors

dreyks avatar maschwenk avatar philwo avatar tessereth avatar ticky avatar timnew avatar toolmantim avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.