Post-deployment statistics #449
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Post-deployment statistics | |
on: | |
deployment_status: | |
jobs: | |
generate_lighthouse_audit: | |
if: github.event_name == 'deployment_status' && github.event.deployment_status.state == 'success' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Audit URLs using Lighthouse | |
id: lighthouseScore | |
uses: treosh/lighthouse-ci-action@v9 | |
env: | |
LHCI_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
#@todo: generate affected urls | |
urls: | | |
${{ github.event.deployment_status.target_url }} | |
${{ github.event.deployment_status.target_url }}/map | |
${{ github.event.deployment_status.target_url }}/tutorial | |
temporaryPublicStorage: true | |
configPath: '.github/workflows/lighthouse/assertions.json' | |
- uses: actions/github-script@v6 | |
id: format-message | |
env: | |
LINKS: ${{ steps.lighthouseScore.outputs.links }} | |
MANIFESTS: ${{ steps.lighthouseScore.outputs.manifest }} | |
with: | |
result-encoding: string | |
script: | | |
const links = JSON.parse(process.env.LINKS) | |
const manifests = JSON.parse(process.env.MANIFESTS) | |
const formatHeader = (input) => { | |
const relPath = input.substring((input.indexOf('.app') !== -1 ? input.indexOf('.app') : input.indexOf('.com'))+5) | |
return relPath.charAt(0).toUpperCase() + relPath.slice(1).replace(/-/g, ' '); | |
} | |
let tableHeaders = ''; | |
let tableCells = ''; | |
manifests.forEach((item) => { | |
const title = item.url.endsWith('/') | |
? 'Landing page' | |
: formatHeader(item.url); | |
tableHeaders = tableHeaders.concat(`<th><a href=${item.url} target="_blank">${title}</a></th>`); | |
tableCells = tableCells.concat(` | |
<td align="center"> | |
||| | |
|--|--| | |
| Performance | ${ | |
item.summary.performance > 0.9 ? '🍏' : item.summary.performance < 0.6 ? '🍓' : '🍊' | |
} ${item.summary.performance * 100} | | |
| Accessibility | ${ | |
item.summary.accessibility > 0.95 ? '🍏' : item.summary.accessibility < 0.9 ? '🍓' : '🍊' | |
} ${item.summary.accessibility * 100} | | |
| Best practices | ${ | |
item.summary['best-practices'] > 0.9 | |
? '🍏' | |
: item.summary['best-practices'] < 0.8 | |
? '🍓' | |
: '🍊' | |
} ${item.summary['best-practices'] * 100} | | |
| SEO | ${item.summary.seo > 0.85 ? '🍏' : item.summary.seo < 0.6 ? '🍓' : '🍊'} ${ | |
item.summary.seo * 100 | |
} | | |
[View full report](${ | |
links[item.url] | |
}) | |
</td>`); | |
}); | |
return ` | |
![Japanese_Wave_Pattern svg](https://user-images.githubusercontent.com/71131586/229189192-0c68aaa7-e366-4b2c-9537-4552723f26c3.png) | |
# Lighthouse scores | |
<table> | |
<tr>${tableHeaders}</tr> | |
<tr>${tableCells}</tr> | |
</table> | |
` | |
- run: echo "${{steps.format-message.outputs.result}}" >> $GITHUB_STEP_SUMMARY | |
- uses: jwalton/gh-find-current-pr@v1 | |
id: findPr | |
- uses: marocchino/sticky-pull-request-comment@v2 | |
with: | |
number: ${{ steps.findPr.outputs.pr }} | |
message: ${{steps.format-message.outputs.result}} |