Skip to content

Commit

Permalink
Improve log output -- print full path of results files in container
Browse files Browse the repository at this point in the history
  • Loading branch information
jakejarvis committed Sep 17, 2019
1 parent 9a63c5d commit a3bcc99
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 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.3.0"
LABEL version="0.3.2"
LABEL repository="https://github.com/jakejarvis/lighthouse-action"
LABEL homepage="https://jarv.is/"
LABEL maintainer="Jake Jarvis <[email protected]>"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
This action integrates Google's helpful [Lighthouse audits](https://developers.google.com/web/tools/lighthouse/) for webpages — specifically testing for Performance, Accessibility, Best Practices, SEO, and Progressive Web Apps. Right now, the action will print the five scores (out of 100) to the output and upload HTML and JSON versions of the report as artifacts. In the next release, the action will let you specify thresholds for each test and optionally fail this step if they are not met.

<p align="center"><img src="https://raw.githubusercontent.com/jakejarvis/lighthouse-action/master/screenshots/screenshot-report.png" alt="Example HTML report"></p>
<p align="center"><img src="https://raw.githubusercontent.com/jakejarvis/lighthouse-action/master/screenshots/screenshot-output.png" alt="Example command line output"></p>
<p align="center"><img src="https://raw.githubusercontent.com/jakejarvis/lighthouse-action/master/screenshots/screenshot-output.png" alt="Example command line output" width="750"></p>
<p align="center"><img src="https://raw.githubusercontent.com/jakejarvis/lighthouse-action/master/screenshots/screenshot-artifact.png" alt="Example HTML report" width="320"></p>

Inspired by [GoogleChromeLabs/lighthousebot](https://github.com/GoogleChromeLabs/lighthousebot).
Expand Down
19 changes: 11 additions & 8 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@ 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 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}"
REPORT_URL="https://deploy-preview-$PULL_REQUEST_NUMBER--$INPUT_NETLIFY_SITE"
else
REPORT_URL=${INPUT_URL}
REPORT_URL=$INPUT_URL
fi

# Prepare directory for audit results and sanitize URL to a valid and unique filename.
OUTPUT_FOLDER="report"
# shellcheck disable=SC2001
OUTPUT_FILENAME=$(echo "$REPORT_URL" | sed 's/[^a-zA-Z0-9]/_/g')
OUTPUT_PATH="./$OUTPUT_FOLDER/$OUTPUT_FILENAME"
mkdir "$OUTPUT_FOLDER"
OUTPUT_PATH="$GITHUB_WORKSPACE/$OUTPUT_FOLDER/$OUTPUT_FILENAME"
mkdir -p "$OUTPUT_FOLDER"

# Clarify in logs which URL we're auditing.
printf "* Beginning audit of %s ...\n\n" "$REPORT_URL"
Expand All @@ -35,14 +36,16 @@ 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...
printf "\n* Completed audit of %s !" "$REPORT_URL"
printf "\n* Scores are printed below and detailed results are saved in ./report\n\n"
printf "%s\n" "+-------------------------------+"
printf "\n* Completed audit of %s ! Scores are printed below:\n\n" "$REPORT_URL"
printf "+-------------------------------+\n"
printf "| Performance: %.0f\t|\n" "$(echo "$SCORE_PERFORMANCE*100" | bc -l)"
printf "| Accessibility: %.0f\t|\n" "$(echo "$SCORE_ACCESSIBILITY*100" | bc -l)"
printf "| Best Practices: %.0f\t|\n" "$(echo "$SCORE_PRACTICES*100" | bc -l)"
printf "| SEO: %.0f\t|\n" "$(echo "$SCORE_SEO*100" | bc -l)"
printf "| Progressive Web App: %.0f\t|\n" "$(echo "$SCORE_PWA*100" | bc -l)"
printf "%s\n" "+-------------------------------+"
printf "+-------------------------------+\n\n"
printf "* Detailed results are saved here, use https://github.com/actions/upload-artifact to retrieve them:\n"
printf " %s\n" "$OUTPUT_PATH.report.html"
printf " %s\n" "$OUTPUT_PATH.report.json"

exit 0
Binary file modified screenshots/screenshot-output.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a3bcc99

Please sign in to comment.