percy / exec-action

A (deprecated) GitHub action to run Percy Agent `percy exec` commands
https://docs.percy.io/docs/github-actions#section-exec-action
MIT License
8 stars 5 forks source link

How to use with finalize --all? #26

Closed steakscience closed 3 years ago

steakscience commented 3 years ago

Hi, I'm currently trying to run percy finalize --all to complete my parallel tests:

Relevant section:

      - name: Finish batch
        uses: percy/exec-action@v0.3.1
        with:
          command: "npx percy finalize --all"
          working-directory: "./e2e"
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
          PERCY_PARALLEL_NONCE: ${GITHUB_ACTION}

Currently, the command will result in an error so there must be a syntax issue with it. I tag all the parallel tests with the nonce ${GITHUB_ACTION} which is a unique ID for each GitHub Action.

What is the right way to do this?

wwilsman commented 3 years ago

Hey @steakscience!

Getting parallel builds to work within GitHub Actions can actually be more difficult than it seems. For example, the parallel nonce must be unique for that specific set of parallel builds. The GITHUB_ACTION environment variable is actually set to be the Action's scoped name or context name, which would be the same every time that step in the action runs even for different commits.

A more accurate nonce, would be to create a unique string at the beginning of the entire workflow and persist that string until the end of the workflow. For example, {branch}-{sha}-{timestamp} would be pretty unique to create once at the beginning and use in subsequent steps for builds that need to be grouped together. In the future, we'd like to automatically create a unique nonce within the action, but for now you'll have to do it manually and ensure it is unique for each group of parallel builds.


As for the error, it would help to know what error actually says, and how you are running your parallel jobs. 🙂

wwilsman commented 3 years ago

Also, I just noticed that you're using the with.command option, when you probably want with.custom-command. The command option gets wrapped as percy exec -- <command>, while custom-command will replace the exec command entirely.

steakscience commented 3 years ago

@wwilsman Using custom-command makes perfect sense. Thank you.

Do I need to use @percy/agent at all or would /exec work for finalize? https://github.com/percy/percy-agent#percy-finalize

wwilsman commented 3 years ago

@percy/agent comes with both the exec and finalize commands. Since custom-command gets executed directly rather than wrapped in percy exec --, you'll probably want something like:

custom-command: "npx percy finalize --all"

If you're referring to needing @percy/agent as a direct dependency, it should be included as a JS dependency of your SDK or installed directly if you're using another language besides JS. In either case, npx will first check your local dependencies for the percy command, and failing to find it should automatically download @percy/agent before executing the command.

Does any of that answer your question? 😄

steakscience commented 3 years ago

@wwilsman

Ok that answers my question

One last thing is: when using custom-command, do the env variables still get passed in? Such as PERCY_PARALLEL_NONCE

- name: Visual Tests
        uses: percy/agent@master
        with:
          custom-command: "npx percy finalize --all"
          working-directory: "./e2e"
        env:
          PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
          PERCY_PARALLEL_NONCE: ${UNIQUE_ID}
wwilsman commented 3 years ago

Sorry for the delay, yes it should pass through all environment variables to the command.

Here is the entire action's code: https://github.com/percy/exec-action/blob/master/src/index.js

We don't specifically set the exec option, env, which means it should be inherited from the current environment.

steakscience commented 3 years ago

@wwilsman Thank you!