diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index f823d4b6..8c806699 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -414,8 +414,8 @@ jobs: runs-on: docker container: image: catthehacker/ubuntu:act-latest - outputs: - report_url: ${{ steps.save.outputs.report_url }} + # outputs: + # report_url: ${{ steps.save.outputs.report_url }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -498,15 +498,7 @@ jobs: CHROME_PATH: /usr/bin/chromium 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 @@ -534,14 +526,9 @@ jobs: - name: šŸ”” Gotify - Success if: needs.deploy.result == 'success' 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 }}" \ -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 - name: šŸ”” Gotify - Failure diff --git a/lighthouserc.js b/lighthouserc.js index 2d361c3a..70238c83 100644 --- a/lighthouserc.js +++ b/lighthouserc.js @@ -1,22 +1,19 @@ module.exports = { - ci: { - collect: { - numberOfRuns: 1, - settings: { - preset: 'desktop', - 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', - }, + ci: { + collect: { + numberOfRuns: 1, + settings: { + preset: 'desktop', + 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 }], + }, + }, + }, }; diff --git a/scripts/pagespeed-sitemap.ts b/scripts/pagespeed-sitemap.ts index b52afebd..4000be43 100644 --- a/scripts/pagespeed-sitemap.ts +++ b/scripts/pagespeed-sitemap.ts @@ -79,33 +79,67 @@ async function main() { const chromePath = process.env.CHROME_PATH || process.env.PUPPETEER_EXECUTABLE_PATH; 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 - 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...`); try { - const output = execSync(lhciCommand, { + execSync(lhciCommand, { 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 - const reportMatch = output.match( - /Sent to (https:\/\/storage\.googleapis\.com\/lighthouse-infrastructure\.appspot\.com\/reports\/[^\s]+)/, - ); - if (reportMatch && reportMatch[1]) { - const reportUrl = reportMatch[1]; - console.log(`\nšŸ“Š Report URL: ${reportUrl}`); - fs.writeFileSync('pagespeed-report-url.txt', reportUrl); - } - } catch (err: any) { - console.error('āŒ LHCI execution failed.'); - if (err.stdout) console.log(err.stdout); - if (err.stderr) console.error(err.stderr); - throw err; + // Calculate Average + const avg = { + Perf: Math.round( + summaryTable.reduce((acc: any, curr: any) => acc + curr.Perf, 0) / summaryTable.length, + ), + Acc: Math.round( + summaryTable.reduce((acc: any, curr: any) => acc + curr.Acc, 0) / summaryTable.length, + ), + BP: Math.round( + summaryTable.reduce((acc: any, curr: any) => acc + curr.BP, 0) / summaryTable.length, + ), + SEO: Math.round( + summaryTable.reduce((acc: any, curr: any) => acc + curr.SEO, 0) / summaryTable.length, + ), + }; + + 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!`);