# CircleCI

> Send VisualCI builds from CircleCI, including parallel jobs that share one build.

Source: https://visualci.com/docs/ci/circleci/
All of VisualCI's documentation: https://visualci.com/llms.txt

Add `VISUALCI_TOKEN` (a project token) to the project's environment variables or a context. The CLI reads the commit from `CIRCLE_SHA1`, the branch from `CIRCLE_BRANCH` and the pull request from `CIRCLE_PULL_REQUEST`.

```yaml
jobs:
  test:
    docker:
      - image: cimg/node:lts
    steps:
      - checkout
      - run:
          name: Install VisualCI
          command: curl -fsSL https://visualci.com/install.sh | VISUALCI_INSTALL_DIR="$HOME/bin" sh
      - run:
          name: Start a VisualCI build
          command: echo "export VISUALCI_BUILD_ID=$($HOME/bin/visualci build create)" >> "$BASH_ENV"
      - run: npm test -- -u # write snapshots instead of failing; see the snapshot guides
      - run:
          name: Send snapshots
          when: always
          command: |
            $HOME/bin/visualci upload --from auto src tests
            $HOME/bin/visualci build finalize
```

`$HOME/bin` must exist and be on the `PATH` in your image; adjust `VISUALCI_INSTALL_DIR` if not.

## Parallel jobs

With `parallelism`, every container creates the build with the same nonce and gets the same build back. Each finalizes its own shard, numbered from 0:

```sh
export VISUALCI_BUILD_ID=$(visualci build create --nonce "$CIRCLE_WORKFLOW_ID-$CIRCLE_JOB" --shards "$CIRCLE_NODE_TOTAL")
# ... tests and uploads ...
visualci build finalize --shard "$CIRCLE_NODE_INDEX"
```

The build is compared once every shard has finalized. The [Ruby helpers](https://visualci.com/docs/screenshots.md#ruby-and-rspec) upload and finalize their shard at exit, and read `CIRCLE_NODE_INDEX` themselves.

If some containers can be skipped (for example, tests split by changed files), add `--subset` when creating the build, so snapshots that weren't sent aren't counted as removed.
