Skip to content

Commit

Permalink
Re-enable artifacts via dashboard update (rust-lang#547)
Browse files Browse the repository at this point in the history
* Re-enable artifacts via dashboard update

* Proper parsing, main and docs

* Copy fixup
  • Loading branch information
adpaco-aws authored and tedinski committed Oct 14, 2021
1 parent 424ead0 commit ef9ce7e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
10 changes: 8 additions & 2 deletions rmc-docs/build-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
63 changes: 63 additions & 0 deletions scripts/ci/update_dashboard.py
Original file line number Diff line number Diff line change
@@ -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/<book>/<chapter>/<section>/<subsection>/<line>.rs`
However, only the first part is shown since these paths are enclosed
in paragraph markers (`<p>` and `</p>`). So they are often rendered as:
`src/test/dashboard/books/<book>/<chapter>/...
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:
`<book>/<chapter>/<section>/<subsection>/<line>.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()
1 change: 1 addition & 0 deletions scripts/setup/install_dashboard_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down

0 comments on commit ef9ce7e

Please sign in to comment.