0

I'm trying to configure lighthouse CI with GitHub Actions for the first time.

My current configuration looks like this:

name: Pull Request Checks

on:
  pull_request:

  lighthouseci:
    runs-on: ubuntu-latest
    steps:
      - name: 'Checkout Github Repository'
        uses: actions/checkout@v3

      - name: Use Node.js 16.x
        uses: actions/setup-node@v3
        with:
          node-version: 16.x

      - name: 'build'
        run: |
          npm install
          npm run build

      - name: 'run lighthouse'
        id: lighthouse
        run: |
          npm install -g @lhci/cli@0.11.x
          lhci autorun

      - name: Output lighthouse results
        run: |
          echo "Performance: ${{ steps.lighthouse.outputs }}" >> $GITHUB_STEP_SUMMARY

Everything up until Output lighthouse results works.
The goal for Output lighthouse results is to post a comment in the PR with an overview of the results from my lighthouse test. This part doesn't work and I am struggling to understand how this is even supposed to work.

I tried checking the docs:

and went digging into the source code of https://github.com/treosh/lighthouse-ci-action/tree/main

I also looked at some other examples of actions with outputs and some of them do something like this:

echo "lhci=$(lhci autorun)\n" >> $GITHUB_OUTPUT

But I get this error message:

Error: Unable to process file command 'output' successfully.

Presumably because the output is not in a structured format?

This answered some questions but left some open:

  1. steps.lighthouse.outputs is some object, but I don't know how I can figure out what that object looks like at all. And the only reason I found this key in the first place is because I stole it from some blog post. Is there any documentation here I am missing?
  2. The build output is nice but I'd like to see it as a comment under the PR. What approach should I be taking for that?

Even just some of the terminology that I need to google would be really helpful as this is a completely new area for me.

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
jsco
  • 25
  • 4
  • These are all good questions, but it's really three questions in one: 1. How can I print a multi-line string to `GITHUB_OUTPUT`? (answer in [this Q&A](https://stackoverflow.com/q/74137120/3266847)) 2. How can I inspect an output object? (answer: see [this docs example using `toJson`](https://docs.github.com/en/actions/learn-github-actions/contexts#example-printing-context-information-to-the-log)) 3. How can I post a comment from a workflow? (see [this Q&A](https://stackoverflow.com/q/58066966/3266847)). – Benjamin W. Jun 22 '23 at 18:25

1 Answers1

0

Since you are using this value within the same job, you should use $GITHUB_ENV instead of $GITHUB_OUTPUT. Heres something you can try:

 - name: 'run lighthouse'
   run: |
     npm install -g @lhci/cli@0.11.x
     echo "lighthouse_output=$(lhci autorun)" >> $GITHUB_ENV

  - name: Output lighthouse results
    run: |
      echo "Performance: ${{ env.lighthouse_output }}" >> $GITHUB_STEP_SUMMARY