treosh / lighthouse-ci-action

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

URL interpolation (e.g. URLs with a PR number in them) #4

Closed orta closed 4 years ago

orta commented 4 years ago

Hi there!

Cool work, I'm trying to audit my PR deploys, but they include a URL which differs per run.

I thought I'd reach out if you had any ideas?

Current (not working):

  lighthouse:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@master
      - name: Run Lighthouse and test budgets
        uses: treosh/lighthouse-ci-action@v1
        with:
          urls: |
            https://typescript-v2-$PR_NUMBER.ortam.now.sh
            https://typescript-v2-$PR_NUMBER.ortam.now.sh/tsconfig
            https://typescript-v2-$PR_NUMBER.ortam.now.sh/docs/handbook/integrating-with-build-tools.html

Fri, 08 Nov 2019 13:28:38 GMT GatherRunner:error DNS servers could not resolve the provided domain. https://typescript-v2-$pr_number.ortam.now.sh/

Some options:

  lighthouse:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@master
      - name: Run Lighthouse and test budgets
        uses: treosh/lighthouse-ci-action@v1
        with:
          urls: |
            https://typescript-v2-$(PR_NUM).ortam.now.sh
            https://typescript-v2-$(PR_NUM).ortam.now.sh/tsconfig
            https://typescript-v2-$(PR_NUM).ortam.now.sh/docs/handbook/integrating-with-build-tools.html
        env:
          PR_NUM: ${{ secrets.$PR_NUMBER }}
orta commented 4 years ago

I gave the first option a go in https://github.com/treosh/lighthouse-ci-action/pull/6

robinmetral commented 4 years ago

Note to future viewers: this will only work if your workflow is set to run on pull_request.

It would be nice if it could also run on push and get the PR number if any PR is associated to the branch.

If you need to run on push, a workaround could be to run a workflow on both push and pull_request but only run the Lighthouse job if we are on a PR.

alekseykulikov commented 4 years ago

@robinmetral env variables interpolation works for all types of events. Check a dedicated workflow recipe for more details. This example using PR specific variables, but it can be any env variable or secret.

robinmetral commented 4 years ago

Thanks for making this extra example @alekseykulikov!

What I meant is that the GitHub environment variable github.events.pull_request.number, is only available on pull_request.

There's nothing this Action can really do about it, I was just mentioning it because it took me a while to understand why it was undefined in my push workflow 🙂