Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatching results from Lighthouse report attached to the output manifest #85

Open
drazenbuljovcic opened this issue Jun 21, 2021 · 5 comments

Comments

@drazenbuljovcic
Copy link

drazenbuljovcic commented Jun 21, 2021

Hi, I have a case of the numbers of the lighthouse score in the report are not equal as we see them in the PR.

Type Bug

The result variable below which inside the console.log is retrieved by ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary. lighthouse_audit is the identifier for the above step that runs the audit!

https://storage.googleapis.com/lighthouse-infrastructure.appspot.com/reports/1624269254964-65478.report.html

image

Part of lighthouse.yaml..

...
      - name: Audit URLs using Lighthouse
        id: lighthouse_audit
        uses: treosh/lighthouse-ci-action@v7
        with:
          configPath: './lighthouserc.json'
          uploadArtifacts: true
          temporaryPublicStorage: true
      - name: Format lighthouse score
        id: format_lighthouse_score
        uses: actions/github-script@v3
        with:
          github-token: ${{secrets.GITHUB_TOKEN}}
          script: |
            const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary
            console.log({ result })
            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} |`,
            ].join('\n');
            core.setOutput("comment", comment);
 ...

Expected
The results returned to the script are exactly the same as the generated report!

@awentzel
Copy link

Any explanation on why the results are mismatched?

@johnnyreilly
Copy link

johnnyreilly commented Feb 1, 2022

I also see this quite regularly. Consider the following screenshot which is driven by the outputs of the GitHub Action:

image

Performance is listed as 65.

However, if we look at the actual report:

image

Performance is listed as 68. Not a vast difference, but crucially these are not the same numbers.

@Yu040419
Copy link

Yu040419 commented Apr 27, 2022

Same here with v9.

@mshick
Copy link

mshick commented Jun 28, 2022

I ran into this issue. It looks like the last item in your manifest is the score that gets reported, but most formatting scripts are grabbing the first item in the array.

You can fix relatively easy by updating your formatting logic from something like this:

const result = ${{ steps.lighthouse_audit.outputs.manifest }}[0].summary

to this:

const manifest = ${{ steps.lighthouse_audit.outputs.manifest }}
const result = manifest[manifest.length - 1].summary

@mttfiorio
Copy link

I have the same problem. I think that generally printing the median is better when looking at multiple runs

const outputs = ${{ steps.lighthouse_audit.outputs.manifest }};
outputs.sort((a, b) => a.summary.performance - b.summary.performance);
const middleIndex = Math.floor(outputs.length / 2);
const result = outputs[middleIndex].summary

Sadly you will have the same mismatch with this code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants