Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lighthouse ci action #1401

Merged
merged 60 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
e475c54
Add Lighthouse-ci Action
tunetheweb Oct 31, 2020
40f9568
Make it run on this repo
tunetheweb Oct 31, 2020
abe8fa9
Fix config
tunetheweb Oct 31, 2020
1ab075c
Fix config
tunetheweb Oct 31, 2020
e2e7a4e
Fix typo
tunetheweb Oct 31, 2020
0c1f48f
Better Budgets
tunetheweb Oct 31, 2020
4d9c797
Revert temp changes for testing
tunetheweb Oct 31, 2020
2657be9
Fix YAML
tunetheweb Oct 31, 2020
7db18e0
Make list of URLs dynamic
tunetheweb Nov 1, 2020
864ea0c
Aloow testing on this repo
tunetheweb Nov 1, 2020
f448261
Linting errors
tunetheweb Nov 1, 2020
76a19ac
Bug fixes and linting errors
tunetheweb Nov 1, 2020
7885671
Bug fixes
tunetheweb Nov 1, 2020
1313ba3
Add production tests and fix bugs
tunetheweb Nov 1, 2020
c21b7c5
Linting fixes and outputs
tunetheweb Nov 1, 2020
38903e2
Linting fixes
tunetheweb Nov 1, 2020
b094428
Assert fixes
tunetheweb Nov 1, 2020
7d21800
Remove budgets to test assertions only
tunetheweb Nov 1, 2020
5059256
Remove budgets as prevent assertions working
tunetheweb Nov 1, 2020
898bd63
Switch from using localhost to fix errors
tunetheweb Nov 1, 2020
8d20507
Tidy up
tunetheweb Nov 1, 2020
0c3263d
Change production job to run at 13:45 on Sunday
tunetheweb Nov 1, 2020
d3485e2
Better formatting
tunetheweb Nov 1, 2020
ce53e24
Syntax fix
tunetheweb Nov 1, 2020
844f1b6
JQ syntax fix
tunetheweb Nov 1, 2020
5695c39
More jq fun
tunetheweb Nov 1, 2020
2922f45
Getting there with jq
tunetheweb Nov 1, 2020
b36b25d
Why is jq so annoying
tunetheweb Nov 1, 2020
f64573b
jq formatioing
tunetheweb Nov 1, 2020
451340a
JQ fixes
tunetheweb Nov 1, 2020
c4242fe
Tidy up
tunetheweb Nov 1, 2020
78f90ea
Better scores
tunetheweb Nov 1, 2020
9c831b5
Typo
tunetheweb Nov 1, 2020
3b87c9e
Version fixes
tunetheweb Nov 1, 2020
f46e484
Fix version numbers
tunetheweb Nov 1, 2020
32e103a
Correct Accessinility Issues in ES CSS chapter
tunetheweb Nov 1, 2020
7e7b674
Test run against production
tunetheweb Nov 1, 2020
b3b7ad5
Misc fixes
tunetheweb Nov 1, 2020
b4fabf6
Test run
tunetheweb Nov 1, 2020
7321403
Update set_lighthouse_urls.sh
tunetheweb Nov 1, 2020
0f67865
Update set_lighthouse_urls.sh
tunetheweb Nov 1, 2020
9366bbb
Fixes
tunetheweb Nov 1, 2020
9f44782
Better audits
tunetheweb Nov 1, 2020
986b01f
Better audits
tunetheweb Nov 1, 2020
0782192
Tweak audits
tunetheweb Nov 1, 2020
190d8c7
Testing
tunetheweb Nov 1, 2020
b5d14d9
Address tap issues
tunetheweb Nov 1, 2020
380e5c2
Improved git diff
tunetheweb Nov 1, 2020
86c5bfa
Diff
tunetheweb Nov 1, 2020
79f1d15
Better diff
tunetheweb Nov 1, 2020
afc118f
Better diffs
tunetheweb Nov 1, 2020
25bad97
Bug fixes
tunetheweb Nov 2, 2020
b9db6bc
Bug fix
tunetheweb Nov 2, 2020
ca50983
More exclusions
tunetheweb Nov 2, 2020
d64d9a9
Cleanup
tunetheweb Nov 2, 2020
0237c9f
Tidy up ready to open upstream
tunetheweb Nov 2, 2020
e8e830c
Merge branch 'main' into lighthouse-ci-action
tunetheweb Nov 3, 2020
2deae7f
Review feedback
tunetheweb Nov 3, 2020
5e65225
Move to jq for JSON manipulation
tunetheweb Nov 3, 2020
7e5686f
Linting fixes
tunetheweb Nov 3, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/lighthouse/lighthouse-config-dev.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"ci": {
"assert": {
"preset": "lighthouse:no-pwa",
"assertions": {
"bootup-time": "off",
"canonical": "off",
"dom-size": "off",
"first-contentful-paint": "off",
"first-cpu-idle": "off",
"first-meaningful-paint": "off",
"font-display": "off",
"interactive": "off",
"is-crawlable": "off",
"is-on-https:": "off",
"largest-contentful-paint": "off",
"mainthread-work-breakdown": "off",
"max-potential-fid": "off",
"speed-index": "off",
"render-blocking-resources": "off",
"unminified-css": "off",
"unminified-javascript": "off",
"unused-css-rules": "off",
"unused-javascript": "off",
"uses-long-cache-ttl": "off",
"uses-rel-preconnect": "off",
"uses-rel-preload": "off",
"uses-text-compression": "off",
"uses-responsive-images": "off",
"uses-webp-images": "off"
}
}
}
}
11 changes: 11 additions & 0 deletions .github/lighthouse/lighthouse-config-prod.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"ci": {
"assert": {
"assertions": {
"categories:accessibility": ["error", {"minScore": 1}],
"categories:best-practices": ["error", {"minScore": 1}],
"categories:seo": ["error", {"minScore": 1}]
}
}
}
}
40 changes: 40 additions & 0 deletions .github/workflows/production-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
######################################
## Custom Web Almanac GitHub action ##
######################################
#
# Run checks against the production website
#
name: Production Checks
on:
schedule:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12 or JAN-DEC)
# │ │ │ │ ┌───────────── day of the week (0 - 6 or SUN-SAT)
# │ │ │ │ │
# │ │ │ │ │
# │ │ │ │ │
# * * * * *
- cron: '45 13 * * 0'
workflow_dispatch:
jobs:
checks:
runs-on: ubuntu-latest
if: github.repository == 'HTTPArchive/almanac.httparchive.org'
steps:
- name: Set the list of URLs for Lighthouse to check
run: ./src/tools/scripts/set_lighthouse_urls.sh -p
- name: Audit URLs using Lighthouse
uses: treosh/lighthouse-ci-action@v3
id: LHCIAction
with:
# For prod, we simply check for 100% in Accessibility, Best Practices and SEO
# We don't check Performance as too much variability and no guarantees on perf in GitHub Actions.
configPath: .github/lighthouse/lighthouse-config-prod.json
uploadArtifacts: true # save results as an action artifacts
temporaryPublicStorage: true # upload lighthouse report to the temporary storage
- name: Show Lighthouse outputs
run: |
# All results by URL:
echo '${{ steps.LHCIAction.outputs.manifest }}' | jq -r '.[] | (.summary|tostring) + " - " + .url'
17 changes: 17 additions & 0 deletions .github/workflows/test_website.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,20 @@ jobs:
FILTER_REGEX_INCLUDE: src/static/html/.*
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VALIDATE_HTML: true
- name: Set the list of URLs for Lighthouse to check
env:
RUN_TYPE: ${{ github.event_name }}
COMMIT_SHA: ${{ github.sha }}
run: ./src/tools/scripts/set_lighthouse_urls.sh
- name: Audit URLs using Lighthouse
uses: treosh/lighthouse-ci-action@v3
id: LHCIAction
with:
# For dev, turn off all timing perf audits (too unreliable) and a few others that don't work on dev
configPath: .github/lighthouse/lighthouse-config-dev.json
uploadArtifacts: true # save results as an action artifacts
temporaryPublicStorage: true # upload lighthouse report to the temporary storage
- name: Show Lighthouse outputs
run: |
# All results by URL:
echo '${{ steps.LHCIAction.outputs.manifest }}' | jq -r '.[] | (.summary|tostring) + " - " + .url'
2 changes: 1 addition & 1 deletion src/content/es/2019/css.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Como era de esperar, en la Figura 2.5, `px` es el tipo de unidad más utilizado,

Cuando se trata de unidades basadas en el espacio físico, la unidad `cm` (or centímetros) es la más popular por mucho, seguida por `in` (pulgadas), y luego por `Q`.Sabemos que este tipo de unidades son específicamente útiles para imprimir hojas de estilo, ¡pero ni siquiera sabíamos que la unidad `Q` existía hasta esta encuesta! ¿Sabías?

<p class="note">Una versión anterior de este capítulo discutia la inesperada popularidad de la unidad<code>Q</code>. Gracias a la discusión de la comunidad <a href="https://discuss.httparchive.org/t/chapter-2-css/1757/6"></a> alrededor de este capítulo, hemos identificado que esto fue un error en nuestro análisis y hemos actualizado la Figura 2.5 en consecuencia.</p>
<p class="note">Una versión anterior de este capítulo discutia la inesperada popularidad de la unidad<code>Q</code>. Gracias a la <a href="https://discuss.httparchive.org/t/chapter-2-css/1757/6">discusión de la comunidad</a> alrededor de este capítulo, hemos identificado que esto fue un error en nuestro análisis y hemos actualizado la Figura 2.5 en consecuencia.</p>

### Unidades basadas en el viewport

Expand Down
4 changes: 4 additions & 0 deletions src/static/css/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,10 @@ figure .fig-desktop {
.anchor-link:focus::before {
content: '';
}

.content ul li {
padding: 5px 0;
}
}

/* Code highlighting */
Expand Down
87 changes: 87 additions & 0 deletions src/tools/scripts/set_lighthouse_urls.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/bin/bash

LIGHTHOUSE_CONFIG_FILE="../.github/lighthouse/lighthouse-config-dev.json"
LIGHTHOUSE_PROD_CONFIG_FILE="../.github/lighthouse/lighthouse-config-prod.json"

# Usage info
show_help() {
cat << EOH
Usage: ${0##*/} [-p]
Get a list of URLs to run a lighthouse test on.
If a commit is given then only URLs changes are tested otherwise all.

-h display this help and exit
-p get all production URLs from sitemap.xml
EOH
}

OPTIND=1 # Reseting is good practive
production=0
while getopts "h?p" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
p) production=1
;;
esac
done
shift "$((OPTIND-1))" # Discard the options and sentinel --

# This script must be run from src directory
if [ -d "src" ]; then
cd src || exit
fi

LIGHTHOUSE_URLS=""

# Set some URLs that should always be checked on pull requests
# to ensure basic coverage
BASE_URLS=$(cat <<-END
http://127.0.0.1:8080/en/2019/
http://127.0.0.1:8080/en/2019/javascript
http://127.0.0.1:8080/en/2020/
END
)

if [ "${production}" == "1" ]; then

# Get the production URLs from the production sitemap
LIGHTHOUSE_URLS=$(curl -s https://almanac.httparchive.org/sitemap.xml | grep "<loc" | grep -v "/static/" | sed 's/ *<loc>//g' | sed 's/<\/loc>//g')

# Switch to the Production Config file
LIGHTHOUSE_CONFIG_FILE="${LIGHTHOUSE_PROD_CONFIG_FILE}"

elif [ "${RUN_TYPE}" == "pull_request" ] && [ "${COMMIT_SHA}" != "" ]; then

# If this is part of pull request then get list of files as those changed
# Uses similar logic to GitHub Super Linter (https://github.com/github/super-linter/blob/master/lib/buildFileList.sh)
# First checkout main to get list of differences
git pull --quiet
git checkout main
# Then get the changes
CHANGED_FILES=$(git diff --name-only "main...${COMMIT_SHA}" --diff-filter=d content templates | grep -v base.html | grep -v ejs | grep -v base_ | grep -v toc.html | grep -v sitemap)
# Then back to the pull request changes
git checkout --progress --force "${COMMIT_SHA}"

# Transform the files to http://127.0.0.1:8080 URLs
LIGHTHOUSE_URLS=$(echo "${CHANGED_FILES}" | sed 's/src\/content/http:\/\/127.0.0.1:8080/g' | sed 's/\.md//g' | sed 's/\/base\//\/en\//g' | sed 's/src\/templates/http:\/\/127.0.0.1:8080/g' | sed 's/\.html//g' | sed 's/_/-/g' | sed 's/\/2019\/accessibility-statement/\/accessibility-statement/g' )

# Add base URLs and strip out newlines
LIGHTHOUSE_URLS=$(echo -e "${LIGHTHOUSE_URLS}\n${BASE_URLS}" | sed '/^$/d')

else

# Else test every URL (except PDFs) in the sitemap
LIGHTHOUSE_URLS=$(grep loc templates/sitemap.xml | grep -v "/static/" | sed 's/ *<loc>//g' | sed 's/<\/loc>//g' | sed 's/https:\/\/almanac.httparchive.org/http:\/\/127.0.0.1:8080/g')

fi

echo "URLS to check:"
echo "${LIGHTHOUSE_URLS}"

# Use jq to insert the URLs into the config file:
LIGHTHOUSE_CONFIG_WITH_URLS=$(echo "${LIGHTHOUSE_URLS}" | jq -Rs '. | split("\n") | map(select(length > 0))' | jq -s '.[0] * {ci: {collect: {url: .[1]}}}' "${LIGHTHOUSE_CONFIG_FILE}" -)

echo "${LIGHTHOUSE_CONFIG_WITH_URLS}" > "${LIGHTHOUSE_CONFIG_FILE}"