Skip to content

Commit

Permalink
Use correct CircleCI environment variable for pull request detection (#…
Browse files Browse the repository at this point in the history
…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 <[email protected]>
Co-authored-by: Pankaj Yadav <[email protected]>
  • Loading branch information
3 people authored Dec 4, 2024
1 parent 5e8e92d commit a42c13c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion packages/env/src/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions packages/env/test/circle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
});
Expand All @@ -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);
});
});

0 comments on commit a42c13c

Please sign in to comment.