Skip to content

Instantly share code, notes, and snippets.

@fotinakis
Last active September 27, 2018 02:34
Show Gist options
  • Save fotinakis/376f1b56db8f4da0088c8cf06f549fd4 to your computer and use it in GitHub Desktop.
Save fotinakis/376f1b56db8f4da0088c8cf06f549fd4 to your computer and use it in GitHub Desktop.
Percy manual build finalization for Circle 2.0 and other parallel CI workflows.
jobs:
# ...
percy_finalize:
docker:
- image: circleci/node:10
steps:
- run: npm install percy-client
- run: node .circleci/percy-finalize.js
workflows:
version: 2
build_and_test:
jobs:
- build
- test
- percy_finalize
requires:
- test
// Percy manual build finalization for Circle 2.0 and other parallel CI workflows.
//
// STEP 0: make sure you are running percy-client >= 2.2.0.
//
//
// STEP 1: opt in to manual parallel handling by setting PERCY_PARALLEL_TOTAL=-1
// in your environment. Note that it is -1, not 1.
//
//
// STEP 2: create a file named `percy-finalize.js` containing:
//
process.env['PERCY_PARALLEL_TOTAL'] = '-1';
let Environment = require('percy-client/dist/environment');
let PercyClient = require('percy-client');
var environment = new Environment(process.env);
if (!environment.parallelNonce || !environment.parallelTotalShards) {
console.warn('[percy][ERROR] PERCY_PARALLEL_NONCE and PERCY_PARALLEL_TOTAL must be set.')
}
let percyClient = new PercyClient({token: process.env.PERCY_TOKEN});
let currentBuildPromise = percyClient.createBuild();
currentBuildPromise.then((currentBuild) => {
console.log(`[percy] Finalizing all parallel shards for build: ${currentBuild.body.data.id}`);
percyClient.finalizeBuild(currentBuild.body.data.id, {allShards: true});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment