Skip to content

Commit

Permalink
Use script
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed May 4, 2022
1 parent be46037 commit 2a2396f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
21 changes: 4 additions & 17 deletions .github/workflows/lighthouse-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,11 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary
const results = ${{ steps.lighthouse_audit.outputs.manifest }}
const links = ${{ steps.lighthouse_audit.outputs.links }}
const formatResult = (res) => Math.round((res * 100))
Object.keys(result).forEach(key => result[key] = formatResult(result[key]))
const score = res => res >= 90 ? '🟢' : res >= 50 ? '🟠' : '🔴'
const comment = [
`⚡️ [Lighthouse report](${Object.values(links)[0]}) for the changes in this PR:`,
'| Category | Score |',
'| --- | --- |',
`| ${score(result.performance)} Performance | ${result.performance} |`,
`| ${score(result.accessibility)} Accessibility | ${result.accessibility} |`,
`| ${score(result['best-practices'])} Best practices | ${result['best-practices']} |`,
`| ${score(result.seo)} SEO | ${result.seo} |`,
`| ${score(result.pwa)} PWA | ${result.pwa} |`,
' ',
`*Lighthouse ran on [${Object.keys(links)[0]}](${Object.keys(links)[0]})*`
].join('\n')
core.setOutput("comment", comment);
const createLighthouseReport = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/scripts/format-lighthouse-score.js`)
const comment = createLighthouseReport({ results, links })
core.setOutput("comment", comment);
- name: Add Lighthouse stats as comment
id: comment_to_pr
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scripts/format-lighthouse-score.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const createMarkdownTableHeader = () => {
];
};

const createLightHouseReport = ({results, links}) => {
const createLighthouseReport = ({results, links}) => {
const tableHeader = createMarkdownTableHeader();
const tableBody = results.map((result) => {
const testUrl = Object.keys(links).find((key) => key === result.url);
Expand All @@ -55,4 +55,4 @@ const createLightHouseReport = ({results, links}) => {
return comment.join('\n');
};

module.exports = createLightHouseReport;
module.exports = createLighthouseReport;

0 comments on commit 2a2396f

Please sign in to comment.