zegl / kube-score

Kubernetes object analysis with recommendations for improved reliability and security. kube-score actively prevents downtime and bugs in your Kubernetes YAML and Charts. Static code analysis for Kubernetes.
https://kube-score.com
MIT License
2.64k stars 174 forks source link

Feature request: Support JUnit XML output format #459

Open atombrella opened 2 years ago

atombrella commented 2 years ago

I've experimented a bit with this tool on some YAML files at work. The output format is currently limited to human (which is neat for just finding and fixing potential issues) and ci (just one line per test). It'd be nice to support also junit. This format allows to see the results more clearly for each of the tests. JUnit is supported also by GitLab, and on other platforms (GitHub), and despite the misleading name, it appears to be a more universal format.

https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=trx%2Cyaml https://docs.gitlab.com/ee/ci/unit_test_reports.html https://support.atlassian.com/bitbucket-cloud/docs/test-reporting-in-pipelines/

zegl commented 2 years ago

Good idea! Do you want to work on it, or should I mark this issue as up-for-grabs?

atombrella commented 2 years ago

I can give it a go, but will probably reach out for assistance once I have something ready for a PR.

kmarteaux commented 2 years ago

There is a tool already available one could leverage -- https://github.com/jstemmer/go-junit-report. I did the following in my local env --

$ go get github.com/jstemmer/go-junit-report $ go install github.com/jstemmer/go-junit-report $ go test -v $(pwd)/cmd/kube-score | go-junit-report > report.html $ cat report.html

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
        <testsuite tests="2" failures="0" time="0.000" name="github.com/zegl/kube-score/cmd/kube-score">        
                <properties>
                        <property name="go.version" value="go1.18.1"></property>
                </properties>
                <testcase classname="kube-score" name="TestParseCli" time="0.000"></testcase>
                <testcase classname="kube-score" name="TestExecName" time="0.000"></testcase>
        </testsuite>
</testsuites>
kaluzaaa commented 1 year ago

@zegl can you assign this issues to me? I will try to upload a pr within the next week.

baracoder commented 1 year ago

@kaluzaaa any progress on the PR. I think this is a useful feature to integrate with gitlab CI

wscourge commented 1 year ago

@zegl please lmk if this is up for grabs, or if not what's the timeline

zegl commented 1 year ago

@wscourge I don't think that anyone is working on this at the moment. Feel free to work on it, and send a PR. :-)

qunabu commented 4 months ago

example in gitlab ci


kube-score-junit:
  stage: test
  when: always
  needs:
    - kube-score
  image:
    name: node
  before_script: 
    - npm install -g sarif-junit@latest
  script: 
    - sarif-junit -i result.json -o result.xml
  artifacts:
    reports:
      junit: "result.xml"

kube-score:
  stage: test
#  allow_failure: true
  image: 
    name: zegl/kube-score
    entrypoint: [""]  
  script:    
    - $(/kube-score score *.yaml -v -o sarif > result.json) || true
    - /kube-score score *.yaml    
  artifacts:
    when: always
    paths:
      - result.json

image

sebhoss commented 3 weeks ago

I've opened https://github.com/zegl/kube-score/pull/603 to add native JUnit output support - please take a look everyone :heart: