Lighthouse #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Lighthouse | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 0 * * *" | |
jobs: | |
lhci: | |
name: Lighthouse | |
runs-on: ubuntu-latest | |
steps: | |
- name: checkout | |
uses: actions/checkout@v4 | |
- name: setup-node | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 20 | |
- name: install Lighthouse | |
run: | | |
npm install -g lighthouse hjson | |
- name: install chrome | |
run: | | |
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb | |
sudo apt install ./google-chrome-stable_current_amd64.deb | |
- name: run Lighthouse | |
run: | | |
lighthouse https://walnuts.dev/ --chrome-flags="--headless" --output json --enable-error-reporting > lighthouse.json | |
- name: extract score | |
run: | | |
cat lighthouse.json |sed -e "/nodeLabel/D" |hjson -j | jq "[.categories[] |{(.id): .score}]| add" > score.json | |
- name: rewrite README.md | |
run: | | |
sed -i -e "s#https://img.shields.io/badge/Performance-.*25-green.svg#https://img.shields.io/badge/Performance-$(cat score.json |jq -r '.performance'| awk '$0=$0*100"%"')25-green.svg#g" README.md | |
sed -i -e "s#https://img.shields.io/badge/Accessibility-.*25-green.svg#https://img.shields.io/badge/Accessibility-$(cat score.json |jq -r '.accessibility'| awk '$0=$0*100"%"')25-green.svg#g" README.md | |
sed -i -e "s#https://img.shields.io/badge/Best%20Practices-.*25-green.svg#https://img.shields.io/badge/Best%20Practices-$(cat score.json |jq -r '."best-practices"'| awk '$0=$0*100"%"')25-green.svg#g" README.md | |
sed -i -e "s#https://img.shields.io/badge/SEO-.*25-green.svg#https://img.shields.io/badge/SEO-$(cat score.json |jq -r '.seo'| awk '$0=$0*100"%"')25-green.svg#g" README.md | |
- name: push | |
run: | | |
git config user.name "github-actions[bot]" | |
git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
git add README.md | |
git commit -m "update README.md" | |
git pull | |
git push --set-upstream origin main |