diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 4a24578..3af8493 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -50,11 +50,13 @@ jobs: id: format_lighthouse_score uses: actions/github-script@v3 with: - github-token: ${{secrets.GITHUB_TOKEN}} script: | const fs = require('fs'); - const results = JSON.parse(fs.readFileSync("${{ env.working-directory }}/lhci_reports/manifest.json")); - let comments = ""; + const path = require('path'); + const resultsPath = path.join(process.env.GITHUB_WORKSPACE, 'lhci_reports', 'manifest.json'); + + const results = JSON.parse(fs.readFileSync(resultsPath)); + let comments = "" results.forEach((result,index) => { const { summary } = result; @@ -64,20 +66,20 @@ jobs: Object.keys(summary).forEach( (key) => (summary[key] = formatResult(summary[key])) ); - + const score = (res) => (res >= 90 ? "🟢" : res >= 70 ? "🟠" : "🔴"); const comment = [ - `⚡️ Lighthouse report ${index}`, - `| Category | Score |`, - `| --- | --- |`, - `| ${score(summary.performance)} Performance | ${summary.performance} |`, - `| ${score(summary.accessibility)} Accessibility | ${summary.accessibility} |`, - `| ${score(summary['best-practices'])} Best practices | ${summary['best-practices']} |`, - `| ${score(summary.seo)} SEO | ${summary.seo} |`, - `| ${score(summary.pwa)} PWA | ${summary.pwa} |`, - `\n`, - ].join("\n"); + `⚡️ **Lighthouse report ${index + 1}**`, + `| Category | Score |`, + `|------------------------|-------|`, + `| ${score(summary.performance)} Performance | ${summary.performance} |`, + `| ${score(summary.accessibility)} Accessibility | ${summary.accessibility} |`, + `| ${score(summary['best-practices'])} Best practices | ${summary['best-practices']} |`, + `| ${score(summary.seo)} SEO | ${summary.seo} |`, + `| ${score(summary.pwa)} PWA | ${summary.pwa} |`, + `\n`, + ].join("\n"); comments += comment + "\n"; }); @@ -86,7 +88,5 @@ jobs: - name: comment PR uses: unsplash/comment-on-pr@v1.3.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - msg: ${{ steps.format_lighthouse_score.outputs.comments}} + msg: ${{ steps.format_lighthouse_score.outputs.comments }}