diff --git a/.github/workflows/lighthouse.yml b/.github/workflows/lighthouse.yml new file mode 100644 index 0000000000..80b8ef9f5d --- /dev/null +++ b/.github/workflows/lighthouse.yml @@ -0,0 +1,49 @@ +name: Lighthouse report + +on: + pull_request: + types: [opened, synchronize] + +permissions: + contents: read + pull-requests: write + +jobs: + lighthouse: + if: github.actor != 'dependabot[bot]' + runs-on: ubuntu-latest + + steps: + - name: Checkout PR code + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + + - name: Setup Node.js with npm cache + uses: actions/setup-node@v4 + with: + node-version: '22.x' + cache: 'npm' + + - name: Install dependencies + run: npm install @unlighthouse/cli puppeteer + + - name: Wait for Netlify preview to be live + run: | + PREVIEW_URL="https://deploy-preview-${{ github.event.pull_request.number }}--expressjscom-preview.netlify.app" + echo "PREVIEW_URL=$PREVIEW_URL" >> "$GITHUB_ENV" + for i in {1..2}; do + if curl -s --head "$PREVIEW_URL" | grep "200 OK" > /dev/null; then + echo "Preview is live!" + break + fi + echo "Waiting for Netlify to deploy... ($i/2)" + sleep 10 + done + + - name: Unlighthouse assertions and client + run: npx unlighthouse-ci --site "$PREVIEW_URL" --mobile --urls /en/5x/api --samples 1 --disable-dynamic-sampling --disable-sitemap --disable-robots-txt + + - name: 📄 Log results + run: cat ./.unlighthouse/ci-result.json