From 381d5880984dd7b3b03d5bf9d9bcb4f7011b4aca Mon Sep 17 00:00:00 2001 From: Pavlo Dudnytskyi Date: Mon, 24 Jun 2024 07:36:16 +0200 Subject: [PATCH] Added workflow to check documentation --- .github/workflows/documentation.yaml | 25 +++++++++++++++++++++++++ .gitignore | 17 +++++++++-------- README.rst | 1 - docs/script/make_doc.py | 23 ++++++++++++++--------- 4 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 .github/workflows/documentation.yaml diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml new file mode 100644 index 0000000..c77f20d --- /dev/null +++ b/.github/workflows/documentation.yaml @@ -0,0 +1,25 @@ +name: documentation check + +on: + push: + pull_request: + branches: [ "master", "dev" , "experimental" ] + +jobs: + tests: + name: documentation check + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4.1.3 + - name: Run script and save results + run: python docs/script/run_script.py README.tmp + - name: Compare temp file with readme.rst + run: diff -u README.rst README.tmp > doc_cmp.result + - name: Fail build if files are not identical + run: | + if [ $? -ne 0 ]; then + echo "Files are not identical" + cat doc_cmp.result + exit 1 + fi \ No newline at end of file diff --git a/.gitignore b/.gitignore index b2fb58b..b3b8c90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ -# Gitignore settings for ESPHome -/.esphome/ -__pycache__/ -/.vscode/ -/secrets.yaml -/buildlog.txt -*.bak -*.local.yaml \ No newline at end of file +# Gitignore settings for ESPHome +/.esphome/ +__pycache__/ +/.vscode/ +/secrets.yaml +/buildlog.txt +*.bak +*.local.yaml +*.tmp \ No newline at end of file diff --git a/README.rst b/README.rst index 7ac50cc..0df57e0 100644 --- a/README.rst +++ b/README.rst @@ -128,7 +128,6 @@ Automations ``on_alarm_start`` Trigger ************************** - This automation will be triggered when a new alarm is activated by AC. The error code of the alarm will be given in the variable "code" (type uint8_t), error message in the variable "message" (type char*). Those variables can be used in `lambdas `_ .. code-block:: yaml diff --git a/docs/script/make_doc.py b/docs/script/make_doc.py index db9eb4a..6c40fc0 100644 --- a/docs/script/make_doc.py +++ b/docs/script/make_doc.py @@ -1,14 +1,15 @@ import re import os +import sys doc_file_path = [ - 'esphome-docs/climate/haier.rst', - 'esphome-docs/sensor/haier.rst', - 'esphome-docs/binary_sensor/haier.rst', - 'esphome-docs/text_sensor/haier.rst', - 'esphome-docs/button/haier.rst', - 'esp32_backup.rst', - 'additional_information.rst', + "/".join(["esphome-docs", "climate", "haier.rst"]), + "/".join(["esphome-docs", "sensor", "haier.rst"]), + "/".join(["esphome-docs", "binary_sensor", "haier.rst"]), + "/".join(["esphome-docs", "text_sensor", "haier.rst"]), + "/".join(["esphome-docs", "button", "haier.rst"]), + "esp32_backup.rst", + "additional_information.rst", ] def process_esphome_refs(line, l_num): @@ -72,12 +73,16 @@ def process_section(section, output_file, pth): " source documentation in ./doc folder or script.\n\n" ] -output_file = open("../../README.rst", "w") +script_path = os.path.dirname(__file__) +output_file_name = "../../README.rst" +if len(sys.argv) > 1: + output_file_name = sys.argv[1] +output_file = open(output_file_name, "w") output_file.writelines(document_header) for in_f in doc_file_path: print(f"Processing: {in_f}") output_file.write(f".. Generated from {in_f}\n\n") - input_file = open(f"../{in_f}", "r") + input_file = open(os.path.join(script_path, "..", in_f), "r") p = os.path.dirname(in_f) lines = input_file.readlines() is_seo = False