Copy referred images into the destination and add git patch (#7)

Copy referred images into the destination and add git patch

Include referred images in the result

Reviewed-by: OpenTelekomCloud Bot <None>
This commit is contained in:
Artem Goncharov 2022-05-06 17:57:43 +02:00 committed by GitHub
parent 0751a20eaa
commit 166e05613f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 177 additions and 75 deletions

View File

@ -7,6 +7,7 @@ import logging
import os import os
import pathlib import pathlib
import re import re
import shutil
class OTCDocConvertor: class OTCDocConvertor:
@ -124,6 +125,8 @@ class OTCDocConvertor:
cap.name = 'figcaption' cap.name = 'figcaption'
figure.append(cap) figure.append(cap)
if img: if img:
# Store all referred images for copying
self.doc_images.add(img['src'])
img['src'] = '/_static/images/' + img['src'] img['src'] = '/_static/images/' + img['src']
figure.append(img) figure.append(img)
i.replace_with(figure) i.replace_with(figure)
@ -233,12 +236,12 @@ class OTCDocConvertor:
'--dest', '--dest',
help='Directory to write resulting files') help='Directory to write resulting files')
self.args = parser.parse_args() self.args = parser.parse_args()
retval = os.getcwd()
meta_data = json.loads(open( meta_data = json.loads(open(
pathlib.Path(self.args.path, "CLASS.TXT.json") pathlib.Path(self.args.path, "CLASS.TXT.json")
).read()) ).read())
metadata_by_uri = dict() metadata_by_uri = dict()
metadata_by_code = dict() metadata_by_code = dict()
self.doc_images = set()
if self.args.dest: if self.args.dest:
dest = pathlib.Path(self.args.dest) dest = pathlib.Path(self.args.dest)
else: else:
@ -415,7 +418,16 @@ class OTCDocConvertor:
f" of result/{path}/index.rst") f" of result/{path}/index.rst")
p.unlink() p.unlink()
os.chdir(retval) # Copy used images
if len(self.doc_images) > 0:
logging.debug("Processing images")
img_dest = pathlib.Path(dest, '_static', 'images')
img_dest.mkdir(parents=True, exist_ok=True)
for img in self.doc_images:
shutil.copyfile(
pathlib.Path(self.args.path, img).resolve(strict=False),
pathlib.Path(img_dest, img).resolve(strict=False)
)
def main(): def main():

View File

@ -1,44 +1,18 @@
--- ---
- hosts: localhost
vars:
vault_addr: "{{ zuul_vault_addr }}"
vault_secret_dest: "{{ zuul.executor.work_root }}/.approle-secret"
vault_token_dest: "{{ zuul.executor.work_root }}/.approle-token"
roles:
# Get the Vault token from prepared secret-id
- role: create-vault-approle-token
vault_role_id: "{{ zuul_vault.vault_role_id }}"
vault_wrapping_token_id: "{{ lookup('file', vault_secret_dest) }}"
- hosts: all - hosts: all
vars:
vault_token_dest: "{{ zuul.executor.work_root }}/.approle-token"
vault_addr: "{{ zuul_vault_addr }}"
tasks: tasks:
- name: Read project docs configuration
include_vars: "{{ docs_update_data_file }}"
- name: Fetch organization tokens - name: Fetch generated artifacts
no_log: true include_role:
check_mode: false name: "fetch_doc_artifacts"
ansible.builtin.uri: vars:
url: "{{ vault.vault_addr }}/v1/{{ vault.vault_token_path }}" fetch_doc_artifacts_name: "{{ doc.label }}"
headers: fetch_doc_artifacts_rst_source: "{{ ansible_user_dir }}/{{ docs_rst_location }}/{{ doc.label }}/{{ docs_new_location }}"
"X-Vault-Token": "{{ lookup('file', vault_token_dest) }}" fetch_doc_artifacts_diff_patch: "{{ ansible_user_dir }}/{{ doc.label }}.patch"
method: "POST" fetch_doc_artifacts_git_patch: "{{ ansible_user_dir }}/{{ doc.label }}.git.patch"
body: loop: "{{ docs }}"
org_name: "opentelekomcloud-docs" loop_control:
body_format: "json" loop_var: "doc"
register: "org_token" label: "{{ doc.label }}"
- name: Revoke GitHub token lease
check_mode: false
no_log: true
uri:
url: "{{ vault.vault_addr }}/v1/sys/leases/revoke"
headers:
"X-Vault-Token": "{{ vault.vault_token }}"
method: "PUT"
body:
lease_id: "{{ org_token.json.lease_id }}"
body_format: "json"
status_code: 204

View File

@ -52,7 +52,6 @@
- "org_token is defined" - "org_token is defined"
- "org_token.json is defined" - "org_token.json is defined"
- hosts: all - hosts: all
vars: vars:
github_token_dest: "{{ zuul.executor.work_root }}/.github" github_token_dest: "{{ zuul.executor.work_root }}/.github"

View File

@ -1,10 +1,5 @@
--- ---
- hosts: all - hosts: all
vars:
docs_rst_location: "docs"
docs_base_location: "base"
docs_new_location: "new"
tasks: tasks:
- name: Read project docs configuration - name: Read project docs configuration
include_vars: "{{ docs_update_data_file }}" include_vars: "{{ docs_update_data_file }}"
@ -16,6 +11,12 @@
register: git_log register: git_log
ignore_errors: true ignore_errors: true
- name: Configure git user name
command: "git config --global user.name 'OpenTelekomCloud Proposal Bot'"
- name: Configure git user email
command: "git config --global user.email 52695153+otcbot@users.noreply.github.com"
- name: Generate new RSTs - name: Generate new RSTs
include_role: include_role:
name: "convert_doc" name: "convert_doc"
@ -54,22 +55,13 @@
doc_label: "{{ doc.label }}" doc_label: "{{ doc.label }}"
generate_doc_patch_base_location: "{{ docs_base_location }}" generate_doc_patch_base_location: "{{ docs_base_location }}"
generate_doc_patch_new_location: "{{ docs_new_location }}" generate_doc_patch_new_location: "{{ docs_new_location }}"
generate_doc_patch_repository: "{{ doc.repository }}"
generate_doc_patch_project_location: "{{ doc.project_location }}"
generate_doc_patch_base: "{{ ansible_user_dir }}/{{ docs_rst_location }}/{{ doc.label }}" generate_doc_patch_base: "{{ ansible_user_dir }}/{{ docs_rst_location }}/{{ doc.label }}"
generate_doc_patch_patch_location: "{{ ansible_user_dir }}/{{ doc.label }}.patch" generate_doc_patch_diff_patch_location: "{{ ansible_user_dir }}/{{ doc.label }}.patch"
generate_doc_patch_git_patch_location: "{{ ansible_user_dir }}/{{ doc.label }}.git.patch"
loop: "{{ docs }}" loop: "{{ docs }}"
loop_control: loop_control:
loop_var: "doc" loop_var: "doc"
label: "{{ doc.label }}" label: "{{ doc.label }}"
when: "git_log.stdout is search(doc.html_location) or git_log.stdout is search('otc_doc_convertor')" when: "git_log.stdout is search(doc.html_location) or git_log.stdout is search('otc_doc_convertor')"
- name: Fetch generated artifacts
include_role:
name: "fetch_doc_artifacts"
vars:
fetch_doc_artifacts_name: "{{ doc.label }}"
fetch_doc_artifacts_rst_source: "{{ ansible_user_dir }}/{{ docs_rst_location }}/{{ doc.label }}/{{ docs_new_location }}"
fetch_doc_artifacts_patch: "{{ ansible_user_dir }}/{{ doc.label }}.patch"
loop: "{{ docs }}"
loop_control:
loop_var: "doc"
label: "{{ doc.label }}"

View File

@ -9,11 +9,32 @@
when: "doc_dir.matched > 0" when: "doc_dir.matched > 0"
include_tasks: doc.yaml include_tasks: doc.yaml
- name: Find {{ fetch_doc_artifacts_name }} Patch - name: Find {{ fetch_doc_artifacts_name }} diff patch
stat: stat:
path: "{{ fetch_doc_artifacts_patch }}" path: "{{ fetch_doc_artifacts_diff_patch }}"
register: doc_patch register: doc_diff_patch
when: "fetch_doc_artifacts_diff_patch is defined"
- name: Process {{ fetch_doc_artifacts_name }} Patch file - name: Process {{ fetch_doc_artifacts_name }} diff patch file
when: "doc_patch.stat.exists" when:
- "fetch_doc_artifacts_diff_patch is defined"
- "doc_diff_patch.stat.exists"
include_tasks: patch.yaml include_tasks: patch.yaml
vars:
patch_file: "{{ fetch_doc_artifacts_diff_patch }}"
patch_type: "diff"
- name: Find {{ fetch_doc_artifacts_name }} git patch
stat:
path: "{{ fetch_doc_artifacts_git_patch }}"
register: doc_git_patch
when: "fetch_doc_artifacts_git_patch is defined"
- name: Process {{ fetch_doc_artifacts_name }} git patch file
when:
- "fetch_doc_artifacts_git_patch is defined"
- "doc_git_patch.stat.exists"
include_tasks: patch.yaml
vars:
patch_file: "{{ fetch_doc_artifacts_git_patch }}"
patch_type: "git"

View File

@ -1,9 +1,9 @@
- block: - block:
- name: Fetch archive - name: Fetch archive
synchronize: synchronize:
dest: "{{ zuul.executor.log_root }}/{{ fetch_doc_artifacts_name }}.patch" dest: "{{ zuul.executor.log_root }}/{{ fetch_doc_artifacts_name }}.{{ patch_type }}.patch"
mode: pull mode: pull
src: "{{ fetch_doc_artifacts_patch }}" src: "{{ patch_file }}"
verify_host: true verify_host: true
owner: no owner: no
group: no group: no
@ -12,8 +12,8 @@
- block: - block:
- name: Copy archive - name: Copy archive
copy: copy:
dest: "{{ zuul_output_dir }}/logs/{{ fetch_doc_artifacts_name }}.patch" dest: "{{ zuul_output_dir }}/logs/{{ fetch_doc_artifacts_name }}.{{ patch_type }}.patch"
src: "{{ fetch_doc_artifacts_patch }}" src: "{{ patch_file }}"
mode: 0644 mode: 0644
remote_src: true remote_src: true
when: zuul_use_fetch_output when: zuul_use_fetch_output
@ -23,9 +23,10 @@
data: data:
zuul: zuul:
artifacts: artifacts:
- name: "{{ fetch_doc_artifacts_name }} patch" - name: "{{ fetch_doc_artifacts_name }} {{ patch_type }} patch"
url: "patches/{{ fetch_doc_artifacts_name }}.patch" url: "{{ fetch_doc_artifacts_name }}.{{ patch_type }}.patch"
metadata: metadata:
type: docs_patch type: "patch"
doc_service: "{{ doc.service }}" doc_service: "{{ doc.service }}"
doc_type: "{{ doc.type }}" doc_type: "{{ doc.type }}"
patch_type: "{{ patch_type }}"

View File

@ -0,0 +1,2 @@
generate_doc_patch_repo_location: "{{ ansible_user_dir }}/{{ generate_doc_patch_repository }}/{{ generate_doc_patch_project_location }}"
generate_doc_patch_doc_location: "{{ generate_doc_patch_repo_location }}/{{ generate_doc_patch_project_location }}"

File diff suppressed because it is too large Load Diff

View File

@ -28,12 +28,13 @@
name: otc-doc-exports-convert-base name: otc-doc-exports-convert-base
parent: unittests parent: unittests
abstract: true abstract: true
nodeset: ubuntu-focal nodeset: ubuntu-jammy
description: | description: |
Convert doc exports from html to rst and generate corresponding rst diff Convert doc exports from html to rst and generate corresponding rst diff
files. files.
pre-run: playbooks/pre.yaml pre-run: playbooks/pre.yaml
run: playbooks/run.yaml run: playbooks/run.yaml
post-run: playbooks/post.yaml
- job: - job:
name: otc-doc-exports-convert-compute name: otc-doc-exports-convert-compute
@ -92,6 +93,10 @@
- project: - project:
merge-mode: squash-merge merge-mode: squash-merge
default-branch: main default-branch: main
vars:
docs_rst_location: "docs"
docs_base_location: "base"
docs_new_location: "new"
check: check:
jobs: jobs:
- otc-tox-pep8: - otc-tox-pep8: