From ef98b3da4c1ca6685c1e7e0800847c038ac73232 Mon Sep 17 00:00:00 2001 From: Yash Khare Date: Mon, 16 Dec 2024 16:30:24 +0530 Subject: [PATCH] compare reports Signed-off-by: Yash Khare --- .github/workflows/lighthouse.yml | 5 ++++- compare-lhci-reports.js | 37 ++++++++++++++++++++++++++++++++ lighthouserc.json | 3 ++- lighthouserckeploy.json | 3 ++- 4 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 compare-lhci-reports.js diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 0fc85ff..b9da5d7 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -24,4 +24,7 @@ jobs: - name: run Lighthouse CI for Keploy.io Deployed Website run: | npm install -g @lhci/cli@0.14.x - lhci autorun --upload.target=temporary-public-storage --config=lighthouserckeploy.json || echo "LHCI failed!" \ No newline at end of file + lhci autorun --upload.target=temporary-public-storage --config=lighthouserckeploy.json || echo "LHCI failed!" + - name: Compare Lighthouse Reports + run: | + node scripts/compare-lhci-reports.js \ No newline at end of file diff --git a/compare-lhci-reports.js b/compare-lhci-reports.js new file mode 100644 index 0000000..a7bb9de --- /dev/null +++ b/compare-lhci-reports.js @@ -0,0 +1,37 @@ +const fs = require('fs'); + +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 appReportPath = './lhci-reports/app/latest-run/report.json'; +const keployReportPath = './lhci-reports/keploy.io/latest-run/report.json'; + +const appReport = loadReport(appReportPath); +const keployReport = loadReport(keployReportPath); + +const categories = ['performance', 'accessibility', 'best-practices', 'seo']; + +let allPass = true; + +categories.forEach(category => { + const appScore = appReport.categories[category].score; + const keployScore = keployReport.categories[category].score; + console.log(`Comparing ${category}: App=${appScore} vs Keploy.io=${keployScore}`); + 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.'); +} \ No newline at end of file diff --git a/lighthouserc.json b/lighthouserc.json index ccc5fd9..5245e93 100644 --- a/lighthouserc.json +++ b/lighthouserc.json @@ -1,7 +1,8 @@ { "ci": { "upload": { - "target": "temporary-public-storage" + "target": "filesystem", + "outputDir": "./lhci-reports/app" }, "collect": { "startServerCommand": "npm run start", diff --git a/lighthouserckeploy.json b/lighthouserckeploy.json index 9ac1f89..986c2ee 100644 --- a/lighthouserckeploy.json +++ b/lighthouserckeploy.json @@ -1,7 +1,8 @@ { "ci": { "upload": { - "target": "temporary-public-storage" + "target": "filesystem", + "outputDir": "./lhci-reports/keploy.io" }, "collect": { "url": [