From 7c6047e1b8414a00cdf1623c6c9626a51d17c2c1 Mon Sep 17 00:00:00 2001
From: Andreas Jaeger <aj@suse.com>
Date: Thu, 16 Nov 2017 10:55:14 +0100
Subject: [PATCH] Build releasenotes without tox

Build releasenotes without tox and use a venv directly. This avoids
problems with special tox install commands in certain projects.

For now, install current project as well to avoid breaking projects that
set version or release for releasenotes document.

This follows the CTI:
https://governance.openstack.org/tc/reference/project-testing-interface.html#release-notes

Change-Id: I56909152975f731a9d2c21b2825b972195e48ee8
---
 playbooks/releasenotes/post.yaml         |  1 -
 roles/build-releasenotes/tasks/main.yaml | 56 +++++++++++++++++++++---
 zuul.d/jobs.yaml                         |  8 ++--
 zuul.d/project-templates.yaml            |  4 ++
 4 files changed, 59 insertions(+), 10 deletions(-)

diff --git a/playbooks/releasenotes/post.yaml b/playbooks/releasenotes/post.yaml
index 8783c5d2..0885c085 100644
--- a/playbooks/releasenotes/post.yaml
+++ b/playbooks/releasenotes/post.yaml
@@ -1,5 +1,4 @@
 - hosts: all
   roles:
-    - role: fetch-tox-output
     - role: fetch-sphinx-output
       sphinx_output_src: "{{ zuul.project.src_dir }}/releasenotes/build/html"
diff --git a/roles/build-releasenotes/tasks/main.yaml b/roles/build-releasenotes/tasks/main.yaml
index e020a393..de7ff714 100644
--- a/roles/build-releasenotes/tasks/main.yaml
+++ b/roles/build-releasenotes/tasks/main.yaml
@@ -4,6 +4,43 @@
     path: "{{ zuul_work_dir }}/releasenotes/source/locale"
   register: translations
 
+- name: Check to see if the constraints file exists
+  stat:
+    path: "{{ constraints_file|default('missing') }}"
+    get_checksum: false
+    get_mime: false
+    get_md5: false
+  register: stat_results
+  when: constraints_file is defined
+
+- name: Record file location
+  set_fact:
+    upper_constraints: "-c {{ constraints_file }}"
+  when: not stat_results|skipped and stat_results.stat.exists
+
+- name: Setup venv
+  shell:
+    chdir: '{{ zuul_work_dir }}'
+    executable: /bin/bash
+    cmd: |
+      set -e
+      set -x
+
+      UPPER_CONSTRAINTS="{{ upper_constraints }}"
+      python -m virtualenv .venv
+      VENV=.venv/bin
+      $VENV/pip install sphinx $UPPER_CONSTRAINTS
+      $VENV/pip install openstackdocstheme $UPPER_CONSTRAINTS
+      $VENV/pip install reno $UPPER_CONSTRAINTS
+      # Optionally, install local requirements
+      if [ -e releasenotes/requirements.txt ] ; then
+          $VENV/pip install -r releasenotes/requirements.txt $UPPER_CONSTRAINTS
+      fi
+      # TODO(jaegerandi): Remove once all repos are fixed.
+      # Try installing current repo in case it needs to be available for
+      # example for version number calculation. Ignore any failures here.
+      $VENV/pip install . || true
+
 - name: Prepare release note translations
   shell:
     chdir: '{{ zuul_work_dir }}'
@@ -14,6 +51,7 @@
 
       DOCNAME=releasenotes
       DIRECTORY=releasenotes
+      VENV=.venv/bin
 
       # Mapping of language codes to language names
       declare -A LANG_NAME=(
@@ -43,7 +81,7 @@
       trap "rm -f -- '$REFERENCES'" EXIT
 
       # Extract translations
-      tox -e venv -- sphinx-build -b gettext \
+      $VENV/sphinx-build -b gettext \
           -d ${DIRECTORY}/build/doctrees.gettext \
           ${DIRECTORY}/source/ \
           ${DIRECTORY}/source/locale/
@@ -85,7 +123,7 @@
           done
 
           # Build translated document
-          tox -e venv -- sphinx-build -b html -D language=${language} \
+          $VENV/sphinx-build -b html -D language=${language} \
               -d "${DIRECTORY}/build/doctrees.${language}" \
               ${DIRECTORY}/source/ ${DIRECTORY}/build/html/${language}
 
@@ -114,6 +152,14 @@
       rm -f ${DIRECTORY}/source/locale/*.pot
   when: translations.stat.exists == True
 
-- name: Build release notes
-  include_role:
-    name: tox
+- name: Run releasenotes sphinx build
+  shell:
+    chdir: '{{ zuul_work_dir }}'
+    executable: /bin/bash
+    cmd: |
+      set -e
+      set -x
+
+      VENV=.venv/bin
+      $VENV/sphinx-build -a -E -W -d releasenotes/build/doctrees -b html \
+          releasenotes/source releasenotes/build/html
diff --git a/zuul.d/jobs.yaml b/zuul.d/jobs.yaml
index ebe63459..cd12432c 100644
--- a/zuul.d/jobs.yaml
+++ b/zuul.d/jobs.yaml
@@ -457,7 +457,6 @@
 
 - job:
     name: build-openstack-releasenotes
-    parent: openstack-tox
     description: |
       Build releasenotes, with optional translation support, using reno.
     success-url: html/
@@ -466,12 +465,13 @@
     # Release notes always build on master.
     override-branch: master
     timeout: 1800
+    required-projects:
+      - name: openstack/requirements
+    vars:
+      constraints_file: '{{ ansible_user_dir }}/src/git.openstack.org/openstack/requirements/upper-constraints.txt'
     files:
       - ^releasenotes/.*
       - ^tox.ini
-      - ^.*requirements.txt$
-    vars:
-      tox_envlist: releasenotes
 
 - job:
     name: build-openstack-api-ref
diff --git a/zuul.d/project-templates.yaml b/zuul.d/project-templates.yaml
index 9e7cdedb..93a13ee8 100644
--- a/zuul.d/project-templates.yaml
+++ b/zuul.d/project-templates.yaml
@@ -291,6 +291,8 @@
 - project-template:
     name: release-notes-jobs-horizon
     description: |
+      DEPRECATED, use release-notes-jobs!
+
       The standard release-notes-jobs but with horizon added as a
       required-projects. The dashboard projects currently need this
       due to how the tox_install.sh zuul-cloner's dashboard for them.
@@ -318,6 +320,8 @@
 - project-template:
     name: release-notes-jobs-neutron
     description: |
+      DEPRECATED, use release-notes-jobs!
+
       The standard release-notes-jobs but with neutron added as a
       required-projects. The neutron stadium projects currently need this
       due to how the tox_install.sh zuul-cloner's neutron for them.