|
28 | 28 | run: lhci autorun
|
29 | 29 | env:
|
30 | 30 | LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}
|
| 31 | + |
| 32 | + - name: Format lighthouse score |
| 33 | + id: format_lighthouse_score |
| 34 | + uses: actions/github-script@v3 |
| 35 | + with: |
| 36 | + github-token: ${{secrets.GITHUB_TOKEN}} |
| 37 | + script: | |
| 38 | +
|
| 39 | + const fs = require('fs'); |
| 40 | + const results = JSON.parse(fs.readFileSync("./lhci_reports/manifest.json")); |
| 41 | + let comments = ""; |
| 42 | +
|
| 43 | + results.forEach((result,index) => { |
| 44 | + const { summary } = result; |
| 45 | +
|
| 46 | + const formatResult = (res) => Math.round(res * 100); |
| 47 | +
|
| 48 | + Object.keys(summary).forEach( |
| 49 | + (key) => (summary[key] = formatResult(summary[key])) |
| 50 | + ); |
| 51 | +
|
| 52 | + const score = (res) => (res >= 90 ? "🟢" : res >= 70 ? "🟠" : "🔴"); |
| 53 | +
|
| 54 | + const comment = [ |
| 55 | + `⚡️ Lighthouse report ${index}`, |
| 56 | + `| Category | Score |`, |
| 57 | + `| --- | --- |`, |
| 58 | + `| ${score(summary.performance)} Performance | ${summary.performance} |`, |
| 59 | + `| ${score(summary.accessibility)} Accessibility | ${summary.accessibility} |`, |
| 60 | + `| ${score(summary['best-practices'])} Best practices | ${summary['best-practices']} |`, |
| 61 | + `| ${score(summary.seo)} SEO | ${summary.seo} |`, |
| 62 | + `| ${score(summary.pwa)} PWA | ${summary.pwa} |`, |
| 63 | + `\n`, |
| 64 | + ].join("\n"); |
| 65 | +
|
| 66 | + comments += comment + "\n"; |
| 67 | + }); |
| 68 | +
|
| 69 | + core.setOutput('comments', comments) |
| 70 | +
|
| 71 | + - name: comment PR |
| 72 | + |
| 73 | + env: |
| 74 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 75 | + with: |
| 76 | + msg: ${{ steps.format_lighthouse_score.outputs.comments}} |
0 commit comments