Skip to content

Commit d7c8ef4

Browse files
committed
Initial commit
0 parents  commit d7c8ef4

5 files changed

Lines changed: 8066 additions & 0 deletions

File tree

.github/workflows/report.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Lighthouse report
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
workflow_dispatch:
7+
8+
jobs:
9+
lighthouse-check:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout the repository
13+
uses: actions/checkout@main
14+
15+
- name: Checkout the reports branch
16+
run: |
17+
git fetch --all
18+
git checkout origin/reports
19+
20+
- name: Create temporary directories
21+
run: |
22+
test -f ./reports.json || touch ./reports.json
23+
mkdir -p /tmp/artifacts ./reports
24+
25+
- name: Generate the report
26+
uses: foo-software/lighthouse-check-action@master
27+
with:
28+
author: ${{ github.actor }}
29+
outputDirectory: /tmp/artifacts
30+
urls: https://helpfulengineering.org
31+
emulatedFormFactor: desktop
32+
33+
- name: Process the report results
34+
id: results
35+
run: |
36+
echo "::set-output name=accessibility::$(jq -r .[0].scores.accessibility < /tmp/artifacts/results.json)"
37+
echo "::set-output name=bestPractices::$(jq -r .[0].scores.bestPractices < /tmp/artifacts/results.json)"
38+
echo "::set-output name=performance::$(jq -r .[0].scores.performance < /tmp/artifacts/results.json)"
39+
echo "::set-output name=progressiveWebApp::$(jq -r .[0].scores.progressiveWebApp < /tmp/artifacts/results.json)"
40+
echo "::set-output name=seo::$(jq -r .[0].scores.seo < /tmp/artifacts/results.json)"
41+
jq -s '.[0] + .[1]' reports.json /tmp/artifacts/results.json > /tmp/artifacts/mix.json
42+
mv /tmp/artifacts/mix.json reports.json
43+
44+
base="$(basename "$(jq -r .[0].localReport < /tmp/artifacts/results.json)")"
45+
time="$(grep -o '[0-9]' <<< "${base%.json.gz}" | tr -d '\n')"
46+
echo "::set-output name=time::$time"
47+
48+
for report in /tmp/artifacts/*.html; do
49+
base="$(basename "$report")"; name="${base%.html}"; time="${name/lighthouse-report-}"
50+
perl -ne '/<script>window.__LIGHTHOUSE_JSON__ = (.*);<\/script>/ and print $1' "$report" |
51+
gzip > "/tmp/artifacts/$time.json.gz"
52+
done
53+
54+
find /tmp/artifacts/*.json.gz | while read report; do
55+
base="$(basename "$report")"
56+
time="$(grep -o '[0-9]' <<< "${base%.json.gz}" | tr -d '\n')"
57+
cat "$report" | gunzip | jq "{\"$time\": {\"address\": .requestedUrl, \"seconds\": (.audits.interactive.numericValue / 1000) | floor}}"
58+
done | jq -s add > /tmp/artifacts/data.json
59+
60+
test -f data.json || echo "{}" > data.json
61+
jq -s '.[0] + .[1]' data.json /tmp/artifacts/data.json > /tmp/artifacts/mix.json
62+
mv /tmp/artifacts/mix.json data.json
63+
64+
cp /tmp/artifacts/*.json.gz reports
65+
66+
- name: Commit the report results
67+
uses: EndBug/add-and-commit@v4
68+
with:
69+
add: "*.json reports"
70+
ref: reports
71+
message: Add reports
72+
author_name: "GitHub Actions"
73+
author_email: "actions@github.com"
74+
env:
75+
GITHUB_TOKEN: ${{ github.token }}
76+
77+
- name: Retrieve the report results
78+
run: |
79+
rm -rf * || true
80+
git checkout origin/reports -- "./reports" "./reports.json" "./data.json"
81+
git checkout origin/main -- "./pages/*"
82+
mv ./pages/* . && rmdir ./pages
83+
84+
- name: Publish the report results
85+
uses: peaceiris/actions-gh-pages@v3
86+
with:
87+
github_token: ${{ github.token }}
88+
force_orphan: true
89+
publish_branch: pages
90+
publish_dir: .
91+
92+
- name: Send the reports to Slack
93+
uses: rtCamp/action-slack-notify@v2.1.0
94+
env:
95+
SLACK_CHANNEL: devops
96+
SLACK_COLOR: good
97+
SLACK_ICON: https://developers.google.com/web/tools/lighthouse/images/lighthouse-logo.svg
98+
SLACK_MESSAGE: |
99+
Accessibility: ${{ steps.results.outputs.accessibility }}%
100+
Best practices: ${{ steps.results.outputs.bestPractices }}%
101+
Performance: ${{ steps.results.outputs.performance }}%
102+
Progressive web application: ${{ steps.results.outputs.progressiveWebApp }}%
103+
Search engine optimization: ${{ steps.results.outputs.seo }}%
104+
:book: <https://helpfulengineering.github.io/lighthouse/report.html?time=${{ steps.results.outputs.time }}|*Read the full report*>
105+
SLACK_FOOTER: |
106+
<https://github.com/helpfulengineering/lighthouse/blob/master/.github/workflows/report.yml|Click here to modify this bot.>
107+
SLACK_TITLE: Metrics for helpfulengineering.org
108+
SLACK_USERNAME: Lighthouse
109+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
110+
MSG_MINIMAL: true

0 commit comments

Comments
 (0)