Skip to content

Commit

Permalink
chore: fix circle-env for contributor PRs (#21292)
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig committed May 2, 2022
1 parent a47b45f commit 7a76de1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
11 changes: 10 additions & 1 deletion scripts/circle-env.js
Expand Up @@ -21,6 +21,10 @@ async function checkCanaries () {

const circleEnv = await readCircleEnv()

if (Object.keys(circleEnv).length === 0) {
return console.warn('CircleCI env empty, assuming this is a contributor PR. Not checking for canary variables.')
}

if (!circleEnv.MAIN_CANARY) throw new Error('Missing MAIN_CANARY.')

if (!circleEnv.CONTEXT_CANARY) throw new Error('Missing CONTEXT_CANARY. Does this job have the test-runner:env-canary context?')
Expand All @@ -36,7 +40,12 @@ async function readCircleEnv () {
// if this starts failing, try SSHing into a CircleCI job and see what changed in the $CIRCLE_INTERNAL_CONFIG file's schema
const circleEnv = taskData['Dispatched']['TaskInfo']['Environment']

if (!circleEnv || !Object.keys(circleEnv).length) throw new Error('An empty Environment object was found.')
if (!circleEnv) throw new Error('No Environment object was found.')

// last-ditch effort to check that an empty circle env is accurately reflecting process.env (external PRs)
if (process.env.CACHE_VERSION && Object.keys(circleEnv).length === 0) {
throw new Error('CACHE_VERSION is set, but circleEnv is empty')
}

return circleEnv
} catch (err) {
Expand Down
49 changes: 38 additions & 11 deletions scripts/unit/circle-env-spec.js
Expand Up @@ -12,22 +12,49 @@ describe('circle-env', () => {
})

beforeEach(() => {
delete process.env.CACHE_VERSION
process.env.CI = 'true'
process.env.CIRCLE_INTERNAL_CONFIG = '/foo.json'
})

it('fails with missing canaries', async () => {
sinon.stub(fs, 'readFile')
.withArgs('/foo.json').resolves(JSON.stringify({
Dispatched: { TaskInfo: { Environment: { somekey: 'someval' } } },
}))
context('with missing canaries', () => {
it('fails', async () => {
sinon.stub(fs, 'readFile')
.withArgs('/foo.json').resolves(JSON.stringify({
Dispatched: { TaskInfo: { Environment: { somekey: 'someval' } } },
}))

try {
await _checkCanaries()
throw new Error('should not reach')
} catch (err) {
expect(err.message).to.include('Missing MAIN_CANARY')
}
})

context('with no circleEnv', () => {
beforeEach(() => {
sinon.stub(fs, 'readFile')
.withArgs('/foo.json').resolves(JSON.stringify({
Dispatched: { TaskInfo: { Environment: {} } },
}))
})

it('passes', async () => {
await _checkCanaries()
})

it('fails if CACHE_VERSION does exist', async () => {
process.env.CACHE_VERSION = 'foo'

try {
await _checkCanaries()
throw new Error('should not reach')
} catch (err) {
expect(err.message).to.include('Missing MAIN_CANARY')
}
try {
await _checkCanaries()
throw new Error('should not reach')
} catch (err) {
expect(err.message).to.include('CACHE_VERSION is set, but circleEnv is empty')
}
})
})
})

it('passes with canaries', async () => {
Expand Down

3 comments on commit 7a76de1

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7a76de1 May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.1/linux-x64/develop-7a76de10f88d3737fb0f46cfabe3b398af0a833f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7a76de1 May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.1/win32-x64/develop-7a76de10f88d3737fb0f46cfabe3b398af0a833f/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 7a76de1 May 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/9.6.1/darwin-x64/develop-7a76de10f88d3737fb0f46cfabe3b398af0a833f/cypress.tgz

Please sign in to comment.