Skip to content

fix auto-lighthouse #155

fix auto-lighthouse

fix auto-lighthouse #155

Workflow file for this run

on:
push:
branches-ignore:
- "lighthouse-patches/**"
jobs:
lighthouse:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install Vercel CLI
run: npm install -g vercel
- name: Get Vercel preview URL
id: vercel
run: echo "url=\"$(vercel --token ${{ secrets.VERCEL_ACCESS_TOKEN }} deploy --yes)\"" >> $GITHUB_OUTPUT
- name: Run Lighthouse Audit
uses: foo-software/lighthouse-check-action@v12.0.1
id: lighthouse
with:
urlsJson: "[${{ steps.vercel.outputs.url }}]"
- name: Save Lighthouse output to file
run: echo '${{ steps.lighthouse.outputs.lighthouseCheckResults }}' > ./lighthouse/report.json
- name: Install npm dependencies
run: npm i
- name: Check if we should make a comment tests on a PR, commit tests to main, or do nothing
id: action-type
run: |
if [[ '${GITHUB_REF/refs\/heads\//}' == "main" ]]; then \
if [[ '${{ github.event.head_commit.message }}' == *"updates lighthouse badges"* ]]; \
then RESULT="nothing"; \
else RESULT="commit"; fi; \
else RESULT="comment"; fi; \
echo result=$RESULT >> $GITHUB_OUTPUT
- name: Set Lighthouse patch branch name
if: steps.action-type.outputs.result == 'commit'
id: patch-branch
run: echo name="lighthouse-patches/${{ steps.git-branch.outputs.name }}" >> $GITHUB_OUTPUT
- name: Generate Lighthouse badges
if: steps.action-type.outputs.result == 'commit'
id: badges
run: npm run badges:write
- name: Run prettier to format the Lighthouse badges
if: steps.action-type.outputs.result == 'commit'
run: npm run format
- name: Create PR with Lighthouse results
id: badge-pr
if: steps.action-type.outputs.result == 'commit'
uses: peter-evans/create-pull-request@v4
with:
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
commit-message: "chore: updates lighthouse badges"
title: "chore: updates lighthouse badges for `${{ steps.git-branch.outputs.name }}`"
branch: ${{ steps.patch-branch.outputs.name }}
- name: Automerge Lighthouse badge PR
if: steps.action-type.outputs.result == 'commit' && steps.badge-pr.outputs.pull-request-operation == 'created'
uses: peter-evans/enable-pull-request-automerge@v2
with:
token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
pull-request-number: ${{ steps.badge-pr.outputs.pull-request-number }}
merge-method: rebase
- name: Find current PR
if: steps.action-type.outputs.result == 'comment'
uses: jwalton/gh-find-current-pr@v1
id: finder
- name: Generate Lighthouse badge comment
if: steps.action-type.outputs.result == 'comment'
id: badge-comment
run: npm run badges:comment
- name: Create comment with Lighthouse results
if: steps.action-type.outputs.result == 'comment'
uses: marocchino/sticky-pull-request-comment@v2
with:
number: ${{ steps.finder.outputs.pr }}
message: ${{ steps.badge-comment.outputs.comment }}