From a42c13ceca0f799a73aa3b5149571683b08326ee Mon Sep 17 00:00:00 2001 From: Ethan Setnik Date: Wed, 4 Dec 2024 04:58:33 -0500 Subject: [PATCH] Use correct CircleCI environment variable for pull request detection (#1767) * Use correct CircleCI environment variable for pull request detection https://circleci.com/docs/variables/#built-in-environment-variables:~:text=CIRCLE_PULL_REQUESTS * update tests and fix PERCY_PARALLEL_TOTAL on circle * Update README.md * Revert Update README.md * Revert update readme. * Fix Lint Issue * Update environment.js * Fix CircleCI test --------- Co-authored-by: ninadbstack <60422475+ninadbstack@users.noreply.github.com> Co-authored-by: Pankaj Yadav --- packages/env/src/environment.js | 7 ++++++- packages/env/test/circle.test.js | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/packages/env/src/environment.js b/packages/env/src/environment.js index e8c059eb3..325a4d17c 100644 --- a/packages/env/src/environment.js +++ b/packages/env/src/environment.js @@ -178,7 +178,7 @@ export class PercyEnv { case 'jenkins': return this.vars.CHANGE_ID; case 'circle': - return this.vars.CI_PULL_REQUESTS?.split('/').slice(-1)[0]; + return this.vars.CIRCLE_PULL_REQUESTS?.split('/').slice(-1)[0]; case 'drone': return this.vars.CI_PULL_REQUEST; case 'semaphore': @@ -212,6 +212,11 @@ export class PercyEnv { // parallel total & nonce get parallel() { let total = parseInt(this.vars.PERCY_PARALLEL_TOTAL, 10); + + if (this.ci === 'circle') { + total = parseInt(this.vars.CIRCLE_NODE_TOTAL, 10); + } + if (!Number.isInteger(total)) total = null; // no nonce if no total diff --git a/packages/env/test/circle.test.js b/packages/env/test/circle.test.js index 6770e1d49..ef84f3753 100644 --- a/packages/env/test/circle.test.js +++ b/packages/env/test/circle.test.js @@ -5,10 +5,10 @@ describe('CircleCI', () => { beforeEach(() => { env = new PercyEnv({ - PERCY_PARALLEL_TOTAL: '-1', + CIRCLE_NODE_TOTAL: '-1', CIRCLE_BRANCH: 'circle-branch', CIRCLE_SHA1: 'circle-commit-sha', - CI_PULL_REQUESTS: 'https://github.com/owner/repo-name/pull/123', + CIRCLE_PULL_REQUESTS: 'https://github.com/owner/repo-name/pull/123', CIRCLE_BUILD_NUM: 'build-number', CIRCLECI: 'true' }); @@ -29,4 +29,9 @@ describe('CircleCI', () => { env = new PercyEnv({ ...env.vars, CIRCLE_WORKFLOW_ID: 'workflow-id' }); expect(env).toHaveProperty('parallel.nonce', 'workflow-id'); }); + + it('has the correct parallel total', () => { + env = new PercyEnv({ ...env.vars, CIRCLE_NODE_TOTAL: '2' }); + expect(env).toHaveProperty('parallel.total', 2); + }); });