percy / percy-js

[Deprecated] JavaScript API client library for Percy.
MIT License
31 stars 19 forks source link

Fails to publish screenshots from bitbucket pull request pipeline #228

Closed erik-inkapool closed 4 years ago

erik-inkapool commented 4 years ago

Getting error message

Uploading x snapshots to Percy.
Error:  { StatusCodeError: 400 - {"errors":[{"status":"bad_request"},{"source":{"pointer":"/data/attributes/sha"},"detail":"Sha must be 40 hexadecimal characters"}]}

In pull requests, but the same pipeline will run fine when triggered manually or by commit. My use case is that I would like to only run percy on the main branch and on PRs to that branch, not on individual feature branch commits or the like.

My pipeline uses the pull-requests build variant, like so:

image: circleci/node:10.22.1-browsers

pipelines:
  pull-requests:
    '**':
      - step:
          caches:
            - npm
          script:
            - npm ci
            - npm run-script build:storybook // build-storybook
            - npm run-script test:visual // percy-storybook --widths=320,1080
definitions:
  caches:
    npm: $HOME/.npm

I can work around the problem by using a configuration that always builds every commit:

image: circleci/node:10.22.1-browsers

pipelines:
  default:
    - step:
        caches:
          - npm
        script:
          - npm ci
          - npm run-script build:storybook // build-storybook
          - npm run-script test:visual // percy-storybook --widths=320,1080
definitions:
  caches:
    npm: $HOME/.npm
Robdel12 commented 4 years ago

Hey @erik-inkapool! This one is a weird one that we haven't been able to figure out. Seemingly (for unknown reasons) Bitbucket pipelines will return the shortened SHA for: https://github.com/percy/percy-js/blob/master/src/environment.js#L217

In these cases you will have to manually set PERCY_COMMIT to the full 40 char SHA. I think this will work: PERCY_COMMIT=$(git rev-parse HEAD)

erik-inkapool commented 4 years ago

Hi @Robdel12! Thanks for the quick response. Your solution worked perfectly, this is what the pipeline looks like now:

image: circleci/node:10.22.1-browsers

pipelines:
  pull-requests:
    '**':
      - step:
          caches:
            - npm
          script:
            - npm ci
            - npm run-script build:storybook # build-storybook
            - PERCY_COMMIT=$(git rev-parse HEAD) npm run-script test:visual # percy-storybook --widths=320,1280
definitions:
  caches:
    npm: $HOME/.npm