From 4e5d348a0536f75014852026777f68573fe5d615 Mon Sep 17 00:00:00 2001 From: Ekrem Seren Date: Thu, 7 Dec 2023 03:49:47 +0300 Subject: [PATCH] Create smaller svg files --- .github/workflows/ci.yaml | 2 ++ scripts/generate_protodot.sh | 5 +++++ scripts/insert_diagram_link.sh | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 scripts/insert_diagram_link.sh diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3e734886..2c7260b9 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -47,6 +47,8 @@ jobs: - uses: actions/checkout@v4 - name: Setup Graphviz uses: ts-graphviz/setup-graphviz@v1 + - name: Install librsvg2-bin + run: sudo apt-get install -y librsvg2-bin # Generate diagrams - name: Generate Diagrams diff --git a/scripts/generate_protodot.sh b/scripts/generate_protodot.sh index caa8250c..cda4dd46 100755 --- a/scripts/generate_protodot.sh +++ b/scripts/generate_protodot.sh @@ -77,6 +77,11 @@ for protofile in `find ${PROTO_DIR} -type f -name '*.proto'`; do # Create the protodot diagram ${PROTODOT} -generated ${protofile_dir} -src ${protofile} -output $(basename ${protofile}) + + # Create a scaled version of the diagram + svg_filename="${protofile}.dot.svg" + xs_filename="${protofile}.dot.xs.svg" + rsvg-convert "${svg_filename}" -w 850 -f svg -o "${xs_filename}" done # When generating finished, revert the truncated big enums diff --git a/scripts/insert_diagram_link.sh b/scripts/insert_diagram_link.sh new file mode 100644 index 00000000..980dff5f --- /dev/null +++ b/scripts/insert_diagram_link.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Directory to search +directory="proto" + +# Process each .proto file found +find "$directory" -type f -name "*.proto" | while read -r proto_file; do + awk ' + !inserted && /^enum|^message/ { + gsub(/\/path\/to\/directory\//, "", FILENAME) # Remove the base directory path + print "// ![Click for diagram](https://storage.googleapis.com/docs-cmp-files/diagrams/" FILENAME ".dot.svg)" + inserted=1 + } + { print } + ' "$proto_file" > temp_file && mv -v temp_file "$proto_file" +done