Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions ci/report_result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
vars_files:
- vars/common.yml
tasks:
- name: Check whether the log dir exists
ansible.builtin.stat:
path: "{{ logs_dir }}"
register: stat_out

- name: Create log dir
when: not stat_out.stat.exists
ansible.builtin.file:
path: "{{ logs_dir }}"
state: directory
Expand All @@ -29,28 +35,30 @@
register: verbose_matches
ignore_errors: true

# The RC from grep is 2 if an error occurred.
- name: Fail if the file was not found (or other grep error)
ansible.builtin.fail:
msg: "{{ verbose_matches.stderr if verbose_matches.stderr | length > 0 else 'There was an error with grep.' }}"
when: verbose_matches.rc > 1

- name: "Fail if there are no XML files"
ansible.builtin.fail:
msg: "There were no XML files found in {{ logs_dir }}."
when: verbose_matches.stdout_lines | length == 0

- name: "Get the number of failed testcases"
- name: "Get the number of testcase errors and failures"
ansible.builtin.set_fact:
tasks_errored: "{{ verbose_matches.stdout | regex_replace('.*errors=\"([0-9]*)\".*>', '\\1') | split('\n') | map('int') | sum }}"
tasks_failed: "{{ verbose_matches.stdout | regex_replace('.*failures=\"([0-9]*)\".*>', '\\1') | split('\n') | map('int') | sum }}"

# The RC from grep is 0 if the string is matched
- name: Fail when there's a testcase failure
- name: Fail when there's a testcase error
ansible.builtin.fail:
msg: There were {{ tasks_failed }} failed testcases.
when: tasks_failed | int > 0 and verbose_matches.rc == 0
msg: There were {{ tasks_errored }} errors in the testcases.
when: tasks_errored | int > 0 and verbose_matches.rc == 0

- name: Determine success or failure based on the number of failed tasks
ansible.builtin.fail:
msg: "The log file(s) contain failed task."
when: tasks_failed | int > 0 and verbose_matches.rc == 0

# The RC from grep is 2 if an error occurred.
- name: Fail if the file was not found (or other grep error)
# The RC from grep is 0 if the string is matched
- name: Fail when there's a testcase failure
ansible.builtin.fail:
msg: "{{ verbose_matches.stderr if verbose_matches.stderr | length > 0 else 'There was an error with grep.' }}"
when: verbose_matches.rc > 1
msg: There were {{ tasks_errored }} errors and {{ tasks_failed }} failed testcases.
when: ( [ tasks_failed, tasks_errored ] | sum > 0 ) and verbose_matches.rc == 0