JakePartusch/wait-for-netlify-action

Fix Lighthouse example

Opened this issue · 3 comments

The Lighthouse example in the README could be improved:

  • the npm install and build steps are unnecessary (other than the global install of lchi/cli), since we are testing against Netlify
  • if using the Lighthouse CI Github App to get Github Status Checks fed back to the PR, the checkout step needs to get its ref from github.event.pull_request.head.sha and the final step needs to get the LHCI_GITHUB_APP_TOKEN from the repo's secrets and supply it to env.
name: Lighthouse
on: pull_request
jobs:
  netlify-deploy-preview:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Read .nvmrc version
        run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
        id: nvm
      - name: Set Node.js version
        uses: actions/setup-node@v1
        with:
          node-version: "${{ steps.nvm.outputs.NVMRC }}"
      - name: Wait for Netlify Preview
        uses: jakepartusch/wait-for-netlify-action@v1.2
        id: netlify
        with:
          site_name: 'your-netlify-site-name'
          max_timeout: 300
      - name: Lighthouse CI
        run: |
          npm install -g @lhci/cli
          lhci autorun --upload.target=temporary-public-storage --collect.url=${{ steps.netlify.outputs.url }} || echo "LHCI failed!"
        env:
          LHCI_GITHUB_APP_TOKEN: ${{ secrets.LHCI_GITHUB_APP_TOKEN }}

Thanks for the feedback @lunelson ! I definitely agree about the install steps.

I'm sort of confused about this part:

with:
  ref: ${{ github.event.pull_request.head.sha }}

Won't the Action re-run with the latest commit by default when the PR is updated?

@JakePartusch yeah sorry that's a Lighthouse specific fix, and I can't find the link any more to the issue thread about it, but the Lighthouse CI Github App was not picking up the reference, so the status-check update (posting the results back to the list of checks, after the netlify checks) wasn't coming through, you'd still have to dig through the action output to find the URL of the report. With this fix, it posts the status update