treosh / lighthouse-ci-action

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

Unable to determine current hash with `git rev-parse HEAD` #21

Closed luisherranz closed 4 years ago

luisherranz commented 4 years ago

I'm having this error when I activate temporaryPublicStorage: true.

This is the run: https://github.com/frontity/frontity/pull/244/checks?check_run_id=339869140

And this is the workflow job:

  lighthouse:
    runs-on: ubuntu-latest
    needs: deploy

    steps:
      - name: Audit URLs using Lighthouse
        uses: treosh/lighthouse-ci-action@v2
        with:
          temporaryPublicStorage: true
          urls: |
            https://mars-theme-frontity.worona.now.sh/
            https://mars-theme-frontity.worona.now.sh/2016/the-beauties-of-gullfoss/

By looking at the specific line that throws the error: https://github.com/GoogleChrome/lighthouse-ci/blob/master/packages/utils/src/build-context.js#L54 it looks like lighthouse is trying to use git rev-list -n1 HEAD to get the commit hash.

Just before that, it looks for some environment variables. I have solved the issue adding the env LHCI_BUILD_CONTEXT__CURRENT_HASH populated with ${{ github.sha }}.

I'm not sure why I am having this problem, but in case you can reproduce it, maybe this package should add the LHCI_BUILD_CONTEXT__CURRENT_HASH env variable by default:

env:
  LHCI_BUILD_CONTEXT__CURRENT_HASH: ${{ github.sha }}
alekseykulikov commented 4 years ago

Hey @luisherranz ! Thank you for the report. Now, the action requires GitHub repo. In the future, It would be great to be able to run in a standalone mode like your example.

Include actions/checkout at the beginning of the workflow to make it work:

steps:
  - uses: actions/checkout@v1

See examples for more details: https://github.com/treosh/lighthouse-ci-action#examples

luisherranz commented 4 years ago

I see, thanks @alekseykulikov.

alekseykulikov commented 4 years ago

Related LHCI issue: https://github.com/GoogleChrome/lighthouse-ci/issues/151

milewski commented 3 years ago

I'm on the latest version I do have actions/checkout@v2 but I still get the error...

LHCI_BUILD_CONTEXT__CURRENT_HASH: ...
LHCI_BUILD_CONTEXT__COMMIT_MESSAGE: ....
LHCI_BUILD_CONTEXT__AUTHOR: ....
LHCI_BUILD_CONTEXT__AVATAR_URL: .....

It keeps asking me .. I'm not sure how many more it will ask.. I gave up when it asked me AVATAR_URL

milewski commented 3 years ago

Actually, I figured it out...

Looking at the log for checkout@v2 I saw this:

image

As I'm using a self-hosted runner I had an old version of git.. upgrading it.. now there is indeed a .git folder in my root directory and everything works as expected.