Skip to main content

`report2junit` is a tool that converts various reports into the JUnit format.

Project description

Report 2 JUnit

License Maintenance GitHub release Continuous Integration codecov

report2junit is a tool that converts various reports into the JUnit format.

Installation

You can install the report2junit tool by running the following command:

pip install report2junit

Usage

Syntax

The following syntax can be used to convert a report:

report2junit <SOURCE_LOCATION>

CLI Examples

Convert an output report from cloudformation-guard using the following command(s):

report2junit ./sample-reports/cfn-guard.json

# Or if you want to specify the destination:
report2junit ./sample-reports/cfn-guard.json --destination-file ./sample-reports/cfn-guard-other-destination.xml

Convert an output report from cfn-nag using the following command(s):

report2junit ./sample-reports/cfn-nag.json

# Or if you want to specify the destination:
report2junit ./sample-reports/cfn-nag.json --destination-file ./sample-reports/cfn-nag-other-destination.xml

Combine both the cloudformation-guard and cfn-nag reports into a single output report.

report2junit ./sample-reports/cfn-nag.json ./sample-reports/cfn-guard.json

# Or if you want to specify the destination:
report2junit ./sample-reports/cfn-nag.json ./sample-reports/cfn-guard.json --destination-file ./sample-reports/junit-other.xml

In some cases it is useful to explicitly stop when there are failures. For example when you want to enforce that there are no failures. Or on the other hand we could continue when there are failures. This behaviour can be influenced using the --ignore-failures and --fail-on-failures options. Where --fail-on-failures is the default.

# Convert the given report and when there are failures exit code 1 is returned.
report2junit ./sample-reports/cfn-guard.json --fail-on-failures
echo $?

# Convert the given report and when there are failures exit code 0 is returned.
report2junit ./sample-reports/cfn-guard.json --ignore-failures
echo $?

AWS CodeBuild Examples

One of the reasons for writing this tool to use it in combination with AWS CodeBuild. In this section you will find a few examples in how you could use it.

Native buildspec.yml

After you synthesized your template, or you use a CloudFormation native template. You can scan it using cloudformation-guard or cfn-nag to scan the template. The outcome of those tools are not compatible with the reporting tools from AWS CodeBuild. So we will use report2junit to convert the 2 results into a single, combined compatible report.

version: 0.2

phases:
  install:
    runtime-versions:
      python: 3.8
    commands:
      - pip install -Ur requirements.txt
      - mkdir -p reports
  build:
    commands:
      # Generate the template or use the already existing template.
      - cdk synth > template.yml
      # Use cfn_nag and cfn-guard to scan the generated template
      - cfn_nag_scan --fail-on-warnings --input-path template.yml -o json > reports/cfn-nag.json || true
      - cfn-guard validate --rules cfn-rules.guard --data template.yml --output-format json --show-summary none > reports/cfn-guard.json || true
  post_build:
    commands:
      - report2junit reports/cfn-guard.json reports/cfn-nag.json --destination-file ./reports/combined-junit-report.xml

artifacts:
  files: '**/*'

reports:
  Conpliance:
    base-directory: ./reports
    file-format: JUNITXML
    files:
      - combined-junit-report.xml

Using CDK CodePipeline

When you want to use the pipelines functionality from CDK you can use the following sample to implement report2junit into that pipeline.

from aws_cdk import (
    core as cdk,
    aws_codebuild as codebuild,
    aws_codecommit as codecommit,
    pipelines as pipelines,
)
from pipeline_stage import PipelineStage

default_synth_spec = {
    "version": "0.2",
    "reports": {
        "Conpliance": {
            "base-directory": "./reports",
            "file-format": "JUNITXML",
            "files": [
                "combined-junit-report.xml",
            ],
        },
    },
}


class PipelineStack(cdk.Stack):

    def __init__(self, scope: cdk.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)

        repository = codecommit.Repository(self, "MyRepo", repository_name="MyRepo")

        pipelines.CodePipeline(
            self,
            "Pipeline",
            self_mutation=True,
            synth_code_build_defaults=pipelines.CodeBuildOptions(
                partial_build_spec=codebuild.BuildSpec.from_object(default_synth_spec),
            ),
            synth=pipelines.ShellStep(
                "Build",
                input=pipelines.CodePipelineSource.code_commit(repository, "main"),
                install_commands=[
                    "pip install -r requirements.txt",
                    "npm install -g aws-cdk",
                    "curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/aws-cloudformation/cloudformation-guard/main/install-guard.sh | sh && ",
                    "mkdir -p /codebuild/user/bin/",
                    "ln -s ~/.guard/bin/cfn-guard /codebuild/user/bin/cfn-guard"
                ],
                commands=[
                    "mkdir reports",
                    "cdk synth > template.yml",
                    "cfn-guard validate --rules cfn-rules.guard --data template.yml --output-format json --show-summary none > reports/cfn-guard.json || true",
                    "report2junit reports/cfn-guard.json",
                ],
            ),
        )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

report2junit-0.2.2.tar.gz (11.0 kB view details)

Uploaded Source

File details

Details for the file report2junit-0.2.2.tar.gz.

File metadata

  • Download URL: report2junit-0.2.2.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for report2junit-0.2.2.tar.gz
Algorithm Hash digest
SHA256 91860b0a2d1a26b091f8232c41ba2617edaa44085ca9c94138cd7c4a7a274cdd
MD5 a114d3e0b8c0f1f32e93e3de84060611
BLAKE2b-256 fbc198aadbd176abddd450daa53d4701cb1844cce85d4dcb09a99ad37baeb617

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page