Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for JUNIT artifacts for results visualization. #538

Closed
DarwinJS opened this issue Jul 2, 2021 · 3 comments
Closed

Support for JUNIT artifacts for results visualization. #538

DarwinJS opened this issue Jul 2, 2021 · 3 comments
Labels
enhancement New feature or request O: stale 🤖 This issue or pull request is stale, it will be closed if there is no activity

Comments

@DarwinJS
Copy link

DarwinJS commented Jul 2, 2021

Is your feature request related to a problem? Please describe.
Many CI systems support UI based test visualization and long term statics when results can be collected in JUNIT format. For example: https://gitlab.com/guided-explorations/ci-cd-plugin-extensions/checkov-iac-sast/-/pipelines/230359640/test_report

Describe the solution you'd like
JUNIT format for test result artifacts.

Describe alternatives you've considered
The text reporter functionality is the the clearest alternative but JUNIT has many other benefits (https://nvuillam.github.io/mega-linter/reporters/TextReporter/#get-artifacts-on-gitlab-ci)

Additional context
This example is not linting results - but it would display ver similarly: https://gitlab.com/guided-explorations/ci-cd-plugin-extensions/checkov-iac-sast/-/pipelines/230359640/test_report

@alexandrebrg
Copy link

👋 As it was an issue for us too, we found an alternative way to do that. Mega-Linter has an export format to TAP, which can easily be converted to JUnit reports. To do that, you need to add in your variables OUTPUT_FORMAT=tap and OUTPUT_DETAIL=detailed, this will activate tap-exporter and gives reports in ./report/tap/. Add the following bash script to your job, and you'll get your reports in JUnit. These reports will be available in ./report_converted/`.

# Version 5.0.0 tap-junit has breaking changes that are currently getting fixed 
npm install -g tap-junit@4.2.0
mkdir report_converted/
cd ./report/tap
for report in *; do
# workaround for https://github.com/dhershman1/tap-junit/issues/30#issuecomment-744462006
  'sed -i "s/message: \*\+/message: /g" $report'
# Some message got comments with # which are ignored by tap-junit, so we escape it
  'sed -i -E "s/(^|[ ]+)(#)[a-zA-Z]*/\1\/\//g" $report'
# Converting TAP files into xml files with JUnit5 format
  cat $report | tap-junit -p -s "mega-linter" > ../../report_converted/${report}.xml
# Remove escaping on newlines for readability
  sed -i 's/\\n/\n/g' ../../report_converted/${report}.xml
# Replace ANSI colors as they are illegal characters
  sed -i 's/\x1b\[[0-9;]*m//g' ../../report_converted/${report}.xml
done

This little piece of code is taken from an R2devops GitLab job.

@nvuillam
Copy link
Member

nvuillam commented Jul 23, 2021

@alexandrebrg that's great, I could use that in a JUNIT reporter :)
I have to check how TAP format works when the linter is not "file by file", not sure it's perfectly working for now

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity.
It will be closed in 14 days if no further activity occurs.
Thank you for your contributions.

If you think this issue should stay open, please remove the O: stale 🤖 label or comment on the issue.

@github-actions github-actions bot added the O: stale 🤖 This issue or pull request is stale, it will be closed if there is no activity label Aug 23, 2021
@github-actions github-actions bot closed this as completed Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request O: stale 🤖 This issue or pull request is stale, it will be closed if there is no activity
Projects
None yet
Development

No branches or pull requests

3 participants