ansible: refactor coverage comparing
First of all, fix a typo. Yay. So this means that I screwed up in mu
last commit, and that the Depends-on header *really* needs to use the
correct Gerrit hostname. Without that, the code was -- apparently --
still using the original, merged version of these jobs. Yay.
More importantly, move artifact download to the very first thing in the
pre-run playbook. IMHO this makes sense, if there's any failure here,
it means that this ansible code is broken, and therefore there's no
point in wasting cycles doing another build when we already know that we
won't be able to return anything useful.
Change-Id: I9ddbc552f1417a8fffb573ddb1f32df65c2112ea
diff --git a/playbooks/coverage-diff/pre.yaml b/playbooks/coverage-diff/pre.yaml
index b9cc154..190ac26 100644
--- a/playbooks/coverage-diff/pre.yaml
+++ b/playbooks/coverage-diff/pre.yaml
@@ -2,3 +2,4 @@
roles:
- ensure-pycobertura
- git-use-previous-commit
+ - download-next-coverage
diff --git a/roles/pycobertura-diff/tasks/download.yaml b/roles/download-next-coverage/tasks/download.yaml
similarity index 100%
rename from roles/pycobertura-diff/tasks/download.yaml
rename to roles/download-next-coverage/tasks/download.yaml
diff --git a/roles/download-next-coverage/tasks/main.yaml b/roles/download-next-coverage/tasks/main.yaml
new file mode 100644
index 0000000..ae7cbfd
--- /dev/null
+++ b/roles/download-next-coverage/tasks/main.yaml
@@ -0,0 +1,17 @@
+- name: Place for new version of sources
+ file:
+ path: "{{ new_source_prefix }}"
+ state: directory
+
+- name: Prepare copy of the new version of sources
+ command: git worktree add {{ new_source_prefix }}/{{ zuul.project.short_name }} {{ zuul.branch }}
+ args:
+ chdir: "{{ zuul.project.src_dir }}"
+
+- name: Retrieve coverage from parent jobs
+ include_tasks: download.yaml
+ loop: "{{ zuul.artifacts | json_query(artifact_seletcor) }}"
+ vars:
+ artifact_seletcor: "[([?metadata.type == 'cobertura_xml' && project == '{{ zuul.project.name }}'])[-1]]"
+ loop_control:
+ loop_var: artifact
diff --git a/roles/pycobertura-diff/tasks/main.yaml b/roles/pycobertura-diff/tasks/main.yaml
index 5c80870..0d5bbe9 100644
--- a/roles/pycobertura-diff/tasks/main.yaml
+++ b/roles/pycobertura-diff/tasks/main.yaml
@@ -1,21 +1,3 @@
-- name: Place for new version of sources
- file:
- path: "{{ new_source_prefix }}"
- state: directory
-
-- name: Prepare copy of the new version of sources
- command: git worktree add {{ new_source_prefix }}/{{ zuul.project.short_name }} {{ zuul.branch }}
- args:
- chdir: "{{ zuul.project.src_dir }}"
-
-- name: Retrieve coverage from parent jobs
- include_task: download.yaml
- loop: "{{ zuul.artifacts | json_query(artifact_seletctor) }}"
- vars:
- artifact_seletctor: "[([?metadata.type == 'cobertura_xml' && project == '{{ zuul.project.name }}'])[-1]]"
- loop_control:
- loop_var: artifact
-
- name: Generate pycobertura report
shell: |
set -ex