Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 117 additions & 0 deletions .github/scripts/extract_and_generate_html.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!/bin/bash

# Destination directory path
destination_dir="doc/gatling"

# Function to copy JS and CSS files
copy_js_and_css() {
mkdir -p "${destination_dir}/js"
mkdir -p "${destination_dir}/style"
cp -rf "./loading/target/gatling/${1}/js" "${destination_dir}"
cp -rf "./loading/target/gatling/${1}/style" "${destination_dir}"
}

# Function to perform replacements in HTML files
replace_in_html_files() {
search="$1"
replace="$2"
directory="$3"
find "${destination_dir}/${directory}" -type f -name "*.html" -exec sed -i -e "s|$search|$replace|g" {} \;
}

# Fonction pour extraire et formater les résultats
generate_html_table() {
run="$1"
stats_file="./loading/target/gatling/$run/js/stats.json"

# Extraire les données nécessaires du fichier JSON avec jq
tableContent=$(jq -r '
(.contents[] | "
<tr>
<th>" + .stats.name + "</th>
<th>" + (.stats.numberOfRequests.ok | tostring) + "</th>
<th>" + (.stats.numberOfRequests.ko | tostring) + "</th>
<th>" + (.stats.minResponseTime.total | tostring) + "</th>
<th>" + (.stats.maxResponseTime.total | tostring) + "</th>
<th>" + (.stats.meanResponseTime.total | tostring) + "</th>
<th>" + (.stats.standardDeviation.total | tostring) + "</th>
<th>" + (.stats.meanNumberOfRequestsPerSecond.total | tostring) + "</th>
</tr>"
)' "$stats_file")

# Créer le tableau HTML
htmlTable="<table>
<tr><th>Request</th><th>Success ✅</th><th>Errors ❌</th><th>Min</th><th>Max</th><th>Avg.</th><th>Std. Dev.</th><th>RPS</th></tr>
$tableContent
</table>"

# Imprimer le contenu HTML
echo "$htmlTable"
}

# Read the contents of lastRun.txt and sort it
last_runs=($(sort -n < loading/target/gatling/lastRun.txt))

# Create the HTML template
template_file="./.github/scripts/template.html"
output_file="loading/target/gatling/summary.html"
cp "$template_file" "$output_file"

# Initialize the content variable
content=""

# Copy JS and CSS for the first run
copy_js_and_css "${last_runs[0]}"

# Iterate through the directories obtained from lastRun.txt
for run in "${last_runs[@]}"; do
# Extract name and date from the entry
report_name="${run%-*}"
timestamp="${run#*-}"
year="${timestamp:0:4}"
month="${timestamp:4:2}"
day="${timestamp:6:2}"
hour="${timestamp:8:2}"
minute="${timestamp:10:2}"
second="${timestamp:12:2}"

formatted_date="${year}-${month}-${day} ${hour}:${minute}:${second}"

# Construct the desired output
content+=" <li><h2>Results for <a href='./$run/index.html'>$report_name</a> at $formatted_date</h2></li>"

html_output=$(generate_html_table ${run})

# Append le contenu de la table à la variable content
content+="$html_output"

# Copy .html and .log files to the destination directory
mkdir -p "${destination_dir}/$run"
cp -rf "./loading/target/gatling/$run"/* "${destination_dir}/$run"

# Remove unnecessary directories
rm -rf "${destination_dir}/$run"/js
rm -rf "${destination_dir}/$run"/style

# Perform replacements in HTML files
replace_in_html_files "src=\"js/" "src=\"../js/" "$run"
replace_in_html_files "\"style/" "\"../style/" "$run"

find "${destination_dir}/${run}" -type f -name "*.html" -exec sed -i 's/details_link\" href=\//details_link\" href=\"\.\//g' {} \;

replace_in_html_files "details_link\" href=\"" "details_link\" href=\"./" "$run"

# Add "SUMMARY" link back to the Summary
replace_in_html_files '<div class="sous-menu">' '<div class="sous-menu"><div class="item "><a href="../summary.html">SUMMARY</a></div>' "$run"
done

ls -la ${destination_dir}

tree ${destination_dir}

# Replace {{CONTENT}} in the template with the generated content
# sed -i "s|{{CONTENT}}|$content|g" "$output_file"
sed -i -e "/{{CONTENT}}/r /dev/stdin" "$output_file" <<< "$content"

# Copy the summary.html file to the destination directory
cp "$output_file" "${destination_dir}"
33 changes: 33 additions & 0 deletions .github/scripts/template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" type="image/x-icon" href="style/favicon.ico"/>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<link href="style/bootstrap.min.css" rel="stylesheet" type="text/css" />
<title>Gatling Stats - Global Information</title>
</head>
<body>
<div class="frise"></div>
<div class="container details">
<div class="head">
<a class="logo" href="https://gatling.io" target="blank_" title="Gatling Home Page"><img alt="Gatling" src="style/logo.svg"/></a>
<div class="frontline"><a href="https://gatling.io/gatling-frontline/?report" target="_blank">Get more features with Gatling FrontLine</a></div>
</div>
<div class="main">
<div class="cadre">
<div class="content">
<div class="sous-menu">
</div>
<div class="content-in">
<h1><span>> </span>Suit Tests</h1>
<ul>
{{CONTENT}}
</ul>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
143 changes: 137 additions & 6 deletions .github/workflows/build-feature.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ concurrency:

jobs:
analyze_code:
environment:
name: analyze-code-quality
url: https://sonarcloud.io/summary/new_code?id=Raouf25_spring-boot-asynchronous-api
name: Analyze Code Quality
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -84,9 +87,9 @@ jobs:

non_regression_test:
name: Non Regression Test
environment:
name: dev-karate-report
url: ${{ steps.deployment.outputs.page_url }}karate-summary.html
# environment:
# name: dev-karate-report
# url: ${{ steps.deployment.outputs.page_url }}karate/karate-summary.html
needs: deploy
runs-on: ubuntu-latest
steps:
Expand Down Expand Up @@ -115,13 +118,136 @@ jobs:
- name: Non Regression Test
continue-on-error: true
run: |
mvn clean test --f ./nrt/pom.xml -PflyServer -Dapi.url='https://spring-boot-asynchronous-api.fly.dev'
mvn clean test --f ./nrt/pom.xml -PflyServer -Dapi.url='https://spring-boot-asynchronous-api.fly.dev'

# Create a "doc" directory and move karate reports to it
- name: Get report
run: |
mkdir -p doc
mv ./nrt/target/karate-reports/* ./doc
mkdir -p doc/karate
mv ./nrt/target/karate-reports/* ./doc/karate

- uses: actions/upload-artifact@master
with:
name: karate-reports
path: doc/karate
# - name: Upload artifact
# uses: actions/upload-pages-artifact@v1
# with:
# # Upload entire repository
# path: './doc'
# - name: Deploy to GitHub Pages
# id: deployment
# uses: actions/deploy-pages@v1

loading_test:
name: Loading Test
# environment:
# name: prep-loading-report
# url: ${{ steps.deployment.outputs.page_url }}gatling/summary.html
needs: non_regression_test
runs-on: ubuntu-latest
steps:
# Checkout the code from the repository
- name: Checkout
uses: actions/checkout@v3

# Execute Gatling Test Suite
- name: Execute Gatling Test Suite
continue-on-error: true
run: |
mvn clean gatling:test --f loading/pom.xml

- name: Install jq
run: |
sudo apt-get update -y
sudo apt-get install jq -y
shell: bash

# New step to generate gatling-summary.html
- name: Generate gatling-summary HTML
run: |
.github/scripts/extract_and_generate_html.sh
shell: bash

- uses: actions/upload-artifact@master
with:
name: gatling-reports
path: doc/gatling

# - name: Upload artifact
# uses: actions/upload-pages-artifact@v1
# with:
# # Upload entire repository
# path: './doc'
# - name: Deploy to GitHub Pages
# id: deployment
# uses: actions/deploy-pages@v1

- name: Generate Job Summary
uses: actions/github-script@v6
with:
script: |
const fs = require('fs')
const lastRuns = fs.readFileSync(`loading/target/gatling/lastRun.txt`).toString().trim().split('\n');

for(const run of lastRuns) {
const formattedLine = run.replace(/(.*)-(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/, ' $1 at $2-$3-$4 $5:$6:$7');
const results = JSON.parse(fs.readFileSync(`loading/target/gatling/${run}/js/stats.json`).toString());
let tableContent = [
[
{data: 'Request', header: true},
{data: 'Success ✅', header: true},
{data: 'Errors ❌', header: true},
{data: 'Min', header: true},
{data: 'Max', header: true},
{data: 'Avg.', header: true},
{data: 'Std. Dev.', header: true},
{data: 'RPS', header: true},
]
];

for(const result in results.contents) {
const requestMetrics = results.contents[result].stats;
tableContent.push([
requestMetrics.name,
requestMetrics.numberOfRequests.ok.toString(),
requestMetrics.numberOfRequests.ko.toString(),
requestMetrics.minResponseTime.total.toString(),
requestMetrics.maxResponseTime.total.toString(),
requestMetrics.meanResponseTime.total.toString(),
requestMetrics.standardDeviation.total.toString(),
requestMetrics.meanNumberOfRequestsPerSecond.total.toString(),
]);
}

await core.summary
.addHeading(`Results for ${formattedLine}`)
.addTable(tableContent)
.addQuote('All times are in millisecond (ms). RPS means "Requests per Second"')
.write()
}

deploy_reports:
name: Deploy Reports
needs:
- non_regression_test
- loading_test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Retrieve saved Non Regression Test
uses: actions/download-artifact@v3
with:
name: karate-reports
path: doc/karate

- name: Retrieve saved Loading Test
uses: actions/download-artifact@v3
with:
name: gatling-reports
path: doc/gatling

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
Expand All @@ -131,3 +257,8 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

- name: Echo URL Reports
run: |
echo "Non Regression Test url : ${{ steps.deployment.outputs.page_url }}karate/karate-summary.html"
echo "Loading Test url : ${{ steps.deployment.outputs.page_url }}gatling/summary.html"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
app/target/
loading/target/
nrt/target/
**/.DS_Store

### STS ###
.apt_generated
Expand All @@ -29,3 +31,5 @@ build/

### VS Code ###
.vscode/

.DS_Store
26 changes: 24 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,37 @@ RUN mvn -f /build/pom.xml clean package
# Package stage
#
# base image to build a JRE
FROM amazoncorretto:19.0.2-alpine as corretto-jdk
FROM amazoncorretto:19.0.2-alpine AS deps

# Identify dependencies
COPY --from=MAVEN_BUILD ./build/app/target/*-SNAPSHOT.jar /app/app.jar
RUN mkdir /app/unpacked && \
cd /app/unpacked && \
unzip ../app.jar && \
cd .. && \
$JAVA_HOME/bin/jdeps \
--ignore-missing-deps \
--print-module-deps \
-q \
--recursive \
--multi-release 17 \
--class-path="./unpacked/BOOT-INF/lib/*" \
--module-path="./unpacked/BOOT-INF/lib/*" \
./app.jar > /deps.info

# base image to build a JRE
FROM amazoncorretto:19.0.2-alpine AS corretto-jdk

# required for strip-debug to work
RUN apk add --no-cache binutils

# copy module dependencies info
COPY --from=deps /deps.info /deps.info

# Build small JRE image
RUN $JAVA_HOME/bin/jlink \
--verbose \
--add-modules ALL-MODULE-PATH \
--add-modules $(cat /deps.info) \
--strip-debug \
--no-man-pages \
--no-header-files \
Expand Down
Loading