52 lines
2.1 KiB
Bash
Executable File
52 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env sh
|
|
set -eo pipefail
|
|
|
|
CONFIG="${LHCI_BASE_DIR%/}/.lighthouserc.yml"
|
|
|
|
exec 5>&1
|
|
OUT=$(/usr/local/bin/lhci "$@" | tee /dev/fd/5) || ERROR=true
|
|
|
|
if [ -f "$CONFIG" ] && echo "$OUT" | grep -q "Done running Lighthouse"; then
|
|
UPLOAD_TARGET=$(yq r "${CONFIG}" --defaultValue "" ci.upload.target)
|
|
UPLOAD_OUTPUT_DIR=$(yq r "${CONFIG}" --defaultValue "" ci.upload.outputDir)
|
|
|
|
if [ "${UPLOAD_TARGET}" = "filesystem" ] && [ -n "${UPLOAD_OUTPUT_DIR}" ] ; then
|
|
MANIFEST=${UPLOAD_OUTPUT_DIR%/}/manifest.json
|
|
DIST="${LHCI_BASE_DIR%/}/${UPLOAD_OUTPUT_DIR%/}/dist"
|
|
mkdir -p "${DIST}"
|
|
|
|
if [ -f "$CONFIG" ]; then
|
|
cp /templates/summary.md "${DIST}/summary.md"
|
|
|
|
printf "\nPost-process report files...\n"
|
|
for ITEM in $(jq -r '.[] | select( .isRepresentativeRun == true ) | @base64' < "${MANIFEST}"); do
|
|
JSON=$(echo "${ITEM}" | base64 -d)
|
|
FILE_DATE=$(date '+%Y%m%d%H%M')
|
|
|
|
FILENAME=$(echo "${JSON}" | jq -r '.htmlPath')
|
|
HASH=$(sha1sum "$FILENAME")
|
|
FILENAME_NEW="${HASH:0:8}-$FILE_DATE"
|
|
DONWLOAD=${LHCI_SERVER_URL%/}/$(basename "${FILENAME_NEW}").html
|
|
|
|
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"
|
|
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
|
|
else
|
|
printf "\nPost-processing skipped. Manifest not found!\n"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$ERROR" ]; then
|
|
exit 1
|
|
fi
|