Use Tanuki in your GitLab CI/CD pipelines to:
- Transform a Unity Test Runner report to a GitLab JUnit report
- Transform a Unity Project Auditor report to a GitLab Code Quality report
- Generate a static HTML Code Quality report for GitLab Merge Requests
- Print code coverage of a Unity Cobertura coverage report to GitLab Code Coverage
The following is a typical GitLab CI/CD configuration using Tanuki:
Code Quality:
image: ghcr.io/zensharp/tanuki
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- |
# Obtain codequality.json here
tanuki html codequality.json -o index.html --title "$CI_PROJECT_TITLE"
artifacts:
paths:
- index.html
expose_as: "Code Quality Report"
reports:
codequality: codequality.json
Run Unit Tests:
image: ghcr.io/zensharp/tanuki
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- |
# Obtain results.xml and cobertura.xml here
tanuki transform results.xml -o junit.xml
tanuki coverage cobertura.xml --multiplier 100
coverage: '/Code coverage is: \d+\.\d+/'
artifacts:
reports:
junit: junit.xmlAfter every merge request pipeline, the merge request will display:
- Code coverage (i.e. Test coverage)
- Code Quality HTML report (i.e. Code Quality Report)
- Code Quality changes
- Test summary
Click "Code Quality Report" to view the HTML report.
# Unity Project Auditor JSON to Code Climate
tanuki transform report.json --codeclimate
# Unity Test Runner XML to JUnit
tanuki transform report.xml --junit
# or let Tanuki automatically determine the format
tanuki transform report.json
tanuki transform report.xml
# By default, Tanuki prints the result to STDOUT
# Use -o|--output to write to a file
tanuki transform report.json -o codeclimate.json
tanuki transform report.xml -o junit.xmltanuki edit report.json [-o edited.json] [--location-prefix "src/Assets"] [--linter "Project Auditor"]tanuki merge a.json b.json ... z.json [-o merged.json]tanuki html report.json [-o index.html] [--base-url "https://docs.example.com"] [--title "My Code Quality Report"]tanuki coverage cobertura.xml [--multiplier 100.0]
# Output
Code coverage is: 0.897Add a Tanukifile at .tanuki/Tanukifile. See this example
Then trigger the file with:
tanuki triggertanuki delete report.json --where ".path == ^Packages/"tanuki assert report.json --none ".severity == Blocker"Tanuki offers a simple syntax language for querying issues. For example:
Here are the available patterns (see also IssueFilterer.cs):
.body.category.check_name.description.fingerprint.linter.location.path.severity
Tanuki will search for a configuration file in the following order:
./.tanuki.yml./.tanuki/tanuki.yml./.config/tanuki.yml~/.config/tanuki.yml
Add custom linters to the configuration file. When using tanuki html, the linters will get properly linked in the generated HTML.
linters:
- name: Project Auditor
url: https://docs.unity3d.com/Packages/com.unity.project-auditor@1.0/manual/index.html
- name: Rubocop
url: https://docs.rubocop.org- Tanuki's report template is based this template from gitlab-org/ci-cd/codequality.