Last active
September 27, 2018 02:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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