treosh / lighthouse-ci-action

Audit URLs using Lighthouse and test performance with Lighthouse CI.
MIT License
1.18k stars 82 forks source link

Use with relative URLs #96

Closed ptmkenny closed 2 years ago

ptmkenny commented 2 years ago

I'm trying to figure out how I can use this action when building dev/staging/live environments that all have different URLs. My hosting company randomly generates the URL for each dev environment, so I can't hard-code the values into main.yml.

Is there a way to support relative paths instead of URLs?

Is it possible to use this action when spinning up dev/staging/live environments dynamically?

ptmkenny commented 2 years ago

I solved this by setting the URLs using an environmental variable that I set in GitHub Actions.

div-cowboy commented 2 years ago

@ptmkenny how did you accomplish this? I'm trying to use this in my Vercel workflow, but I don't know the preview URL until the PR is open.

cc @alekseykulikov 🙏

ptmkenny commented 2 years ago

Here's my GitHub Actions config:

      - name: "TEST: Audit URLs using Lighthouse."
        id: test
        continue-on-error: true
        uses: treosh/lighthouse-ci-action@v8
        with:
          # PLATFORMSH_URL includes a trailing slash.
          urls: |
            $PLATFORMSH_NOSLASH_URL/page1
            $PLATFORMSH_NOSLASH_URL/page2
            $PLATFORMSH_NOSLASH_URL/dir1/page3
          configPath: .ci/test/lighthouse/anon-lighthouserc-testing.yml
          uploadArtifacts: false # Save results as artifacts. Do it manually instead.
          temporaryPublicStorage: false # Never share the result publicly.
        timeout-minutes: 30

In a previous step, I use the PlatformSH command-line tool (as the site is hosted on platformSH) to get the URL and set it as an environment variable. This works because I've set the auth token for the command-line tool via another environment variable.

Not sure what you would do with Vercel, but hopefully the provider has a way to fetch the URL.