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

feat: lighthouse ci pipeline #155

Open
wants to merge 46 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
f5946fb
feat: lighthouse ci pipeline
khareyash05 Dec 10, 2024
ec244c8
push main
khareyash05 Dec 10, 2024
2e93712
on every branch
khareyash05 Dec 10, 2024
740cf8c
on PR
khareyash05 Dec 10, 2024
fdae4fb
Merge branch 'main' into lighthouse-ci
khareyash05 Dec 10, 2024
cec2515
check lighthouse with config
khareyash05 Dec 10, 2024
467a570
remove reset assertions
khareyash05 Dec 10, 2024
57a155d
update lighthouse components
khareyash05 Dec 10, 2024
5132a65
add necessary global points for lighthouse
khareyash05 Dec 16, 2024
40ed80a
revert lighthouse changes
khareyash05 Dec 16, 2024
21e9830
setup default lighthouse ci
khareyash05 Dec 16, 2024
f9b354f
check for best practices
khareyash05 Dec 16, 2024
e9464cc
add step for keploy deploy lighthouse
khareyash05 Dec 16, 2024
c8fbe9c
check route
khareyash05 Dec 16, 2024
c4f6ab7
check with routing
khareyash05 Dec 16, 2024
2ac7dfd
npm run start
khareyash05 Dec 16, 2024
4c075fc
increase number of runs
khareyash05 Dec 16, 2024
ef98b3d
compare reports
khareyash05 Dec 16, 2024
be1c581
fix routes for scripts
khareyash05 Dec 16, 2024
595e7af
check path
khareyash05 Dec 16, 2024
02276bf
ls
khareyash05 Dec 16, 2024
f829801
check
khareyash05 Dec 16, 2024
19dda7a
uncomment and test script
khareyash05 Dec 16, 2024
61bdbde
check the path of peipleine
khareyash05 Dec 16, 2024
c2e9445
decrease critical values for report upload
khareyash05 Dec 16, 2024
ef7d1b3
update page for reports
khareyash05 Dec 16, 2024
853bfb5
decrease performance metric
khareyash05 Dec 16, 2024
7ec32de
fix routing
khareyash05 Dec 16, 2024
bfef475
decrease value for test
khareyash05 Dec 16, 2024
96f003e
check
khareyash05 Dec 16, 2024
f4f81c4
pwd
khareyash05 Dec 16, 2024
648a010
make script inside
khareyash05 Dec 16, 2024
7cbead1
uncomment
khareyash05 Dec 16, 2024
3ae28f9
run and check
khareyash05 Dec 16, 2024
14feedc
pwd and ls
khareyash05 Dec 16, 2024
9c31b4d
check check
khareyash05 Dec 16, 2024
cc58229
run global routes
khareyash05 Dec 16, 2024
f5d1644
remove latest run file
khareyash05 Dec 16, 2024
9d071ff
find all file with ending report
khareyash05 Dec 16, 2024
983fceb
best practices
khareyash05 Dec 16, 2024
e280237
remove extra comments
khareyash05 Dec 16, 2024
c9c0259
Merge branch 'main' into lighthouse-ci
khareyash05 Dec 16, 2024
bad8f57
increase iteration to 10
khareyash05 Dec 16, 2024
4d4cdf2
make single json
khareyash05 Dec 16, 2024
cf8edf8
yaml
khareyash05 Dec 16, 2024
82b89c3
Merge branch 'main' into lighthouse-ci
khareyash05 Dec 24, 2024
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
30 changes: 30 additions & 0 deletions .github/workflows/lighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: CI
on:
pull_request:
branches:
- "**"
jobs:
lhci:
name: Lighthouse
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 18.x
- name: Install dependencies
run: |
npm install
npm run build
- name: run Lighthouse CI for the Application
run: |
npm install -g @lhci/[email protected]
lhci autorun --config=lighthouserc.json --collect.url="http://localhost:3000" --collect.startServerCommand="npm run start" --upload.outputDir="./lhci-reports/app"
- name: run Lighthouse CI for Keploy.io Deployed Website
run: |
npm install -g @lhci/[email protected]
lhci autorun --config=lighthouserc.json --collect.url="https://www.keploy.io" --upload.outputDir="./lhci-reports/keploy.io"
- name: Compare Lighthouse Reports
run: |
node compare-lhci-reports.js
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,5 @@ next-env.d.ts


.early.coverage

.lighthouseci
54 changes: 54 additions & 0 deletions compare-lhci-reports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const fs = require('fs');
const path = require('path');

function findReportFile(directory) {
if (!fs.existsSync(directory)) {
console.error(`Directory not found: ${directory}`);
process.exit(1);
}
const files = fs.readdirSync(directory);
const reportFile = files.find(file => file.endsWith('.report.json'));
if (!reportFile) {
console.error(`No report file found in directory: ${directory}`);
process.exit(1);
}
return path.join(directory, reportFile);
}

function loadReport(path) {
if (!fs.existsSync(path)) {
console.error(`Report not found at path: ${path}`);
process.exit(1);
}
const data = fs.readFileSync(path, 'utf8');
return JSON.parse(data);
}

const appReportDirectory = './lhci-reports/app';
const keployReportDirectory = './lhci-reports/keploy.io';

const appReportPath = findReportFile(appReportDirectory);
const keployReportPath = findReportFile(keployReportDirectory);

const appReport = loadReport(appReportPath);
const keployReport = loadReport(keployReportPath);

const categories = ['performance', 'accessibility', 'seo'];

let allPass = true;

categories.forEach(category => {
const appScore = appReport.categories[category].score;
const keployScore = keployReport.categories[category].score;
if (appScore < keployScore) {
console.error(`Score for ${category} is lower in the application (${appScore}) than Keploy.io (${keployScore})`);
allPass = false;
}
});

if (!allPass) {
console.error('Lighthouse scores are lower than the baseline. Failing the CI job.');
process.exit(1);
} else {
console.log('All Lighthouse scores are equal or better than the baseline.');
}
19 changes: 19 additions & 0 deletions lighthouserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"ci": {
"upload": {
"target": "filesystem"
},
"collect": {
"numberOfRuns": 10
},
"assert": {
"assertions": {
"categories:performance": ["error", {"minScore": 0.1}],
"categories:accessibility": ["error", {"minScore": 0.1}],
"categories:best-practices": ["error", {"minScore": 0.1}],
"categories:seo": ["error", {"minScore": 0.8}],
"csp-xss": "warn"
}
}
}
}
Loading