lhci/overlay/usr/bin/lhci

52 lines
2.1 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env bash
2020-07-16 07:53:03 +00:00
set -eo pipefail
CONFIG="${LHCI_BASE_DIR%/}/.lighthouserc.yml"
2020-09-20 15:13:36 +00:00
exec 5>&1
OUT=$(/usr/local/bin/lhci "$@" | tee /dev/fd/5) || ERROR=true
2020-07-16 07:53:03 +00:00
2020-09-20 15:13:36 +00:00
if [ -f "$CONFIG" ] && echo "$OUT" | grep -q "Done running Lighthouse"; then
2020-12-23 14:14:25 +00:00
UPLOAD_TARGET=$(yq e '.ci.upload.target // ""' "${CONFIG}")
UPLOAD_OUTPUT_DIR=$(yq e '.ci.upload.outputDir // ""' "${CONFIG}")
2020-07-16 07:53:03 +00:00
2021-05-21 13:44:29 +00:00
if [ "${UPLOAD_TARGET}" = "filesystem" ] && [ -n "${UPLOAD_OUTPUT_DIR}" ]; then
2020-07-16 07:53:03 +00:00
MANIFEST=${UPLOAD_OUTPUT_DIR%/}/manifest.json
2020-07-16 08:09:13 +00:00
DIST="${LHCI_BASE_DIR%/}/${UPLOAD_OUTPUT_DIR%/}/dist"
2020-07-16 07:53:03 +00:00
mkdir -p "${DIST}"
if [ -f "$CONFIG" ]; then
2021-05-21 13:44:29 +00:00
cp /templates/summary.md "${DIST}/summary.md"
2020-09-20 15:13:36 +00:00
printf "\nPost-process report files...\n"
2021-05-21 13:44:29 +00:00
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"
DOWNLOAD=${LHCI_SERVER_URL%/}/$(basename "${FILENAME_NEW}").html
2020-09-20 15:13:36 +00:00
URL=$(echo "${JSON}" | jq -r '.url')
2020-09-20 15:13:36 +00:00
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 ${DOWNLOAD}"
2020-09-20 15:13:36 +00:00
2021-05-21 13:44:29 +00:00
echo "| [Link](${DOWNLOAD}) | \`${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
2020-07-16 07:53:03 +00:00
fi
fi
if [ -n "$ERROR" ]; then
exit 1
fi