Skip to content

Commit

Permalink
🐛 📚 Fix mermaid diagram generation on Ubuntu
Browse files Browse the repository at this point in the history
Problem:
- Ubuntu 23.10 and later has security rules around running chrome, which means
  mermaid-cli can't generate diagrams without a workaround.
- See mermaid-js/mermaid-cli#730

Solution:
- Provide a puppeteer_config.json file in the docs directory which can be passed
  to mmdc by specifying an attribute in AsciiDoctor markdown.
- See https://docs.asciidoctor.org/diagram-extension/latest/diagram_types/mermaid/
  • Loading branch information
elbeno committed Oct 28, 2024
1 parent 53a3a03 commit ff13ef0
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 17 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/asciidoctor-ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ jobs:
node-version: 20
- name: Install Mermaid
run: |
sudo npm install -g @mermaid-js/[email protected]
sudo npm install -g @mermaid-js/[email protected]
npx puppeteer browsers install chrome-headless-shell
- name: Install asciidoctor
run: |
sudo apt update
Expand Down
29 changes: 15 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ jobs:

- name: Install Mermaid
run: |
sudo npm install -g @mermaid-js/[email protected]
sudo npm install -g @mermaid-js/[email protected]
npx puppeteer browsers install chrome-headless-shell
- name: Install asciidoctor
run: |
Expand Down Expand Up @@ -75,32 +76,32 @@ jobs:
run: |
pip install mypy black
- name: Restore CPM cache
env:
cache-name: cpm-cache-0
id: cpm-cache-restore
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ~/cpm-cache
key: ${{runner.os}}-${{env.cache-name}}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }}
restore-keys: |
${{runner.os}}-${{env.cache-name}}-
- name: Configure cmake for lib
env:
CC: "/usr/lib/llvm-${{env.TARGET_LLVM_VERSION}}/bin/clang"
CXX: "/usr/lib/llvm-${{env.TARGET_LLVM_VERSION}}/bin/clang++"
PR_TARGET_BRANCH: ${{ steps.target_branch.outputs.branch }}
working-directory: ${{github.workspace}}/test/library
run: cmake -Bbuild -DCPM_SOURCE_CACHE=~/cpm-cache
run: cmake -Bbuild

- name: Check lib quality
working-directory: ${{github.workspace}}/test/library
run: cmake --build build -t ci-quality

- name: Build lib docs
working-directory: ${{github.workspace}}/test/library
run: cmake --build build -t docs
run: test $(cmake --build build -v -t docs | grep -c ERROR) == 0

- name: Restore CPM cache
env:
cache-name: cpm-cache-0
id: cpm-cache-restore
uses: actions/cache/restore@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ~/cpm-cache
key: ${{runner.os}}-${{env.cache-name}}-${{ hashFiles('**/CMakeLists.txt', 'cmake/**') }}
restore-keys: |
${{runner.os}}-${{env.cache-name}}-
- name: Configure cmake for app
env:
Expand Down
3 changes: 2 additions & 1 deletion ci/.github/workflows/asciidoctor-ghpages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ jobs:
node-version: 20
- name: Install Mermaid
run: |
sudo npm install -g @mermaid-js/[email protected]
sudo npm install -g @mermaid-js/[email protected]
npx puppeteer browsers install chrome-headless-shell
- name: Install asciidoctor
run: |
sudo apt update
Expand Down
6 changes: 6 additions & 0 deletions cmake/main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ option(INFRA_PROVIDE_PRESETS "Provide cmake presets and toolchains" ON)
option(INFRA_PROVIDE_MULL "Provide mull.yml file" ON)
option(INFRA_PROVIDE_PYTEST_REQS
"Provide pip requirements.txt for python tests" ON)
option(
INFRA_PROVIDE_PUPPETEER_CONFIG
"Provide puppeteer_config.json for generating mermaid diagrams in documentation"
ON)
option(INFRA_PROVIDE_GITIGNORE "Add provided things to .gitignore" ON)
option(INFRA_USE_SYMLINKS "Use symlinks to provide common files" ON)

Expand All @@ -38,6 +42,8 @@ if(${PROJECT_SOURCE_DIR}/cmake STREQUAL CMAKE_CURRENT_LIST_DIR)
set(INFRA_PROVIDE_CMAKE_FORMAT OFF)
set(INFRA_PROVIDE_PRESETS OFF)
set(INFRA_PROVIDE_MULL OFF)
set(INFRA_PROVIDE_PYTEST_REQS OFF)
set(INFRA_PROVIDE_PUPPETEER_CONFIG OFF)
set(INFRA_PROVIDE_GITIGNORE OFF)
endif()

Expand Down
12 changes: 12 additions & 0 deletions cmake/setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function(make_gitignore)
list(APPEND GITIGNORE_CONTENTS "requirements.txt")
endif()
endif()
if(INFRA_PROVIDE_PUPPETEER_CONFIG)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/docs/puppeteer_config.json")
list(APPEND GITIGNORE_CONTENTS "docs/puppeteer_config.json")
endif()
endif()
endif()

string(REPLACE ";" "\n" GITIGNORE_CONTENTS "${GITIGNORE_CONTENTS}")
Expand All @@ -61,6 +66,10 @@ function(make_gitignore)
endfunction()

function(put_in_project_dir FILENAME)
get_filename_component(DIRNAME ${FILENAME} DIRECTORY)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
"${CMAKE_SOURCE_DIR}/${DIRNAME}")

if(INFRA_USE_SYMLINKS)
set(put_command "create_symlink")
else()
Expand Down Expand Up @@ -120,6 +129,9 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
if(INFRA_PROVIDE_PYTEST_REQS)
put_in_project_dir("requirements.txt")
endif()
if(INFRA_PROVIDE_PUPPETEER_CONFIG)
put_in_project_dir("docs/puppeteer_config.json")
endif()

if(INFRA_PROVIDE_GITHUB_WORKFLOWS)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
Expand Down
1 change: 1 addition & 0 deletions docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
:rouge-style: base16.solarized
:source-language: c++
:toc: left
:mermaid-puppeteer-config: puppeteer_config.json

include::intro.adoc[]
include::options.adoc[]
Expand Down
3 changes: 3 additions & 0 deletions docs/puppeteer_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"args": ["--no-sandbox"]
}
2 changes: 2 additions & 0 deletions test/application/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ rm -f mull.yml
rm -f .gitignore
rm -f CMakePresets.json
rm -f toolchains
rm -f requirements.txt

rm -rf docs
rm -rf build
rm -rf .github
2 changes: 2 additions & 0 deletions test/library/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ rm -f mull.yml
rm -f .gitignore
rm -f CMakePresets.json
rm -f toolchains
rm -f requirements.txt
rm -f docs/puppeteer_config.json

rm -rf build
rm -rf .github
1 change: 1 addition & 0 deletions test/library/docs/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Ben Deane <[email protected]>
:rouge-style: base16.solarized
:source-language: c++
:toc: left
:mermaid-puppeteer-config: puppeteer_config.json

== Introduction

Expand Down
2 changes: 1 addition & 1 deletion test/verify_links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail

echo "Verifying links in "`pwd`

links=( .clang-format .clang-tidy .cmake-format.yaml CMakePresets.json toolchains )
links=( .clang-format .clang-tidy .cmake-format.yaml CMakePresets.json docs/puppeteer_config.json mull.yml requirements.txt toolchains )
for l in "${links[@]}"
do
if ! [[ -L "application/${l}" ]]; then
Expand Down

0 comments on commit ff13ef0

Please sign in to comment.