From 62379dccf93aba6ed75ed9f6cf079ce2adaf8877 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Thu, 7 Sep 2017 14:37:40 -0400 Subject: [PATCH] Add prepare-docs-for-afs role We'll use this role for unified openstack docs publishing. Change-Id: I879d42cd04ab051b91c0b636856470cd4126b6f2 Signed-off-by: Paul Belanger --- roles/prepare-docs-for-afs/README.rst | 1 + roles/prepare-docs-for-afs/defaults/main.yaml | 1 + roles/prepare-docs-for-afs/tasks/branch.yaml | 14 ++++ roles/prepare-docs-for-afs/tasks/main.yaml | 68 +++++++++++++++++++ roles/prepare-docs-for-afs/tasks/stable.yaml | 15 ++++ roles/prepare-docs-for-afs/tasks/tagged.yaml | 18 +++++ 6 files changed, 117 insertions(+) create mode 100644 roles/prepare-docs-for-afs/README.rst create mode 100644 roles/prepare-docs-for-afs/defaults/main.yaml create mode 100644 roles/prepare-docs-for-afs/tasks/branch.yaml create mode 100644 roles/prepare-docs-for-afs/tasks/main.yaml create mode 100644 roles/prepare-docs-for-afs/tasks/stable.yaml create mode 100644 roles/prepare-docs-for-afs/tasks/tagged.yaml diff --git a/roles/prepare-docs-for-afs/README.rst b/roles/prepare-docs-for-afs/README.rst new file mode 100644 index 00000000..0c593fe0 --- /dev/null +++ b/roles/prepare-docs-for-afs/README.rst @@ -0,0 +1 @@ +Prepare built openstack docs to be published to the OpenStack AFS cell. diff --git a/roles/prepare-docs-for-afs/defaults/main.yaml b/roles/prepare-docs-for-afs/defaults/main.yaml new file mode 100644 index 00000000..189d518f --- /dev/null +++ b/roles/prepare-docs-for-afs/defaults/main.yaml @@ -0,0 +1 @@ +zuul_work_dir: "src/{{ zuul.project.canonical_name }}" diff --git a/roles/prepare-docs-for-afs/tasks/branch.yaml b/roles/prepare-docs-for-afs/tasks/branch.yaml new file mode 100644 index 00000000..b6b8598d --- /dev/null +++ b/roles/prepare-docs-for-afs/tasks/branch.yaml @@ -0,0 +1,14 @@ +# Put other branch changes in dir named after branch under the +# build dir. When Zuul copies these files they will be +# accessible under the developer docs root using the branch name. +# EG: feature/foo or milestone-proposed +- name: Move built html to the side + command: "mv {{ doc_build_dir }}/html {{ doc_build_dir }}/tmp" + +- name: Ensure destination path exists + file: + path: "{{ doc_build_dir }}/html/{{ zuul.branch | dirname }}" + state: directory + +- name: Move html to branch location + command: "mv {{ doc_build_dir }}/tmp {{ doc_build_dir }}/html/{{ zuul.branch }}" diff --git a/roles/prepare-docs-for-afs/tasks/main.yaml b/roles/prepare-docs-for-afs/tasks/main.yaml new file mode 100644 index 00000000..8db26e66 --- /dev/null +++ b/roles/prepare-docs-for-afs/tasks/main.yaml @@ -0,0 +1,68 @@ +- name: Write marker text + copy: + dest: "{{ zuul_work_dir }}/doc/build/html/.root-marker" + content: "Project: {{ zuul.project.name }} Branch: {{ zuul.branch }} Build: {{ zuul.build }} Revision: {{ zuul.ref }}" + +- name: Process tagged build + include: tagged.yaml + when: "zuul.branch != 'master' and zuul.tag is defined" + +- name: Process stable branch build + include: stable.yaml + when: "'stable' in zuul.branch and zuul.tag is not defined" + +- name: Process branch build + include: branch.yaml + when: "zuul.branch != 'master' and 'stable' not in zuul.branch and zuul.tag is not defined" + +- name: Rearrange publish directories + args: + executable: /bin/bash + shell: | + set -xe + if [[ {{ zuul.ref }} =~ ^refs/tags/ ]]; then + # This job should not be configured to run for + # pre-releases, so if we have a tag we want to use it as + # the publishing location. + tag=$(echo {{ zuul.ref }} | cut -d/ -f3-) + branch_name="" + else + # If the ref wasn't a tag, assume it is a branch. + branch_name={{ zuul.branch }} + tag="" + fi + # Rearrange the build output to reflect the end publishing + # location, so we can use doc/publish as the source for the + # publisher step. + mkdir -p doc/publish + if [[ ! -z "$tag" ]]; then + # We will have already moved the content inside + # a directory named for the tag, so we move that + # directory to the publish location. + mv doc/build/html/$tag doc/publish/ + mv doc/build/.root-marker doc/publish/$tag/ + elif [[ $branch_name = master ]]; then + # The above tasks does not rename the output directory, but + # we want it to be called "latest". + mv doc/build/html doc/publish/latest + mv doc/build/.root-marker doc/publish/latest/ + elif [[ $branch_name =~ stable/ ]]; then + # We will have already moved the content inside + # a directory named for the branch, so move that to the + # publish location. + mv doc/build/html/$(basename $branch_name) doc/publish/ + mv doc/build/.root-marker doc/publish/$(basename $branch_name) + elif [[ $branch_name =~ feature/ ]]; then + echo "Docs should not be published for feature branches" + exit 1 + elif [[ $branch_name =~ driverfixes/ ]]; then + echo "Docs should not be published for feature branches" + exit 1 + else + # What is this even? + echo "Could not determine publishing location for branch_name $branch_name" + exit 1 + fi + # Move back into doc/build/html for artifact publisher. + rm -rf doc/build/html + mv doc/publish doc/build/html diff --git a/roles/prepare-docs-for-afs/tasks/stable.yaml b/roles/prepare-docs-for-afs/tasks/stable.yaml new file mode 100644 index 00000000..0d09d9e3 --- /dev/null +++ b/roles/prepare-docs-for-afs/tasks/stable.yaml @@ -0,0 +1,15 @@ +# Put stable release changes in dir named after stable release under the +# build dir. When Zuul copies these files they will be accessible under +# the developer docs root using the stable release name. +- name: Move built html to the side + command: "mv {{ doc_build_dir }}/html {{ doc_build_dir }}/tmp" + +- name: Ensure destination path exists + file: + path: "{{ doc_build_dir }}/html" + state: directory + +- name: Move html to branch location without stable prefix + command: >- + mv {{ doc_build_dir }}/tmp + {{ doc_build_dir }}/html/{{ zuul.branch | replace('stable/', '') }} diff --git a/roles/prepare-docs-for-afs/tasks/tagged.yaml b/roles/prepare-docs-for-afs/tasks/tagged.yaml new file mode 100644 index 00000000..ee6da208 --- /dev/null +++ b/roles/prepare-docs-for-afs/tasks/tagged.yaml @@ -0,0 +1,18 @@ +# Put tagged releases in proper location. All tagged builds get copied to +# BUILD_DIR/tagname. If this is the latest tagged release the copy of files +# at BUILD_DIR remains. When Zuul copies this file the root developer +# docs are always the latest release with older tags available under the +# root in the tagname dir. +- name: Copy content to the temporary location + copy: + remote_src: true + src: "{{ doc_build_dir }}/html" + dest: "{{ doc_build_dir }}/tmp" + +- name: Make destination path + file: + path: "{{ doc_build_dir }}/html/{{ zuul.tag | dirname }}" + state: directory + +- name: Move html to branch location + command: "mv {{ doc_build_dir }}/tmp {{ doc_build_dir }}/html/{{ zuul.tag }}"