Skip to content

Commit d97bee6

Browse files
RobinCslGatsbyJS Bot
authored andcommitted
feat(gatsby-core-utils): Add isCI and getCIName (#19039)
Fixes #19018
1 parent 54565f0 commit d97bee6

File tree

14 files changed

+64
-20
lines changed

14 files changed

+64
-20
lines changed

packages/gatsby-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"better-opn": "^0.1.4",
1717
"bluebird": "^3.7.1",
1818
"chalk": "^2.4.2",
19-
"ci-info": "^2.0.0",
2019
"clipboardy": "^2.1.0",
2120
"common-tags": "^1.8.0",
2221
"configstore": "^5.0.0",
@@ -26,6 +25,7 @@
2625
"execa": "^2.1.0",
2726
"fs-exists-cached": "^1.0.0",
2827
"fs-extra": "^8.1.0",
28+
"gatsby-core-utils": "^1.0.15",
2929
"gatsby-telemetry": "^1.1.34",
3030
"hosted-git-info": "^3.0.2",
3131
"is-valid-path": "^0.1.1",

packages/gatsby-cli/src/reporter/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// @flow
22

33
const semver = require(`semver`)
4-
const { isCI } = require(`ci-info`)
4+
const { isCI } = require(`gatsby-core-utils`)
55
const signalExit = require(`signal-exit`)
66
const reporterActions = require(`./redux/actions`)
77

@@ -17,7 +17,7 @@ if (!process.env.GATSBY_LOGGER) {
1717
if (
1818
inkExists &&
1919
semver.satisfies(process.version, `>=8`) &&
20-
!isCI &&
20+
!isCI() &&
2121
typeof jest === `undefined`
2222
) {
2323
process.env.GATSBY_LOGGER = `ink`

packages/gatsby-cli/src/util/__tests__/is-tty.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,35 @@ describe(`isTTY`, () => {
1111

1212
it(`returns true if not on ci & TTY is enabled`, () => {
1313
process.stdout.isTTY = true
14-
jest.mock(`ci-info`, () => {
15-
return { isCI: false }
14+
jest.mock(`gatsby-core-utils`, () => {
15+
return { isCI: () => false }
1616
})
1717
const isTTY = require(`../is-tty`)
1818
expect(isTTY()).toBe(true)
1919
})
2020

2121
it(`returns false if not on ci & TTY is disabled`, () => {
2222
process.stdout.isTTY = false
23-
jest.mock(`ci-info`, () => {
24-
return { isCI: false }
23+
jest.mock(`gatsby-core-utils`, () => {
24+
return { isCI: () => false }
2525
})
2626
const isTTY = require(`../is-tty`)
2727
expect(isTTY()).toBe(false)
2828
})
2929

3030
it(`returns false if on ci & TTY is enabled`, () => {
3131
process.stdout.isTTY = true
32-
jest.mock(`ci-info`, () => {
33-
return { isCI: true }
32+
jest.mock(`gatsby-core-utils`, () => {
33+
return { isCI: () => true }
3434
})
3535
const isTTY = require(`../is-tty`)
3636
expect(isTTY()).toBe(false)
3737
})
3838

3939
it(`returns false if on ci & TTY is disabled`, () => {
4040
process.stdout.isTTY = false
41-
jest.mock(`ci-info`, () => {
42-
return { isCI: true }
41+
jest.mock(`gatsby-core-utils`, () => {
42+
return { isCI: () => true }
4343
})
4444
const isTTY = require(`../is-tty`)
4545
expect(isTTY()).toBe(false)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const isCI = require(`ci-info`).isCI
1+
const { isCI } = require(`gatsby-core-utils`)
22

33
// Some CI pipelines incorrectly report process.stdout.isTTY status,
44
// which causes unwanted lines in the output. An additional check for isCI helps.
55
// @see https://github.com/prettier/prettier/blob/36aeb4ce4f620023c8174e826d7208c0c64f1a0b/src/utils/is-tty.js
6-
module.exports = () => process.stdout.isTTY && !isCI
6+
module.exports = () => process.stdout.isTTY && !isCI()

packages/gatsby-core-utils/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,30 @@ const pathname = "./gatsby/is/awesome"
6363
const url = joinPath(BASEPATH, pathname)
6464
// ...
6565
```
66+
67+
### isCI
68+
69+
A utility that enhances `isCI` from 'ci-info` with support for ZEIT's Now and Heroku detection
70+
71+
```js
72+
const { isCI } = require("gatsby-core-utils")
73+
74+
if (isCI()) {
75+
// execute CI-specific code
76+
}
77+
// ...
78+
```
79+
80+
### getCIName
81+
82+
A utility that returns the name of the current CI environment if available, `null` otherwise
83+
84+
```js
85+
const { getCIName } = require("gatsby-core-utils")
86+
87+
const CI_NAME = getCIName()
88+
console.log({ CI_NAME })
89+
// {CI_NAME: null}, or
90+
// {CI_NAME: "ZEIT Now"}
91+
// ...
92+
```

packages/gatsby-core-utils/index.d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,15 @@ export declare function cpuCoreCount(ignoreEnvVar?: boolean): number
3131
* @param {string[]} segments A sequence of segments
3232
*/
3333
export declare function urlResolve(...segments: string[]): string
34+
35+
/**
36+
* Determines whether the environment where the code is running is in CI
37+
* @return {boolean} true if the environment is in CI, false otherwise
38+
*/
39+
export declare function isCI(): boolean
40+
41+
/**
42+
* Gets the name of the CI environment (e.g. "ZEIT Now", "Heroku", etc.)
43+
* @return {string | null} The name of the CI if available. Defaults to null if not in CI
44+
*/
45+
export declare function getCIName(): string | null

packages/gatsby-core-utils/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
"index.d.ts"
2929
],
3030
"types": "index.d.ts",
31+
"dependencies": {
32+
"ci-info": "2.0.0"
33+
},
3134
"devDependencies": {
3235
"@babel/cli": "^7.6.4",
3336
"@babel/core": "^7.6.4",
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)