CircleCI
Selective detects CircleCI automatically and reads the node index from parallelism. The orb fills in the pieces CircleCI doesn’t expose to the job directly.
Set SELECTIVE_API_KEY as an environment variable on the project or in a context. Then in the test job:
- setup-selective/init: actor: << pipeline.trigger_parameters.github_app.user_username >> run_id: << pipeline.id >> target_branch: main
- run: bundle exec selective rspecSet parallelism on the job to the number of nodes you want; each node pulls from the same queue.
A working config is in the selective-ruby-rspec repository and the selective-ruby-minitest repository.
run_idshould stay the same across reruns of the same commit and change when a new commit is pushed. The pipeline id does that.target_branchis the branch the change will merge into. Selective uses it to order tests by the diff and, in selection mode, to decide what changed.
Daily map recording
Section titled “Daily map recording”Test selection needs a fresh map of which files each test executes. Add a pipeline parameter and pass it to the test job as SELECTIVE_TEST_MAP_RECORD:
parameters: record_map: type: boolean default: false
jobs: test: parallelism: 4 environment: SELECTIVE_TEST_MAP_RECORD: << pipeline.parameters.record_map >>Then create a scheduled pipeline in Project Settings → Triggers that runs daily on the default branch with record_map set to true. That run prints Recording a test map. See keeping the map fresh.
Warm-up
Section titled “Warm-up”With test selection on, a job that tells Selective about the run as the workflow starts has the commit’s file tree, the map and the semantic decision ready before the test nodes connect. See warm-up.
jobs: selective-warmup: docker: - image: cimg/base:current steps: - run: name: Warm up Selective command: | curl -sS --max-time 20 -X POST https://app.selective.ci/warmup \ -H "authorization: $SELECTIVE_API_KEY" -H "content-type: application/json" \ -d "{\"sha\": \"$CIRCLE_SHA1\", \"git_repo_full_name\": \"$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME\", \"target_branch\": \"main\", \"branch\": \"$CIRCLE_BRANCH\"}" \ || true
workflows: tests: jobs: - selective-warmup - testGive it the same context or project variables as the test job. target_branch must be the same value as the orb’s target_branch, and there’s no base_sha because the runner doesn’t report one on CircleCI. The test job doesn’t requires: it, so both start together.