Skip to content

Commit

Permalink
chore: omit unused circle variables that cause contributor PR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
AtofStryker committed May 31, 2023
1 parent acc4d5f commit 0922996
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/circle-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
Expand Down
50 changes: 50 additions & 0 deletions scripts/unit/circle-env-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 0922996

Please sign in to comment.