-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- the role converts reports into json, optionally merging multiple fragments into 1 report in loadable json format - add initial tests - add author to `galaxy.yml` - upd collection `README.md` - added previously merged filter line `junit2obj` - added the role `junit2json` Signed-off-by: Maxim Kovgan <makovgan@redhat.com>
- Loading branch information
Showing
14 changed files
with
563 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,217 @@ | ||
<!-- DOCSIBLE START --> | ||
|
||
# 📃 Role overview | ||
|
||
## junit2json | ||
|
||
|
||
|
||
Description: Converts XML junit reports passed or in passed directory into single or fragmented JSON report file(s) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<details> | ||
<summary><b>🧩 Argument Specifications in meta/argument_specs</b></summary> | ||
|
||
#### Key: main | ||
**Description**: The resulting JSON file(s) are of the same structure for all the teams' and CI systems and used later to be sent to the data collection system. | ||
This is the main entrypoint for the role `redhatci.ocp.junit2json`. | ||
Scans all the XML reports passed as `junit2json_input_reports`, scans folders for files matching `global_reports_path_patterns`. | ||
Converts XMLs into JSON, if variable `junit2json_do_merge` is `true` XMLs are merged into one. | ||
New filenames are based on the old ones. | ||
|
||
|
||
|
||
- **junit2json_input_reports** | ||
- **Required**: True | ||
- **Type**: list | ||
- **Default**: none | ||
- **Description**: Mixed List files or directories containing the XML report(s) to convert | ||
|
||
|
||
|
||
|
||
|
||
- **junit2json_output_dir** | ||
- **Required**: True | ||
- **Type**: str | ||
- **Default**: none | ||
- **Description**: Output directory for resulting report JSON file path(s) | ||
|
||
|
||
|
||
|
||
|
||
- **junit2json_do_merge** | ||
- **Required**: False | ||
- **Type**: bool | ||
- **Default**: True | ||
- **Description**: Should we merge data of converted reports into 1 file or not. | ||
When `false`, each report `XML` file is converted to a corresponding json file appended `.json` extension | ||
Otherwise, resulting merged report is named as the directory, with `.report.json` extension. | ||
in both cases, the result is stored under `junit2json_output_dir`. | ||
|
||
|
||
|
||
|
||
|
||
- **junit2json_input_merged_report** | ||
- **Required**: False | ||
- **Type**: str | ||
- **Default**: none | ||
- **Description**: Relative file name for the Merged XML report (relevant only when `junit2json_do_merge` is `true`), | ||
it is generated under `junit2json_output_dir` | ||
|
||
|
||
|
||
|
||
|
||
- **junit2json_output_merged_report** | ||
- **Required**: False | ||
- **Type**: str | ||
- **Default**: none | ||
- **Description**: Relative file name for the JSON report (relevant only when `junit2json_do_merge` is `true`), | ||
it is generated under `junit2json_output_dir` | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</details> | ||
|
||
|
||
### Defaults | ||
|
||
**These are static variables with lower priority** | ||
|
||
#### File: defaults/main.yml | ||
|
||
| Var | Type | Value |Required | Title | | ||
|--------------|--------------|-------------|-------------|-------------| | ||
| [junit2json_hash](defaults/main.yml#L5) | str | `sha256` | n/a | n/a | | ||
| [junit2json_debug](defaults/main.yml#L6) | bool | `False` | n/a | n/a | | ||
| [junit2json_do_merge](defaults/main.yml#L7) | bool | `True` | n/a | n/a | | ||
|
||
|
||
|
||
|
||
|
||
### Tasks | ||
|
||
|
||
#### File: tasks/convert.yml | ||
|
||
| Name | Module | Has Conditions | | ||
| ---- | ------ | --------- | | ||
| Read file content | ansible.builtin.set_fact | False | | ||
| Generate content hash from the content | ansible.builtin.set_fact | False | | ||
| Print curr XML report filename | ansible.builtin.debug | True | | ||
| Obtain info on previous content checksum file | ansible.builtin.stat | False | | ||
| Update junit2json_result_data [junit2json_do_merge: {{ junit2json_do_merge }}] | ansible.builtin.set_fact | True | | ||
| Convert junit XML to JSON and save in junit2json_result_data | ansible.builtin.set_fact | True | | ||
| Setup JSoN report file name (with extension .xml) | ansible.builtin.set_fact | True | | ||
| Setup JSoN report file name (with extension .xml) | ansible.builtin.set_fact | True | | ||
| Update junit2json_output_report_path [junit2json_do_merge: {{ junit2json_do_merge }}] | ansible.builtin.set_fact | True | | ||
| Update junit2json_output_report_path [junit2json_do_merge: {{ junit2json_do_merge }}] | ansible.builtin.set_fact | True | | ||
| Get xml_old_hash | ansible.builtin.set_fact | True | | ||
| Update global_json_reports_list | ansible.builtin.set_fact | False | | ||
| Ensure json data destination folder | ansible.builtin.file | True | | ||
| Write json data to destination | ansible.builtin.copy | True | | ||
| Write current hash to destination | ansible.builtin.copy | True | | ||
|
||
#### File: tasks/merge.yml | ||
|
||
| Name | Module | Has Conditions | | ||
| ---- | ------ | --------- | | ||
| Generate XML files list | ansible.builtin.set_fact | False | | ||
| Print XML reports' filenames data | ansible.builtin.debug | True | | ||
| Merge multiple JUnit XML files into single consolidated report | ansible.builtin.shell | False | | ||
| Write merge resulting file | ansible.builtin.copy | True | | ||
| Override the xml files list for conversion | ansible.builtin.set_fact | False | | ||
|
||
#### File: tasks/expand.yml | ||
|
||
| Name | Module | Has Conditions | | ||
| ---- | ------ | --------- | | ||
| Print path_item value | ansible.builtin.debug | False | | ||
| Setup helper variables | ansible.builtin.set_fact | False | | ||
| Check whether the path_item is a directory | ansible.builtin.stat | False | | ||
| Add path_item as JUnit XML report (it is a file) | ansible.builtin.set_fact | True | | ||
| Find JUnit XML reports under path_item (it is a directory) | ansible.builtin.find | True | | ||
| Setup the default list for conversion | ansible.builtin.set_fact | True | | ||
| Setup the default list for conversion | ansible.builtin.set_fact | True | | ||
|
||
#### File: tasks/main.yml | ||
|
||
| Name | Module | Has Conditions | | ||
| ---- | ------ | --------- | | ||
| Validate some variables | ansible.builtin.assert | False | | ||
| Initialize input reports variable | ansible.builtin.set_fact | False | | ||
| Initialize input reports variable | ansible.builtin.debug | False | | ||
| Expand the input list to list of existing files | ansible.builtin.include_tasks | False | | ||
| Merge JUnit XML reports into single file for junit2json_do_merge=true | ansible.builtin.include_tasks | True | | ||
| Convert XML to JSON | ansible.builtin.include_tasks | True | | ||
|
||
|
||
|
||
|
||
## Playbook | ||
|
||
```yml | ||
--- | ||
|
||
- name: "Test redhatci.ocp.junit2json role :: simple input" | ||
hosts: localhost | ||
tasks: | ||
- name: Test role redhatci.ocp.junit2json | ||
ansible.builtin.include_role: | ||
name: redhatci.ocp.junit2json | ||
vars: | ||
junit2json_input_reports: "{{ role_path }}/../../tests/unit/data/test_junit2obj_simple_input.xml" | ||
junit2json_output_dir: "{{ role_path }}/tests" | ||
junit2json_do_merge: false | ||
- name: Load actual result to variable actual | ||
ansible.builtin.set_fact: | ||
actual: "{{ lookup('file', playbook_dir + '/test_junit2obj_simple_input.json') | from_json }}" | ||
- name: Load expected result to variable expected | ||
ansible.builtin.set_fact: | ||
expected: "{{ lookup('file', playbook_dir + '/../../../tests/unit/data/test_junit2obj_simple_result.json') }}" | ||
- name: Ensure both are identical | ||
ansible.builtin.assert: | ||
that: | ||
- actual == expected | ||
|
||
# - name: test system-tests data conversion | ||
# hosts: localhost | ||
# roles: | ||
# - name: junit2json | ||
# vars: | ||
# j2j_reports_path: "{{ roles_path }}/junit2json/tests/data/system-tests/" | ||
# j2j_reports_path_patterns: | ||
# - "*.xml" | ||
# | ||
|
||
``` | ||
|
||
|
||
## Author Information | ||
Max Kovgan | ||
|
||
#### License | ||
|
||
Apache-2.0 | ||
|
||
#### Minimum Ansible Version | ||
|
||
2.9 | ||
|
||
#### Platforms | ||
|
||
No platforms specified. | ||
<!-- DOCSIBLE END --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
--- | ||
# defaults file for role redhatci.ocp.junit2json | ||
|
||
junit2json_hash: sha256 | ||
junit2json_debug: false | ||
junit2json_do_merge: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
# arguments spec file for redhatci.ocp.junit2json role | ||
argument_specs: | ||
main: | ||
short_description: Main entry point for role redhatci.ocp.junit2json | ||
description: | | ||
The resulting JSON file(s) are of the same structure for all the teams' and CI systems and used later to be sent to the data collection system. | ||
This is the main entrypoint for the role `redhatci.ocp.junit2json`. | ||
Scans all the XML reports passed as `junit2json_input_reports`, scans folders for files matching `global_reports_path_patterns`. | ||
Converts XMLs into JSON, if variable `junit2json_do_merge` is `true` XMLs are merged into one. | ||
New filenames are based on the old ones. | ||
author: | ||
- Max Kovgan | ||
options: | ||
junit2json_input_reports: | ||
type: list | ||
required: true | ||
elements: str | ||
description: | | ||
Mixed List files or directories containing the XML report(s) to convert | ||
junit2json_output_dir: | ||
type: str | ||
required: true | ||
description: | | ||
Output directory for resulting report JSON file path(s) | ||
junit2json_do_merge: | ||
type: bool | ||
required: false | ||
default: true | ||
description: | | ||
Should we merge data of converted reports into 1 file or not. | ||
When `false`, each report `XML` file is converted to a corresponding json file appended `.json` extension | ||
Otherwise, resulting merged report is named as the directory, with `.report.json` extension. | ||
in both cases, the result is stored under `junit2json_output_dir`. | ||
junit2json_input_merged_report: | ||
type: str | ||
required: false | ||
description: | | ||
Relative file name for the Merged XML report (relevant only when `junit2json_do_merge` is `true`), | ||
it is generated under `junit2json_output_dir` | ||
junit2json_output_merged_report: | ||
type: str | ||
required: false | ||
description: | | ||
Relative file name for the JSON report (relevant only when `junit2json_do_merge` is `true`), | ||
it is generated under `junit2json_output_dir` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
--- | ||
galaxy_info: | ||
author: Max Kovgan | ||
description: Converts XML junit reports passed or in passed directory into single or fragmented JSON report file(s) | ||
company: Red Hat, Inc. | ||
# issue_tracker_url: http://example.com/issue/tracker | ||
license: Apache-2.0 | ||
min_ansible_version: "2.9" | ||
galaxy_tags: [] | ||
dependencies: [] |
Oops, something went wrong.