GitHub Actions
Add VISUALCI_TOKEN (a project token) to the repository's Actions secrets. Then add these steps to the job that runs your tests:
jobs:
test:
runs-on: ubuntu-latest
env:
VISUALCI_TOKEN: ${{ secrets.VISUALCI_TOKEN }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
fetch-depth: 0 # VisualCI finds the baseline through the commit's ancestors
- name: Install VisualCI
run: |
curl -fsSL https://visualci.com/install.sh | VISUALCI_INSTALL_DIR="$RUNNER_TEMP" sh
echo "$RUNNER_TEMP" >> "$GITHUB_PATH"
- name: Start a VisualCI build
run: echo "VISUALCI_BUILD_ID=$(visualci build create)" >> "$GITHUB_ENV"
- run: npm test -- -u # write snapshots instead of failing; see the snapshot guides
- name: Send snapshots
if: always()
run: |
visualci upload --from auto src tests
visualci build finalize
Commit, branch and pull request
On a pull_request event, GITHUB_SHA is a merge commit GitHub made. The CLI reads the branch's own commit and the pull request number from the event payload (GITHUB_EVENT_PATH) instead, so the check lands on the branch's commit. On other events it reads GITHUB_SHA. The branch comes from GITHUB_HEAD_REF on pull requests and GITHUB_REF_NAME otherwise.
The checkout step above checks out that same commit, so the history the CLI sends starts from it.
fetch-depth: 0 gives the CLI the commit's history, which it sends so VisualCI can find the nearest approved ancestor.
Blacksmith, Depot and other runners
Blacksmith, Depot and other GitHub Actions runner providers run the same workflow with a different runs-on. Nothing else changes.
Parallel jobs
Matrix or sharded jobs can share one build. Each job creates the build with the same nonce, and finalizes its own shard:
export VISUALCI_BUILD_ID=$(visualci build create --nonce "$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" --shards 4)
# ... tests and uploads ...
visualci build finalize --shard "$SHARD_INDEX" # 0 to 3
See Other CI providers.