diff --git a/scripts/circle-env.js b/scripts/circle-env.js index 09d650fb46f6..50e76d605eaf 100644 --- a/scripts/circle-env.js +++ b/scripts/circle-env.js @@ -46,6 +46,13 @@ async function readCircleEnv () { throw new Error('COPY_CIRCLE_ARTIFACTS is set, but circleEnv is empty') } + if (Object.keys(circleEnv).length === 3) { + // remove known circle variables that are not used if they exist + delete circleEnv['CIRCLE_OIDC_TOKEN'] + delete circleEnv['CIRCLE_OIDC_TOKEN_V2'] + delete circleEnv['CIRCLE_PLUGIN_TEST'] + } + return circleEnv } catch (err) { throw new Error(`An error occurred when reading the environment from Circle task data: ${err}`) diff --git a/scripts/unit/circle-env-spec.js b/scripts/unit/circle-env-spec.js index df98851e0c26..86e808fd70c0 100644 --- a/scripts/unit/circle-env-spec.js +++ b/scripts/unit/circle-env-spec.js @@ -55,6 +55,56 @@ describe('circle-env', () => { } }) }) + + context('with circleEnv plus only omitted keys', () => { + it('passes', async () => { + sinon.stub(fs, 'readFile') + .withArgs('/foo.json').resolves(JSON.stringify({ + Dispatched: { TaskInfo: { Environment: { + CIRCLE_OIDC_TOKEN: 'foo', + CIRCLE_OIDC_TOKEN_V2: 'bar', + CIRCLE_PLUGIN_TEST: 'baz', + } } }, + })) + + sinon.spy(console, 'warn') + await _checkCanaries() + expect(console.warn).to.be.calledWith('CircleCI env empty, assuming this is a contributor PR. Not checking for canary variables.') + }) + + it('also passes', async () => { + sinon.stub(fs, 'readFile') + .withArgs('/foo.json').resolves(JSON.stringify({ + Dispatched: { TaskInfo: { Environment: { + CIRCLE_OIDC_TOKEN: 'foo', + CIRCLE_OIDC_TOKEN_V2: 'bar', + CIRCLE_PLUGIN_TEST: 'baz', + MAIN_CANARY: 'qux', + CONTEXT_CANARY: 'quux', + } } }, + })) + + await _checkCanaries() + }) + + it('fails', async () => { + sinon.stub(fs, 'readFile') + .withArgs('/foo.json').resolves(JSON.stringify({ + Dispatched: { TaskInfo: { Environment: { + CIRCLE_OIDC_TOKEN: 'foo', + CIRCLE_OIDC_TOKEN_V2: 'bar', + CIRCLE_PLUGIN_TEST: 'baz', + SOME_OTHER_VAR: 'quux', + } } }, + })) + + try { + await _checkCanaries() + } catch (e) { + expect(e.message).to.equal('Missing MAIN_CANARY.') + } + }) + }) }) it('passes with canaries', async () => {