tooling/lighthouse #17
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: Lighthouse CI | |
on: | |
pull_request: | |
branches: [main] | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
lighthouse: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup Node | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Build application | |
run: npm run build | |
- name: Install Lighthouse CI | |
run: npm install -g @lhci/cli | |
- name: Start HTTP Server | |
run: npx http-server ./dist -p 4173 & | |
shell: bash | |
- name: Wait for HTTP Server to start | |
run: sleep 10 | |
- name: Run Lighthouse CI | |
id: lhci | |
run: | | |
lhci autorun --config=.lighthouserc.cjs > lhci.log | |
continue-on-error: true | |
- name: Check Lighthouse Outcome | |
id: check_lighthouse | |
run: | | |
if grep -q "Assertion failed" lhci.log; then | |
echo "Lighthouse tests failed." | |
echo "::set-output name=status::failed" | |
else | |
echo "Lighthouse tests passed." | |
echo "::set-output name=status::passed" | |
fi | |
- name: Post Comment on PR | |
uses: peter-evans/create-or-update-comment@v1 | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
${{ steps.check_lighthouse.outputs.status == 'failed' && '❌ Lighthouse checks failed. Please review the Lighthouse report in the Artifacts.' || '✅ Lighthouse checks passed successfully!' }} | |
Report URL: [View Lighthouse Report](${{ steps.extract_url.outputs.report_url }}) | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Fail the Workflow if Lighthouse Failed | |
if: steps.check_lighthouse.outputs.status == 'failed' | |
run: exit 1 |