diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml index 98f1f3ec..6c385e32 100644 --- a/.github/workflows/lighthouse.yml +++ b/.github/workflows/lighthouse.yml @@ -48,23 +48,29 @@ jobs: github-token: ${{secrets.GITHUB_TOKEN}} script: | const manifest = ${{ toJSON(steps.lighthouse_audit.outputs.manifest) }}; + const links = ${{ toJSON(steps.lighthouse_audit.outputs.links) }}; + + if (!manifest || Object.keys(manifest).length === 0) { + core.setFailed('Lighthouse audit did not generate any results.'); + return; + } const formatResult = (res) => Math.round((res * 100)); const score = (res) => (res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'); - let comment = `⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this PR:\n`; - comment += '| Category | Score |\n'; - comment += '| --- | --- |\n'; - + let comment Object.keys(manifest).forEach((page) => { + comment += `*Lighthouse ran on [${pageLink}](${pageLink})*\n\n`; + comment += '| Category | Score |\n'; + comment += '| --- | --- |\n'; const result = manifest[page].summary; const pageLink = manifest[page].url; Object.keys(result).forEach((key) => { const formattedScore = formatResult(result[key]); comment += `| ${score(result[key])} ${key} | ${formattedScore} |\n`; }); - comment += `*Lighthouse ran on [${pageLink}](${pageLink})*\n\n`; + }); core.setOutput('comment', comment);