-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Lighthouse CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
lighthouse: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: '16' | ||
|
||
- name: Install dependencies | ||
run: npm install | ||
|
||
- name: Run Lighthouse CI | ||
run: npx lhci autorun | ||
|
||
- name: Update README with Lighthouse scores | ||
run: node update-readme.js | ||
|
||
- name: Commit updated README | ||
run: | | ||
git config --global user.name "github-actions[bot]" | ||
git config --global user.email "github-actions[bot]@users.noreply.github.com" | ||
git add README.md | ||
git commit -m "Update Lighthouse scores" | ||
git push |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable no-undef */ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
// Path to the Lighthouse report | ||
const reportPath = path.join(__dirname, 'lhci-report', 'latest-report.json'); | ||
|
||
// Read the Lighthouse report JSON | ||
const getLighthouseReport = () => { | ||
const report = JSON.parse(fs.readFileSync(reportPath, 'utf-8')); | ||
return report; | ||
}; | ||
|
||
// Extract scores | ||
const extractScores = (report) => { | ||
const performance = report.categories.performance.score * 100; | ||
const accessibility = report.categories.accessibility.score * 100; | ||
const bestPractices = report.categories['best-practices'].score * 100; | ||
const seo = report.categories.seo.score * 100; | ||
const pwa = report.categories.pwa.score * 100; | ||
|
||
return { performance, accessibility, bestPractices, seo, pwa }; | ||
}; | ||
|
||
// Create a string with the scores | ||
const createScoreString = (scores) => { | ||
const { performance, accessibility, bestPractices, seo, pwa } = scores; | ||
return ` | ||
## Lighthouse Report (Page Speed Scores) | ||
- **Performance:** ${performance}/100 | ||
- **Accessibility:** ${accessibility}/100 | ||
- **Best Practices:** ${bestPractices}/100 | ||
- **SEO:** ${seo}/100 | ||
- **PWA:** ${pwa}/100 | ||
`; | ||
}; | ||
|
||
// Update the README with the new scores | ||
const updateReadme = (newScores) => { | ||
const readmePath = path.join(__dirname, 'README.md'); | ||
let readmeContent = fs.readFileSync(readmePath, 'utf-8'); | ||
|
||
// Replace the old Lighthouse section or append new one | ||
readmeContent = readmeContent.replace(/## Lighthouse Report.*/s, newScores); | ||
|
||
// Write the updated README back to the file | ||
fs.writeFileSync(readmePath, readmeContent); | ||
}; | ||
|
||
// Main function to run the process | ||
const main = () => { | ||
const report = getLighthouseReport(); | ||
const scores = extractScores(report); | ||
const scoresString = createScoreString(scores); | ||
updateReadme(scoresString); | ||
}; | ||
|
||
main(); |