From f817197c0f75f00032e682cf3eb00eb7d7c7b8d3 Mon Sep 17 00:00:00 2001 From: Suren Gabrielyan Date: Wed, 26 Apr 2023 20:35:28 +0400 Subject: [PATCH] docs(common): deploy docs if component version got changed --- .github/workflows/publish-docs-component.yml | 75 +++++++++++------ docs/asio/generate_docs | 54 ++++++++++-- docs/esp_modem/generate_docs | 28 ++++--- docs/esp_mqtt_cxx/generate_docs | 36 ++++++-- docs/esp_websocket_client/generate_docs | 36 ++++++-- docs/mdns/generate_docs | 87 ++++++++++++++++++-- 6 files changed, 254 insertions(+), 62 deletions(-) diff --git a/.github/workflows/publish-docs-component.yml b/.github/workflows/publish-docs-component.yml index 357efc73515..34807033bd2 100644 --- a/.github/workflows/publish-docs-component.yml +++ b/.github/workflows/publish-docs-component.yml @@ -43,27 +43,54 @@ jobs: tag_name: ${{ env.BUMP_TAG }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - # - name: Generate docs - # shell: bash - # run: | - # sudo apt-get update - # sudo apt-get -y install doxygen clang python3-pip - # python -m pip install breathe recommonmark esp-docs==1.4.1 - # cd $GITHUB_WORKSPACE/docs - # ./generate_docs - # - name: Deploying generated docs - # if: always() - # shell: bash - # run: | - # source $GITHUB_WORKSPACE/docs/utils.sh - # add_doc_server_ssh_keys $DOCS_DEPLOY_KEY $DOCS_DEPLOY_SERVER $DOCS_DEPLOY_SERVER_USER - # export GIT_VER=$(git describe --always) - # export GITHUB_REF_NAME=latest - # export DOCS_BUILD_DIR=$GITHUB_WORKSPACE/docs - # deploy-docs - # - name: Upload components to component service - # uses: espressif/github-actions/upload_components@master - # with: - # directories: "components/esp_modem;components/esp_websocket_client;components/mdns;components/asio;components/esp_mqtt_cxx" - # namespace: "espressif" - # api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} + - name: Check if the document exists + id: document_check + if: env.BUMP_VERSION != '' + shell: bash + run: | + if [[ ${{ env.BUMP_COMPONENT } == "mdns" ]]; then + URL=$DOCS_DEPLOY_URL_BASE/${{ env.BUMP_COMPONENT }}/docs/${{ env.BUMP_VERSION }}/en/index.html + else + URL=$DOCS_DEPLOY_URL_BASE/${{ env.BUMP_COMPONENT }}/docs/${{ env.BUMP_VERSION }}/index.html + fi + # Send a GET request to the web page and store the response status code in a variable + HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${URL}") + # Check if the response status code is 200 + if [ "${HTTP_STATUS}" -ne 200 ]; then + echo "::set-output name=exist::no" + fi + - name: Generate docs + if: ${{ steps.document_check.outputs.exist == 'no' }} + shell: bash + run: | + sudo apt-get update + sudo apt-get -y install doxygen clang python3-pip + python -m pip install breathe recommonmark esp-docs==1.4.1 + cd $GITHUB_WORKSPACE/docs/${{ env.BUMP_COMPONENT }} + ./generate_docs + # Modify index.html to have new release + if [[ ${{ env.BUMP_COMPONENT } == "mdns" ]]; then + $GITHUB_WORKSPACE/ci/modify_docs_releases.sh $URL ${{ env.BUMP_VERSION }} docs/en/html/index.html + $GITHUB_WORKSPACE/ci/modify_docs_releases.sh $URL ${{ env.BUMP_VERSION }} docs/zh_CN/html/index.html + else + $GITHUB_WORKSPACE/ci/modify_docs_releases.sh $URL ${{ env.BUMP_VERSION }} docs/generic/html/index.html + fi + - name: Deploying generated docs + if: ${{ steps.document_check.outputs.exist == 'no' }} + shell: bash + run: | + source $GITHUB_WORKSPACE/docs/utils.sh + add_doc_server_ssh_keys $DOCS_DEPLOY_KEY $DOCS_DEPLOY_SERVER $DOCS_DEPLOY_SERVER_USER + export GIT_VER=$(git describe --always) + export GITHUB_REF_NAME=latest + export DOCS_BUILD_DIR=$GITHUB_WORKSPACE/docs/${{ env.BUMP_COMPONENT }} + export DOCS_DEPLOY_PATH=$DOCS_DEPLOY_PATH/${{ env.BUMP_COMPONENT }} + deploy-docs + export GITHUB_REF_NAME=${{ env.BUMP_VERSION }} + deploy-docs + - name: Upload components to component service + uses: espressif/github-actions/upload_components@master + with: + directories: "components/esp_modem;components/esp_websocket_client;components/mdns;components/asio;components/esp_mqtt_cxx" + namespace: "espressif" + api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }} diff --git a/docs/asio/generate_docs b/docs/asio/generate_docs index def507c5ede..aebab4d18bd 100755 --- a/docs/asio/generate_docs +++ b/docs/asio/generate_docs @@ -1,21 +1,61 @@ +#!/bin/bash + +rm -rf docs + +if [ "$#" -eq 1 ]; then + NEW_RELEASE=$1 +fi + build-docs --target esp32 --language en -cp -rf _build/en/esp32/html . +mkdir -p docs/generic +mv _build/en/esp32/html docs/generic + rm -rf _build __pycache__ +if [ -n NEW_RELEASE ]; then + URL="https://docs.espressif.com/projects/esp-protocols/asio/docs/latest/index.html" + RELEASES=$(curl $URL | awk '/var RELEASES = \[/,/];/' | sed 's/var RELEASES = \[//' | sed 's/];$//' | tr -d '",') + RELEASES+=(\'$NEW_RELEASE\') +fi + +NEW_RELEASES=() +for element in "${RELEASES[@]}"; do + NEW_RELEASES+=("$element,") +done +echo ${NEW_RELEASES[@]} + # Modifes some version and target fields of index.html echo "" >> html/index.html +" | tee -a docs/generic/html/index.html > /dev/null diff --git a/docs/esp_modem/generate_docs b/docs/esp_modem/generate_docs index c3552407703..dbe8adad2d4 100755 --- a/docs/esp_modem/generate_docs +++ b/docs/esp_modem/generate_docs @@ -1,5 +1,5 @@ # Cleanup the generated html -rm -rf html +rm -rf html docs # Generate C++ API header of the DCE cat ../../components/esp_modem/include/generate/esp_modem_command_declare.inc | clang++ -E -P -CC -xc++ -I../../components/esp_modem/include -DGENERATE_DOCS - | sed -n '1,/DCE command documentation/!p' > en/esp_modem_dce.hpp @@ -13,27 +13,31 @@ cat ../../components/esp_modem/include/generate/esp_modem_command_declare.inc | build-docs --target esp32 --language en -cp -rf _build/en/esp32/html . -rm -rf _build __pycache__ +mkdir -p docs/generic +mv _build/en/esp32/html docs/generic +rm -rf _build __pycache__ -# Modifes some version and target fields of index.html -echo "" >> html/index.html +" | tee -a docs/generic/html/index.html > /dev/null diff --git a/docs/esp_mqtt_cxx/generate_docs b/docs/esp_mqtt_cxx/generate_docs index def507c5ede..63710b8ce9c 100755 --- a/docs/esp_mqtt_cxx/generate_docs +++ b/docs/esp_mqtt_cxx/generate_docs @@ -1,21 +1,43 @@ +rm -rf docs + build-docs --target esp32 --language en -cp -rf _build/en/esp32/html . +mkdir -p docs/generic +mv _build/en/esp32/html docs/generic + rm -rf _build __pycache__ # Modifes some version and target fields of index.html echo "" >> html/index.html +" | tee -a docs/generic/html/index.html > /dev/null diff --git a/docs/esp_websocket_client/generate_docs b/docs/esp_websocket_client/generate_docs index def507c5ede..0b722051377 100755 --- a/docs/esp_websocket_client/generate_docs +++ b/docs/esp_websocket_client/generate_docs @@ -1,21 +1,43 @@ +rm -rf docs + build-docs --target esp32 --language en -cp -rf _build/en/esp32/html . +mkdir -p docs/generic +mv _build/en/esp32/html docs/generic + rm -rf _build __pycache__ # Modifes some version and target fields of index.html echo "" >> html/index.html +" | tee -a docs/generic/html/index.html > /dev/null diff --git a/docs/mdns/generate_docs b/docs/mdns/generate_docs index 3ad939356f6..34a24457ef8 100755 --- a/docs/mdns/generate_docs +++ b/docs/mdns/generate_docs @@ -1,23 +1,100 @@ +#!/bin/bash + +if [ "$#" -eq 1 ]; then + NEW_RELEASE=$1 +fi + +rm -rf docs build-docs --target esp32 --language en build-docs --target esp32 --language zh_CN -cp -rf _build/en/esp32/html en -cp -rf _build/zh_CN/esp32/html zh_CN +mkdir -p docs/en +mv _build/en/esp32/html docs/en +mkdir -p docs/zh_CN +mv _build/zh_CN/esp32/html docs/zh_CN + rm -rf _build __pycache__ tee +if [ -n NEW_RELEASE ]; then + URL="https://docs.espressif.com/projects/esp-protocols/mdns/docs/latest/en/index.html" + RELEASES=$(curl $URL | awk '/var RELEASES = \[/,/];/' | sed 's/var RELEASES = \[//' | sed 's/];$//' | tr -d '",') + RELEASES+=(\'$NEW_RELEASE\') +fi + +NEW_RELEASES=() +for element in "${RELEASES[@]}"; do + NEW_RELEASES+=("$element,") +done +echo ${NEW_RELEASES[@]} + # Modifes some version and target fields of index.html -echo "" | tee -a docs/en/html/index.html > /dev/null + +# Modifes some version and target fields of index.html +echo "" | tee -a html_en/index.html html_zh_CN/index.html > /dev/null +" | tee -a docs/zh_CN/html/index.html > /dev/null