From ef9ce7ee7d7d81743a61f30e39aec968f1724b63 Mon Sep 17 00:00:00 2001 From: Adrian Palacios <73246657+adpaco-aws@users.noreply.github.com> Date: Thu, 14 Oct 2021 13:41:37 -0400 Subject: [PATCH] Re-enable artifacts via dashboard update (#547) * Re-enable artifacts via dashboard update * Proper parsing, main and docs * Copy fixup --- rmc-docs/build-docs.sh | 10 +++- scripts/ci/update_dashboard.py | 63 +++++++++++++++++++++++++ scripts/setup/install_dashboard_deps.sh | 1 + 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 scripts/ci/update_dashboard.py diff --git a/rmc-docs/build-docs.sh b/rmc-docs/build-docs.sh index eb9defad5968d..93a9fa869d4c3 100755 --- a/rmc-docs/build-docs.sh +++ b/rmc-docs/build-docs.sh @@ -24,9 +24,15 @@ HTML_DIR=$RMC_DIR/build/output/latest/html/ if [ -d $HTML_DIR ]; then # Litani run is copied into `src` to avoid deletion by `mdbook` cp -r $HTML_DIR src/dashboard/ - # Remove unnecessary artifacts to save space + # Replace artifacts by examples under test + BOOKS_DIR=$RMC_DIR/src/test/dashboard/books rm -r src/dashboard/artifacts - rm -r src/dashboard/run.json + cp -r $BOOKS_DIR src/dashboard/artifacts + # Update paths in HTML dashboard + python $RMC_DIR/scripts/ci/update_dashboard.py src/dashboard/index.html new_index.html + mv new_index.html src/dashboard/index.html + + rm src/dashboard/run.json else echo "WARNING: Could not find the latest dashboard run." fi diff --git a/scripts/ci/update_dashboard.py b/scripts/ci/update_dashboard.py new file mode 100644 index 0000000000000..98d60df29a12c --- /dev/null +++ b/scripts/ci/update_dashboard.py @@ -0,0 +1,63 @@ +#!/usr/bin/python3 +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 OR MIT + +import argparse +from bs4 import BeautifulSoup + +def update_path(run, path): + ''' + Shortens a path referring to an example and adds a link to the file. + + By default, the path to an example follows this pattern: + + `src/test/dashboard/books///
//.rs` + + However, only the first part is shown since these paths are enclosed + in paragraph markers (`

` and `

`). So they are often rendered as: + + `src/test/dashboard/books///... + + This update removes `src/test/dashboard/books/` from the path (common to + all examples) and transforms them into anchor elements with a link to + the example, so the path to the example is shown as: + + `//
//.rs` + ''' + orig_path = path.p.string + new_string = '/'.join(orig_path.split('/')[4:]) + new_tag = run.new_tag('a') + new_tag.string = new_string + # Add link to the example + new_tag['href'] = "artifacts/" + new_string + path.p.replace_with(new_tag) + +def main(): + parser = argparse.ArgumentParser( + description='Produces an updated HTML dashboard file from the ' + 'contents of an HTML file generated with `litani`') + parser.add_argument('input') + parser.add_argument('output') + args = parser.parse_args() + + with open(args.input) as fp: + run = BeautifulSoup(fp, 'html.parser') + + # Update pipeline names to link to the example under test + for row in run.find_all('div', attrs={'class': 'pipeline-row'}): + path = row.find('div', attrs={'class': 'pipeline-name'}) + # Some paths here may be `None` - skip them + if path.p: + update_path(run, path) + + # Delete links to empty artifacts folder from progress bars + for bar in run.find_all('a', attrs={'class': 'stage-artifacts-link fail'}): + del bar['href'] + for bar in run.find_all('a', attrs={'class': 'stage-artifacts-link success'}): + del bar['href'] + + with open(args.output, "w") as file: + file.write(str(run)) + +if __name__ == "__main__": + main() diff --git a/scripts/setup/install_dashboard_deps.sh b/scripts/setup/install_dashboard_deps.sh index 97f09a0a6b857..662d300ed9c68 100755 --- a/scripts/setup/install_dashboard_deps.sh +++ b/scripts/setup/install_dashboard_deps.sh @@ -15,6 +15,7 @@ DEPS=( sudo DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes "${DEPS[@]}" PYTHON_DEPS=( + bs4 # Used for dashboard updates jinja2 )