create summary.md from lhci reports

This commit is contained in:
Robert Kaussow 2020-09-20 17:13:36 +02:00
parent 80be57afe7
commit 4c127c2628
No known key found for this signature in database
GPG Key ID: 65362AE74AF98B61
2 changed files with 19 additions and 4 deletions

View File

@ -0,0 +1,4 @@
### LHCI Report Overview
| URL | Performance | Accessibility | Best-Practices | SEO | PWA | Report |
| --- | ----------- | ------------- | -------------- | --- | --- | ------ |

View File

@ -3,10 +3,10 @@ set -eo pipefail
CONFIG="${LHCI_BASE_DIR%/}/.lighthouserc.yml" CONFIG="${LHCI_BASE_DIR%/}/.lighthouserc.yml"
/usr/local/bin/lhci "$@" || ERROR=true exec 5>&1
OUT=$(/usr/local/bin/lhci "$@" | tee /dev/fd/5) || ERROR=true
if [ -f "$CONFIG" ]; then
if [ -f "$CONFIG" ] && echo "$OUT" | grep -q "Done running Lighthouse"; then
UPLOAD_TARGET=$(yq r "${CONFIG}" --defaultValue "" ci.upload.target) UPLOAD_TARGET=$(yq r "${CONFIG}" --defaultValue "" ci.upload.target)
UPLOAD_OUTPUT_DIR=$(yq r "${CONFIG}" --defaultValue "" ci.upload.outputDir) UPLOAD_OUTPUT_DIR=$(yq r "${CONFIG}" --defaultValue "" ci.upload.outputDir)
@ -16,6 +16,8 @@ if [ -f "$CONFIG" ]; then
mkdir -p "${DIST}" mkdir -p "${DIST}"
if [ -f "$CONFIG" ]; then if [ -f "$CONFIG" ]; then
cp /templates/summary.md "${DIST}/summary.md"
printf "\nPost-process report files...\n" printf "\nPost-process report files...\n"
for ITEM in $(jq -r '.[] | select( .isRepresentativeRun == true ) | @base64' < "${MANIFEST}"); do for ITEM in $(jq -r '.[] | select( .isRepresentativeRun == true ) | @base64' < "${MANIFEST}"); do
JSON=$(echo "${ITEM}" | base64 -d) JSON=$(echo "${ITEM}" | base64 -d)
@ -24,10 +26,19 @@ if [ -f "$CONFIG" ]; then
FILENAME=$(echo "${JSON}" | jq -r '.htmlPath') FILENAME=$(echo "${JSON}" | jq -r '.htmlPath')
HASH=$(sha1sum "$FILENAME") HASH=$(sha1sum "$FILENAME")
FILENAME_NEW="${HASH:0:8}-$FILE_DATE" FILENAME_NEW="${HASH:0:8}-$FILE_DATE"
DONWLOAD=${LHCI_SERVER_URL%/}/$(basename "${FILENAME_NEW}").html
URL=$(echo "${JSON}" | jq -r '.url') URL=$(echo "${JSON}" | jq -r '.url')
PERF=$(echo "${JSON}" | jq -r '.summary.performance')
ACCESS=$(echo "${JSON}" | jq -r '.summary.accessibility')
PRACTICE=$(echo "${JSON}" | jq -r '.summary["best-practices"]')
SEO=$(echo "${JSON}" | jq -r '.summary.seo')
PWA=$(echo "${JSON}" | jq -r '.summary.pwa')
cp "${FILENAME}" "${DIST}/${FILENAME_NEW}.html" cp "${FILENAME}" "${DIST}/${FILENAME_NEW}.html"
echo "Report for ${URL} will be uploaded to ${LHCI_SERVER_URL%/}/$(basename "${FILENAME_NEW}").html" echo "Report for ${URL} will be uploaded to ${DONWLOAD}"
echo "| \`${URL}\` | $(echo "scale=0;($PERF*100)/1" | bc) % | $(echo "scale=0;($ACCESS*100)/1" | bc) % | $(echo "scale=0;($PRACTICE*100)/1" | bc) % | $(echo "scale=0;($SEO*100)/1" | bc) % | $(echo "scale=0;($PWA*100)/1" | bc) % |" >> "${DIST}/summary.md"
done done
else else
printf "\nPost-processing skipped. Manifest not found!\n" printf "\nPost-processing skipped. Manifest not found!\n"