feat: Disable Lighthouse CI report uploading and generate a local summary table of PageSpeed scores instead.
This commit is contained in:
@@ -414,8 +414,8 @@ jobs:
|
|||||||
runs-on: docker
|
runs-on: docker
|
||||||
container:
|
container:
|
||||||
image: catthehacker/ubuntu:act-latest
|
image: catthehacker/ubuntu:act-latest
|
||||||
outputs:
|
# outputs:
|
||||||
report_url: ${{ steps.save.outputs.report_url }}
|
# report_url: ${{ steps.save.outputs.report_url }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
@@ -498,15 +498,7 @@ jobs:
|
|||||||
CHROME_PATH: /usr/bin/chromium
|
CHROME_PATH: /usr/bin/chromium
|
||||||
run: npm run pagespeed:test
|
run: npm run pagespeed:test
|
||||||
|
|
||||||
- name: 💾 Save Report URL
|
|
||||||
id: save
|
|
||||||
if: always()
|
|
||||||
run: |
|
|
||||||
if [ -f pagespeed-report-url.txt ]; then
|
|
||||||
URL=$(cat pagespeed-report-url.txt)
|
|
||||||
echo "report_url=$URL" >> $GITHUB_OUTPUT
|
|
||||||
echo "✅ Report URL found: $URL"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# ──────────────────────────────────────────────────────────────────────────────
|
# ──────────────────────────────────────────────────────────────────────────────
|
||||||
# JOB 6: Notifications
|
# JOB 6: Notifications
|
||||||
@@ -534,14 +526,9 @@ jobs:
|
|||||||
- name: 🔔 Gotify - Success
|
- name: 🔔 Gotify - Success
|
||||||
if: needs.deploy.result == 'success'
|
if: needs.deploy.result == 'success'
|
||||||
run: |
|
run: |
|
||||||
REPORT_MSG=""
|
|
||||||
if [ -n "${{ needs.pagespeed.outputs.report_url }}" ]; then
|
|
||||||
REPORT_MSG="\n\n⚡ **PageSpeed Report:**\n${{ needs.pagespeed.outputs.report_url }}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
curl -s -k -X POST "${{ secrets.GOTIFY_URL }}/message?token=${{ secrets.GOTIFY_TOKEN }}" \
|
curl -s -k -X POST "${{ secrets.GOTIFY_URL }}/message?token=${{ secrets.GOTIFY_TOKEN }}" \
|
||||||
-F "title=${{ needs.prepare.outputs.gotify_title }}" \
|
-F "title=${{ needs.prepare.outputs.gotify_title }}" \
|
||||||
-F "message=Erfolgreich deployt auf **${{ needs.prepare.outputs.target }}**\n\nVersion: **${{ needs.prepare.outputs.image_tag }}**\nCommit: ${{ needs.prepare.outputs.short_sha }} (${{ needs.prepare.outputs.commit_msg }})\nVon: ${{ github.actor }}\nRun: ${{ github.run_id }}${REPORT_MSG}" \
|
-F "message=Erfolgreich deployt auf **${{ needs.prepare.outputs.target }}**\n\nVersion: **${{ needs.prepare.outputs.image_tag }}**\nCommit: ${{ needs.prepare.outputs.short_sha }} (${{ needs.prepare.outputs.commit_msg }})\nVon: ${{ github.actor }}\nRun: ${{ github.run_id }}" \
|
||||||
-F "priority=4" || true
|
-F "priority=4" || true
|
||||||
|
|
||||||
- name: 🔔 Gotify - Failure
|
- name: 🔔 Gotify - Failure
|
||||||
|
|||||||
@@ -1,22 +1,19 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
ci: {
|
ci: {
|
||||||
collect: {
|
collect: {
|
||||||
numberOfRuns: 1,
|
numberOfRuns: 1,
|
||||||
settings: {
|
settings: {
|
||||||
preset: 'desktop',
|
preset: 'desktop',
|
||||||
onlyCategories: ['performance', 'accessibility', 'best-practices', 'seo'],
|
onlyCategories: ['performance', 'accessibility', 'best-practices', 'seo'],
|
||||||
},
|
},
|
||||||
},
|
|
||||||
assert: {
|
|
||||||
assertions: {
|
|
||||||
'categories:performance': ['warn', { minScore: 0.9 }],
|
|
||||||
'categories:accessibility': ['warn', { minScore: 0.9 }],
|
|
||||||
'categories:best-practices': ['warn', { minScore: 0.9 }],
|
|
||||||
'categories:seo': ['warn', { minScore: 0.9 }],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
upload: {
|
|
||||||
target: 'temporary-public-storage',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
assert: {
|
||||||
|
assertions: {
|
||||||
|
'categories:performance': ['warn', { minScore: 0.9 }],
|
||||||
|
'categories:accessibility': ['warn', { minScore: 0.9 }],
|
||||||
|
'categories:best-practices': ['warn', { minScore: 0.9 }],
|
||||||
|
'categories:seo': ['warn', { minScore: 0.9 }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -79,33 +79,67 @@ async function main() {
|
|||||||
const chromePath = process.env.CHROME_PATH || process.env.PUPPETEER_EXECUTABLE_PATH;
|
const chromePath = process.env.CHROME_PATH || process.env.PUPPETEER_EXECUTABLE_PATH;
|
||||||
const chromePathArg = chromePath ? `--collect.chromePath="${chromePath}"` : '';
|
const chromePathArg = chromePath ? `--collect.chromePath="${chromePath}"` : '';
|
||||||
|
|
||||||
|
// Clean up old reports
|
||||||
|
if (fs.existsSync('.lighthouseci')) {
|
||||||
|
fs.rmSync('.lighthouseci', { recursive: true, force: true });
|
||||||
|
}
|
||||||
|
|
||||||
// Using a more robust way to execute and capture output
|
// Using a more robust way to execute and capture output
|
||||||
const lhciCommand = `npx lhci collect ${urlArgs} ${chromePathArg} --collect.settings.chromeFlags='--no-sandbox --disable-setuid-sandbox' --collect.settings.extraHeaders='${extraHeaders}' && npx lhci assert && npx lhci upload`;
|
// We remove 'npx lhci upload' to keep everything local and avoid Google-hosted reports
|
||||||
|
const lhciCommand = `npx lhci collect ${urlArgs} ${chromePathArg} --collect.settings.chromeFlags='--no-sandbox --disable-setuid-sandbox' --collect.settings.extraHeaders='${extraHeaders}' && npx lhci assert`;
|
||||||
|
|
||||||
console.log(`💻 Executing LHCI...`);
|
console.log(`💻 Executing LHCI...`);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const output = execSync(lhciCommand, {
|
execSync(lhciCommand, {
|
||||||
encoding: 'utf8',
|
encoding: 'utf8',
|
||||||
stdio: ['inherit', 'pipe', 'inherit'], // Pipe stdout so we can parse it
|
stdio: 'inherit',
|
||||||
|
});
|
||||||
|
} catch (err: any) {
|
||||||
|
console.warn('⚠️ LHCI assertion finished with warnings or errors.');
|
||||||
|
// We continue to show the table even if assertions failed
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Summarize Results (Local & Independent)
|
||||||
|
const manifestPath = path.join(process.cwd(), '.lighthouseci', 'manifest.json');
|
||||||
|
if (fs.existsSync(manifestPath)) {
|
||||||
|
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
||||||
|
console.log(`\n📊 PageSpeed Summary (FOSS - Local Report):\n`);
|
||||||
|
|
||||||
|
const summaryTable = manifest.map((entry: any) => {
|
||||||
|
const s = entry.summary;
|
||||||
|
return {
|
||||||
|
URL: entry.url.replace(targetUrl, ''),
|
||||||
|
Perf: Math.round(s.performance * 100),
|
||||||
|
Acc: Math.round(s.accessibility * 100),
|
||||||
|
BP: Math.round(s['best-practices'] * 100),
|
||||||
|
SEO: Math.round(s.seo * 100),
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(output);
|
console.table(summaryTable);
|
||||||
|
|
||||||
// Extract report URL from LHCI output
|
// Calculate Average
|
||||||
const reportMatch = output.match(
|
const avg = {
|
||||||
/Sent to (https:\/\/storage\.googleapis\.com\/lighthouse-infrastructure\.appspot\.com\/reports\/[^\s]+)/,
|
Perf: Math.round(
|
||||||
);
|
summaryTable.reduce((acc: any, curr: any) => acc + curr.Perf, 0) / summaryTable.length,
|
||||||
if (reportMatch && reportMatch[1]) {
|
),
|
||||||
const reportUrl = reportMatch[1];
|
Acc: Math.round(
|
||||||
console.log(`\n📊 Report URL: ${reportUrl}`);
|
summaryTable.reduce((acc: any, curr: any) => acc + curr.Acc, 0) / summaryTable.length,
|
||||||
fs.writeFileSync('pagespeed-report-url.txt', reportUrl);
|
),
|
||||||
}
|
BP: Math.round(
|
||||||
} catch (err: any) {
|
summaryTable.reduce((acc: any, curr: any) => acc + curr.BP, 0) / summaryTable.length,
|
||||||
console.error('❌ LHCI execution failed.');
|
),
|
||||||
if (err.stdout) console.log(err.stdout);
|
SEO: Math.round(
|
||||||
if (err.stderr) console.error(err.stderr);
|
summaryTable.reduce((acc: any, curr: any) => acc + curr.SEO, 0) / summaryTable.length,
|
||||||
throw err;
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
console.log(`\n📈 Average Scores:`);
|
||||||
|
console.log(` Performance: ${avg.Perf > 90 ? '✅' : '⚠️'} ${avg.Perf}`);
|
||||||
|
console.log(` Accessibility: ${avg.Acc > 90 ? '✅' : '⚠️'} ${avg.Acc}`);
|
||||||
|
console.log(` Best Practices: ${avg.BP > 90 ? '✅' : '⚠️'} ${avg.BP}`);
|
||||||
|
console.log(` SEO: ${avg.SEO > 90 ? '✅' : '⚠️'} ${avg.SEO}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`\n✨ PageSpeed tests completed successfully!`);
|
console.log(`\n✨ PageSpeed tests completed successfully!`);
|
||||||
|
|||||||
Reference in New Issue
Block a user