action-hosting-deploy icon indicating copy to clipboard operation
action-hosting-deploy copied to clipboard

`output.urls` consumption issues

Open jthegedus opened this issue 4 years ago • 2 comments

It appears passing data as arrays is not natively supported by GitHub Actions and thus each consumer of the outputs.urls would need to support consuming arrays by converting from a string.

When first using the Hosting Channel Action I hard coded the URL for my test PR into the Lighthouse step. After successful testing, I changed the code to use the urls output from the Firebase Action and began seeing "Invalid URL" errors with Lighthouse.

My GitHub Action YAML and changes

name: Deploy to Hosting Channel on PR
"on": pull_request
jobs:
  build_deploy_lighthouse:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Deploy to Firebase Hosting Channel
        id: deploy_firebase_hosting_channel
        uses: FirebaseExtended/[email protected]
        with:
          repoToken: "${{ secrets.GITHUB_TOKEN }}"
          firebaseServiceAccount: "${{ secrets.FIREBASE_SERVICE_ACCOUNT_REDACTED }}"
          projectId: REDACTED
        env:
          FIREBASE_CLI_PREVIEWS: hostingchannels
      - name: Run Lighthouse on urls and validate with lighthouserc
        uses: treosh/lighthouse-ci-action@v3
        with:
-		   urls: https://redacted--pr51-fix-hosting-channels-rwjjf6g3.web.app
+          urls: ${{ steps.deploy_firebase_hosting_channel.outputs.urls }}
          configPath: ".lighthouserc.json"
          runs: 3

Lighthouse input config when hard coded URL

  Input args: ***
    "urls": [
      "redacted--pr51-fix-hosting-channels-rwjjf6g3.web.app"
    ],

This worked.

New Lighthouse input config

  Input args: ***
    "urls": [
      "[\"https://redacted--pr51-fix-hosting-channels-rwjjf6g3.web.app\"]"
    ],

Note the double array.

Lighthouse Error

  Running Lighthouse 3 time(s) on ["redacted--pr51-fix-hosting-channels-rwjjf6g3.web.app"]
  ...
  Sun, 27 Sep 2020 05:16:17 GMT ChromeLauncher Killing Chrome instance 2891
  Runtime error encountered: The URL you have provided appears to be invalid.
  LHError: INVALID_URL
      at Function.run (/home/runner/work/_actions/treosh/lighthouse-ci-action/v3/node_modules/lighthouse/lighthouse-core/runner.js:78:17)
      at lighthouse (/home/runner/work/_actions/treosh/lighthouse-ci-action/v3/node_modules/lighthouse/lighthouse-core/index.js:48:17)
      at runLighthouse (/home/runner/work/_actions/treosh/lighthouse-ci-action/v3/node_modules/lighthouse/lighthouse-cli/run.js:224:32)
      at processTicksAndRejections (internal/process/task_queues.js:97:5)
  Error: LHCI 'collect' has encountered a problem.

Lighthouse correctly fails to pass ["redacted--pr51-fix-hosting-channels-rwjjf6g3.web.app"] as an URL.

Lighthouse Action urls input

Lighthouse's urls input usage is described as an array of URLs, but like so:

urls: |
  url-1.com
  url-2.com

And so the code - https://github.com/treosh/lighthouse-ci-action/blob/3f01a66925eae1613cb01504ae14ddb29b76cf0d/src/index.js#L32 - does not perform any checks to see if the first input value is a JSON.stringified array, leading to my error.

Workaround

  urls: ${{ steps.deploy_firebase_hosting_channel.outputs.details_url }}

works as expected.

I understand this issue is less of a Firebase Hosting Action issue and so there may be no fix to this, but for future users I am commenting anyway.

jthegedus avatar Sep 27 '20 06:09 jthegedus

The GitHub Action fromJson could potentially solve this. I am yet to test it

jthegedus avatar Oct 30 '20 01:10 jthegedus

urls: ${{ fromJson(steps.deploy_firebase_hosting_channel.outputs.urls)[0] }} worked for me.

ibrahimAboelsuod avatar May 20 '23 16:05 ibrahimAboelsuod