Skip to content
Snippets Groups Projects

Updated pipeline to deploy site and test coverage report to Gitlab Pages

Merged Andreas Kluge Svendsrud requested to merge feat/workflow-ci-coverage-report into master
7 files
+ 181
19
Compare changes
  • Side-by-side
  • Inline
Files
7
+ 50
0
# Function is used to modify target/site/project-reports.html to include
# a link to the JaCoCo generated coverage files at target/site/jacoco/index.html.
def add_jacoco_coverage_link_to_html(file_path):
import bs4
# Open and read the HTML file at file_path
with open(file_path, 'r', encoding='utf-8') as file:
original_html = file.read()
# Parse the content of the HTML file using Beautiful Soup (bs4)
soup = bs4.BeautifulSoup(original_html, features='html.parser')
# Find the <ul> element that contains the Checkstyle link inside the Project Reports navigation section
# This is where we wanna add a list item for the JaCoCo coverage report
nav_list = soup.find("li", class_="active").find("ul", class_="nav nav-list")
# Create the new list item for JaCoCo
new_li = soup.new_tag("li")
new_a = soup.new_tag("a", href="jacoco/index.html")
new_a.string = "Jacoco Coverage"
new_li.append(new_a)
# Add the new list item to the navigation list
nav_list.append(new_li)
# Find the table that contains the Checkstyle link
# This is where we wanna add a table that contains a link for the JaCoCo report
table = soup.find("table", class_="table table-striped")
# Create the new table row for JaCoCo
new_tr = soup.new_tag("tr", **{"class": "a"})
new_td1 = soup.new_tag("td")
new_a2 = soup.new_tag("a", href="jacoco/index.html")
new_a2.string = "Jacoco Coverage"
new_td2 = soup.new_tag("td")
new_td2.string = "Code coverage report generated by JaCoCo."
new_td1.append(new_a2)
new_tr.append(new_td1)
new_tr.append(new_td2)
# Add the new table row to the table
table.append(new_tr)
# Write the modified HTML content back to the original file
with open(file_path, 'w', encoding='utf-8') as file:
file.write(str(soup.prettify()))
file_path = 'target/site/project-reports.html'
add_jacoco_coverage_link_to_html(file_path)
Loading