From 78ea4e9aa4808efb48aa92ebef8e0f1521928d24 Mon Sep 17 00:00:00 2001 From: apolisskyi Date: Fri, 2 Aug 2024 00:27:28 +0400 Subject: [PATCH] :white_check_mark: feat(PlantUML) generate images gh action --- .github/workflows/doxygen-docs.yml | 2 +- .github/workflows/plantuml-docs.yml | 79 +++++++++++++++++++ firmware/iot-risk-logger-stm32l4/Doxyfile | 4 +- .../app/tasks/light_sensor/README.md | 7 +- .../app/tasks/light_sensor/light_sensor.h | 2 +- 5 files changed, 84 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/plantuml-docs.yml diff --git a/.github/workflows/doxygen-docs.yml b/.github/workflows/doxygen-docs.yml index b3d0897e..01b35f6e 100644 --- a/.github/workflows/doxygen-docs.yml +++ b/.github/workflows/doxygen-docs.yml @@ -3,7 +3,7 @@ name: doxygen-docs on: push: branches: - [ main ] #TODO remove not main branch + [ main ] jobs: gh-pages-doxygen-deploy: diff --git a/.github/workflows/plantuml-docs.yml b/.github/workflows/plantuml-docs.yml new file mode 100644 index 00000000..1263a9da --- /dev/null +++ b/.github/workflows/plantuml-docs.yml @@ -0,0 +1,79 @@ +name: Generate and Insert PlantUML SVG + +on: + push: + branches: + - main + pull_request: + branches: + [ main ] + +jobs: + generate-and-insert: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Set up JDK + uses: actions/setup-java@v3 + with: + distribution: 'adopt-openjdk' + java-version: '11' + + - name: Install PlantUML + run: | + mkdir -p ~/.local/bin + wget https://sourceforge.net/projects/plantuml/files/plantuml.jar/download -O ~/.local/bin/plantuml.jar + chmod +x ~/.local/bin/plantuml.jar + + - name: Generate SVG and update Markdown files + run: | + # Create directories for diagrams + mkdir -p diagrams + + # Process each markdown file + for file in $(find . -name '*.md'); do + # Create a temporary file for updated content + temp_file="updated_$(basename "$file")" + + # Read the file line by line + while IFS= read -r line; do + if [[ "$line" =~ ^@startuml ]]; then + # Extract the PlantUML diagram block + diagram="" + while IFS= read -r diagram_line && [[ ! "$diagram_line" =~ ^@enduml ]]; do + diagram+="$diagram_line\n" + done + # Generate the SVG + svg_file="diagrams/$(basename "$file" .md)_diagram.svg" + echo "$diagram" | java -jar ~/.local/bin/plantuml.jar -tsvg -pipe > "$svg_file" + # Insert SVG image link into temporary file + echo "![Diagram]($svg_file)" >> "$temp_file" + echo "" >> "$temp_file" # Add a blank line after the image link + # Add the PlantUML block to the temporary file + echo "$line" >> "$temp_file" + while IFS= read -r diagram_line && [[ ! "$diagram_line" =~ ^@enduml ]]; do + echo "$diagram_line" >> "$temp_file" + done + echo "$diagram_line" >> "$temp_file" # Add the @enduml line + else + # Copy other lines to the temporary file + echo "$line" >> "$temp_file" + fi + done < "$file" + + # Move updated file to the original location + mv "$temp_file" "$file" + done + + - name: Commit changes + run: | + git config --global user.name "github-actions" + git config --global user.email "actions@github.com" + git add . + git commit -m "Add PlantUML diagrams as SVG images in markdown files" + git push + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/firmware/iot-risk-logger-stm32l4/Doxyfile b/firmware/iot-risk-logger-stm32l4/Doxyfile index b47b3bb3..28c66c41 100644 --- a/firmware/iot-risk-logger-stm32l4/Doxyfile +++ b/firmware/iot-risk-logger-stm32l4/Doxyfile @@ -522,7 +522,7 @@ EXTRACT_PACKAGE = NO # included in the documentation. # The default value is: NO. -EXTRACT_STATIC = NO +EXTRACT_STATIC = YES # If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined # locally in source files will be included in the documentation. If set to NO, @@ -2615,7 +2615,7 @@ DIAFILE_DIRS = # a preprocessing step. Doxygen will generate a warning when it encounters a # \startuml command in this case and will not generate output for the diagram. -PLANTUML_JAR_PATH = +PLANTUML_JAR_PATH = $(PLANTUML_INSTALL_DIR)/plantuml.jar # When using plantuml, the PLANTUML_CFG_FILE tag can be used to specify a # configuration file for plantuml. diff --git a/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/README.md b/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/README.md index 655ea423..bc6841db 100644 --- a/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/README.md +++ b/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/README.md @@ -5,7 +5,7 @@ ### State Diagram ```plantuml -@startuml +@startuml{light_sensor_fsm.png} title Light Sensor FSM hide empty description TURNED_OFF: Initialized, turned off\nready for commands, low power mode @@ -25,10 +25,5 @@ ERROR --> TURNED_OFF : RECOVER TURNED_OFF --> ERROR : ERROR CONTINUOUS_MEASURE --> ERROR : ERROR OUT_OF_RANGE --> ERROR : ERROR - -json rawLux { - "exponent[15:12]":"0b111", - "mantissa[12:0]":"0b111" -} @enduml ``` \ No newline at end of file diff --git a/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/light_sensor.h b/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/light_sensor.h index f643077c..908571d8 100644 --- a/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/light_sensor.h +++ b/firmware/iot-risk-logger-stm32l4/app/tasks/light_sensor/light_sensor.h @@ -2,7 +2,7 @@ * @file light_sensor.h * @brief Brief description of the file. * - * Detailed description of the file. + * TODO Detailed description of the file. * * @date 28/07/2024 * @author artempolisskyi