Skip to content

Commit

Permalink
Output results to a unique filename based on URL (fixes #7)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejarvis committed Sep 17, 2019
1 parent 9fc992d commit 9a63c5d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LABEL "com.github.actions.description"="Run tests on a webpage via Google's Ligh
LABEL "com.github.actions.icon"="check-square"
LABEL "com.github.actions.color"="yellow"

LABEL version="0.2.2"
LABEL version="0.3.0"
LABEL repository="https://github.com/jakejarvis/lighthouse-action"
LABEL homepage="https://jarv.is/"
LABEL maintainer="Jake Jarvis <jake@jarv.is>"
Expand Down
23 changes: 11 additions & 12 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,22 @@

set -e

# Check if we're being triggered by a pull request
# Check if we're being triggered by a pull request.
PULL_REQUEST_NUMBER=$(jq .number "$GITHUB_EVENT_PATH")

# If this is a PR and Netlify is configured, plan to check the deploy preview and generate its unique URL.
# Otherwise, simply check the plain URL.
# Otherwise, simply check the provided live URL.
if [ -n "$INPUT_NETLIFY_SITE" ] && [ -n "$PULL_REQUEST_NUMBER" ] && [ "$PULL_REQUEST_NUMBER" != "null" ]; then
REPORT_URL="https://deploy-preview-${PULL_REQUEST_NUMBER}--${INPUT_NETLIFY_SITE}"
else
REPORT_URL=${INPUT_URL}
fi

# Prepare directory for audit results.
# TODO: Name files after the tested URL to allow multiple tests.
# Right now, a second test would overwrite the first results.
# Prepare directory for audit results and sanitize URL to a valid and unique filename.
OUTPUT_FOLDER="report"
OUTPUT_PATH="$OUTPUT_FOLDER/lighthouse"
mkdir $OUTPUT_FOLDER
OUTPUT_FILENAME=$(echo "$REPORT_URL" | sed 's/[^a-zA-Z0-9]/_/g')
OUTPUT_PATH="./$OUTPUT_FOLDER/$OUTPUT_FILENAME"
mkdir "$OUTPUT_FOLDER"

# Clarify in logs which URL we're auditing.
printf "* Beginning audit of %s ...\n\n" "$REPORT_URL"
Expand All @@ -28,11 +27,11 @@ lighthouse --port=9222 --chrome-flags="--headless --disable-gpu --no-sandbox --n

# Parse individual scores from JSON output.
# Unorthodox jq syntax because of dashes -- https://github.com/stedolan/jq/issues/38
SCORE_PERFORMANCE=$(jq '.categories["performance"].score' ./report/lighthouse.report.json)
SCORE_ACCESSIBILITY=$(jq '.categories["accessibility"].score' ./report/lighthouse.report.json)
SCORE_PRACTICES=$(jq '.categories["best-practices"].score' ./report/lighthouse.report.json)
SCORE_SEO=$(jq '.categories["seo"].score' ./report/lighthouse.report.json)
SCORE_PWA=$(jq '.categories["pwa"].score' ./report/lighthouse.report.json)
SCORE_PERFORMANCE=$(jq '.categories["performance"].score' "$OUTPUT_PATH".report.json)
SCORE_ACCESSIBILITY=$(jq '.categories["accessibility"].score' "$OUTPUT_PATH".report.json)
SCORE_PRACTICES=$(jq '.categories["best-practices"].score' "$OUTPUT_PATH".report.json)
SCORE_SEO=$(jq '.categories["seo"].score' "$OUTPUT_PATH".report.json)
SCORE_PWA=$(jq '.categories["pwa"].score' "$OUTPUT_PATH".report.json)

# Print scores to standard output (0 to 100 instead of 0 to 1).
# Using hacky bc b/c bash hates floating point arithmetic...
Expand Down

0 comments on commit 9a63c5d

Please sign in to comment.