forked from laiweijian4/doc-exports
Add job for comparing doc content to the current
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: gtema <artem.goncharov@gmail.com> Co-committed-by: gtema <artem.goncharov@gmail.com>
This commit is contained in:
parent
22737368b1
commit
7821fdbd24
113
metadata.yaml
113
metadata.yaml
File diff suppressed because it is too large
Load Diff
78
otc_doc_convertor/comparator.py
Normal file
78
otc_doc_convertor/comparator.py
Normal file
@ -0,0 +1,78 @@
|
||||
import argparse
|
||||
import logging
|
||||
import requests
|
||||
import pathlib
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
|
||||
def body_filter(tag):
|
||||
return (
|
||||
tag.name == "div"
|
||||
and tag.has_attr("id")
|
||||
and tag["id"].startswith("body")
|
||||
)
|
||||
|
||||
|
||||
class OTCComparator:
|
||||
|
||||
def compare(self, url_prefix, file_path, file_name):
|
||||
try:
|
||||
data = requests.get(
|
||||
f"https://docs.otc.t-systems.com/{url_prefix}/"
|
||||
f"{file_name}.json")
|
||||
page_data = None
|
||||
for item in data.json():
|
||||
if (
|
||||
item.get("url").endswith(f"{file_name}.html")
|
||||
and item['content']
|
||||
):
|
||||
page_data = item["content"]
|
||||
break
|
||||
original = BeautifulSoup(page_data, 'html.parser')
|
||||
with open(f"{file_path}/{file_name}.html", "r") as f:
|
||||
new_content = f.read()
|
||||
new = BeautifulSoup(new_content, 'html.parser')
|
||||
t1 = original.find(body_filter)
|
||||
t2 = new.find(body_filter)
|
||||
if t1 != t2:
|
||||
logging.error("Content mismatch")
|
||||
return False
|
||||
logging.info("Content matches")
|
||||
return True
|
||||
except Exception as ex:
|
||||
logging.error("Content comparison error %s" % ex)
|
||||
return False
|
||||
|
||||
def main(self):
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
parser = argparse.ArgumentParser(description="Compare document data.")
|
||||
parser.add_argument(
|
||||
"path",
|
||||
type=str,
|
||||
help="Path to the document content (i.e. docs/ecs/api-ref")
|
||||
parser.add_argument(
|
||||
"url",
|
||||
type=str,
|
||||
help="url prefix in the helpcenter (i.e. api/ecs)")
|
||||
args = parser.parse_args()
|
||||
match = True
|
||||
|
||||
for f in pathlib.Path(args.path).glob("*.html"):
|
||||
logging.info(f"Comparing {f.name}")
|
||||
if not self.compare(
|
||||
args.url, args.path, f.name.replace(".html", "")):
|
||||
match = False
|
||||
|
||||
if not match:
|
||||
logging.error("Comparison showed deviations")
|
||||
exit(1)
|
||||
else:
|
||||
logging.info("No deviations found")
|
||||
|
||||
|
||||
def main():
|
||||
OTCComparator().main()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
30
playbooks/compare.yaml
Normal file
30
playbooks/compare.yaml
Normal file
@ -0,0 +1,30 @@
|
||||
---
|
||||
- hosts: all
|
||||
tasks:
|
||||
- name: Read project docs configuration
|
||||
ansible.builtin.include_vars: "{{ docs_update_data_file }}"
|
||||
|
||||
- name: Detect list of changes
|
||||
ansible.builtin.command: "git log -1 --name-only --pretty="
|
||||
args:
|
||||
chdir: "{{ zuul.project.src_dir }}"
|
||||
register: git_log
|
||||
ignore_errors: true
|
||||
changed_when: false
|
||||
|
||||
- name: Verify document matches the one in the current HC
|
||||
ansible.builtin.include_role:
|
||||
name: "compare"
|
||||
vars:
|
||||
compare_html_location: "{{ doc.1.html_location }}"
|
||||
compare_hc_location: "{{ doc.1.hc_location }}"
|
||||
doc_label: "{{ doc.0.service_type }}_{{ doc.1.type }}"
|
||||
loop: "{{ categories | json_query('*') | flatten | subelements('docs') }}"
|
||||
loop_control:
|
||||
loop_var: "doc"
|
||||
label: "{{ doc.0.service_type }}_{{ doc.1.type }}"
|
||||
when:
|
||||
- "doc.1.html_location is defined"
|
||||
- "doc.1.hc_location is defined"
|
||||
- |
|
||||
git_log.stdout is search(doc.1.html_location)
|
@ -1,3 +1,4 @@
|
||||
bs4
|
||||
lxml
|
||||
Jinja2
|
||||
requests
|
||||
|
5
roles/compare/tasks/main.yaml
Normal file
5
roles/compare/tasks/main.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
- name: Verify document {{ doc_label }} matches the one in the current HC
|
||||
args:
|
||||
executable: "/bin/bash"
|
||||
chdir: "{{ ansible_user_dir }}/{{ zuul.project.src_dir }}"
|
||||
ansible.builtin.shell: "source {{ ansible_user_dir }}/.venv/bin/activate; otc-convert-compare {{ compare_html_location }} {{ compare_hc_location }}"
|
@ -30,7 +30,6 @@
|
||||
ansible.builtin.set_fact:
|
||||
convert_params: "{{ convert_params }} --templates-location {{ zuul_work_dir }}/templates"
|
||||
|
||||
|
||||
- name: Convert {{ doc_label | default('') }} HTML to RST
|
||||
args:
|
||||
executable: "/bin/bash"
|
||||
|
@ -25,3 +25,4 @@ packages = otc_doc_convertor
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
otc-convert-doc = otc_doc_convertor.convertor:main
|
||||
otc-convert-compare = otc_doc_convertor.comparator:main
|
||||
|
Loading…
x
Reference in New Issue
Block a user