zuul-jobs/roles/tox/tasks/main.yaml
Albin Vass 86041d9914 Don't require tox_envlist
Since tox_envlist has a default value it cannot be undefined
so the fail task will never run. Instead handle the case when
tox_envlist is an empty string by getting the default configured
envlist from tox. Also handle the casewhen tox_envlist is 'ALL'.

This also updates tox_install_sibling_packages to correctly
handle multiple testenvs and uses configuration supplied by
'tox --showconfig -e <envlist>' instead of guessing where the
envdir and logdir are located.

We also cannot run tox inside python because it gets complicated
to know which tox_executable we should call during the python test
cases so run these commands in ansible and pass the output to
tox_install_sibling_packages.

Since role params have higher precedence than set_fact we set an
internal _tox_envlist fact that is a comma separated list of testenvs
that should be run.

Change-Id: I9e5a1b041f653cbcff7b8ed62e4a95a0a040fdd7
2020-05-19 14:32:26 +02:00

110 lines
3.1 KiB
YAML

- name: Check to see if the constraints file exists
stat:
path: "{{ tox_constraints_file }}"
get_checksum: false
get_mime: false
get_md5: false
register: stat_results
when: tox_constraints_file is defined
- name: Fail if constraints file is missing
when: tox_constraints_file is defined and not stat_results.stat.exists
fail:
msg: tox_constraints_file is defined but was not found
- name: Record file location
set_fact:
tox_constraints_env:
TOX_CONSTRAINTS_FILE: "{{ tox_constraints_file }}"
# Backward compatibility, to be removed
UPPER_CONSTRAINTS_FILE: "{{ tox_constraints_file }}"
when: tox_constraints_file is defined
# Tox siblings cannot take 'ALL' and tox_parse_output expects
# an envlist to be supplied so always set _tox_envlist equal to
# the list of testenvs we're going to run
- name: Set _tox_envlist from supplied tox_envlist
set_fact:
_tox_envlist: "{{ tox_envlist }}"
when:
- tox_envlist is defined and tox_envlist
- tox_envlist != "ALL"
- name: Get tox default envlist
command: "{{ tox_executable }} -l"
args:
chdir: "{{ zuul_work_dir }}"
register: _tox_default_envlist
when: tox_envlist is not defined or not tox_envlist
- name: Set tox envlist fact
set_fact:
_tox_envlist: "{{ _tox_default_envlist.stdout_lines | join(',') }}"
when:
- _tox_default_envlist is defined
- _tox_default_envlist.stdout_lines is defined
- name: Get all tox testenvs
command: "{{ tox_executable }} -a"
args:
chdir: "{{ zuul_work_dir }}"
register: _tox_all_testenvs
when: tox_envlist is defined and tox_envlist == 'ALL'
- name: Set tox envlist fact
set_fact:
_tox_envlist: "{{ _tox_all_testenvs.stdout_lines | join(',') }}"
when:
- _tox_all_testenvs is defined
- _tox_all_testenvs.stdout_lines is defined
- name: Fail if tox_envlist is empty
fail:
msg: "No envlist configured in zuul or tox.ini"
when: _tox_envlist is not defined
- name: Install tox siblings
include: siblings.yaml
when: tox_install_siblings
- name: Emit tox command
debug:
msg: >-
{{ tox_executable }}
-e{{ _tox_envlist }}
{{ tox_extra_args }}
- block:
- name: Run tox
args:
chdir: "{{ zuul_work_dir }}"
environment: "{{ tox_environment|combine(tox_constraints_env|default({})) }}"
command: >-
{{ tox_executable }}
-e{{ _tox_envlist }}
{{ tox_extra_args }}
register: tox_output
# Even though any test environment in tox failed we want to
# return file comments produced so always run this.
always:
- name: Look for output
tox_parse_output:
tox_output: '{{ tox_output.stdout }}'
tox_envlist: '{{ _tox_envlist }}'
workdir: '{{ zuul_work_dir }}'
when: tox_inline_comments
register: file_comments
failed_when: false
- name: Return file comments to Zuul
when:
- tox_inline_comments
- file_comments.file_comments
delegate_to: localhost
zuul_return:
data:
zuul:
file_comments: '{{ file_comments.file_comments }}'
failed_when: false