Use three separate jobs for code coverage diffing

Reusable roles and playbooks are quite important upstream (I have
zuul-jobs inclusion in mind). Besides that, in Zuul's Ansible a playbook
is supposed to come from the same repo as the one where the job
definition is placed, and one can only override a job's `run` playbook.
This makes it rather annoying to modify, say, `tox-coverage` definition.

My previous approach with a job which performed two things (build the
old source *and* then generate coverage report) also would not scale
that well if the build+test phase is long.

Switch to three jobs:

- build the current, proposed state, and gather coverage info,
- build the past state, gather coverage info,
- download two artifacts from previous runs, reproduce the source trees,
and generate the final coverage diff report.

See-also: https://review.gerrithub.io/c/Telecominfraproject/oopt-zuul-jobs/+/489964
Change-Id: I6eb61669c6f28440a55ba08569a4f2683513a9fa
diff --git a/roles/pycobertura-diff/tasks/main.yaml b/roles/pycobertura-diff/tasks/main.yaml
index 418b273..471c22e 100644
--- a/roles/pycobertura-diff/tasks/main.yaml
+++ b/roles/pycobertura-diff/tasks/main.yaml
@@ -1,45 +1,18 @@
 - name: Generate pycobertura report
   shell: |
     set -ex
-    PATH=${PATH}:~/.local/bin
-    pycobertura show --format html --output "{{ ansible_user_dir }}/zuul-output/logs/coverage.html" \
-      --source "{{ new_source_prefix }}/{{ zuul.project.short_name }}" "{{ new_source_prefix }}/coverage.xml"
+
+    pycobertura show --format html --output "{{ ansible_user_dir }}/zuul-output/logs/coverage-previous.html" \
+      --source "{{ previous_source_prefix }}/{{ zuul.project.canonical_hostname }}/{{ zuul.project.name}}" \
+      "{{ ansible_user_dir }}/coverage-previous.xml"
+
+    pycobertura show --format html --output "{{ ansible_user_dir }}/zuul-output/logs/coverage-current.html" \
+      --source "{{ zuul.project.src_dir }}" \
+      "{{ ansible_user_dir }}/coverage-current.xml"
+
     pycobertura diff --format html --output "{{ ansible_user_dir }}/zuul-output/logs/coverage-diff.html" \
-      --source1 "{{ zuul.project.src_dir }}" "{{ coverage_xml_dir }}/coverage.xml" \
-      --source2 "{{ new_source_prefix }}/{{ zuul.project.short_name }}" "{{ new_source_prefix }}/coverage.xml"
-    sed -e 's;^  </body>$;    <p>Show <a href="coverage.html">final coverage</a> only</p>\n  </body>;' \
-      -i "{{ ansible_user_dir }}/zuul-output/logs/coverage-diff.html"
+      --source1 "{{ previous_source_prefix }}/{{ zuul.project.canonical_hostname }}/{{ zuul.project.name}}" "{{ ansible_user_dir }}/coverage-previous.xml" \
+      --source2 "{{ zuul.project.src_dir }}" "{{ ansible_user_dir }}/coverage-current.xml"
 
-- name: Check for coverage-diff.html
-  stat:
-    path: "{{ ansible_user_dir }}/zuul-output/logs/coverage-diff.html"
-    get_checksum: false
-    get_mime: false
-    get_md5: false
-  register: coverage_diff_html_stat
-
-- name: Check for coverage.html
-  stat:
-    path: "{{ ansible_user_dir }}/zuul-output/logs/coverage.html"
-    get_checksum: false
-    get_mime: false
-    get_md5: false
-  register: coverage_html_stat
-
-- name: Register coverage reports as artifacts
-  when: coverage_html_stat.stat.exists
-  zuul_return:
-    data:
-      zuul:
-        artifacts:
-          - name: "Full coverage report"
-            url: "coverage.html"
-
-- name: Register coverage reports as artifacts
-  when: coverage_diff_html_stat.stat.exists
-  zuul_return:
-    data:
-      zuul:
-        artifacts:
-          - name: "Change of code coverage report"
-            url: "coverage-diff.html"
+    sed -e 's;^  </body>$;    <p>Show <a href="coverage-current.html">previous</a> or <a href="coverage-current.html">final coverage</a> only</p>\n  </body>;' \
+      -i "{{ ansible_user_dir }}/zuul-output/logs/coverage-diff.html" || true