fix: ci detection
This commit is contained in:
1 parent
b988b67118
commit
9475ed7689
3 files changed
+100
-4
No files matched your search
@@ -1,3 +1,5 @@
|
|||||||
|
const { isCI } = require("./util/is-cli")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const showAnalyticsNotification = require(`./util/show-notification`)
|
const showAnalyticsNotification = require(`./util/show-notification`)
|
||||||
const Store = require(`./store`)
|
const Store = require(`./store`)
|
||||||
@@ -5,7 +7,7 @@ try {
|
|||||||
const eventStorage = new Store()
|
const eventStorage = new Store()
|
||||||
const disabled = eventStorage.disabled_
|
const disabled = eventStorage.disabled_
|
||||||
const enabledInConfig = eventStorage.getConfig(`telemetry.enabled`)
|
const enabledInConfig = eventStorage.getConfig(`telemetry.enabled`)
|
||||||
if (enabledInConfig === undefined && !disabled) {
|
if (enabledInConfig === undefined && !disabled && !isCI()) {
|
||||||
showAnalyticsNotification()
|
showAnalyticsNotification()
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -5,9 +5,10 @@ import isDocker from "is-docker"
|
|||||||
import { v4 as uuidv4 } from "uuid"
|
import { v4 as uuidv4 } from "uuid"
|
||||||
|
|
||||||
import createFlush from "./util/create-flush"
|
import createFlush from "./util/create-flush"
|
||||||
import showAnalyticsNotification from "./util/show-notification"
|
|
||||||
import isTruthy from "./util/is-truthy"
|
|
||||||
import getTermProgram from "./util/get-term-program"
|
import getTermProgram from "./util/get-term-program"
|
||||||
|
import isTruthy from "./util/is-truthy"
|
||||||
|
import showAnalyticsNotification from "./util/show-notification"
|
||||||
|
import { isCI, getCIName } from "./util/is-cli"
|
||||||
import Store from "./store"
|
import Store from "./store"
|
||||||
|
|
||||||
const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false
|
const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false
|
||||||
@@ -45,7 +46,9 @@ class Telemeter {
|
|||||||
}
|
}
|
||||||
let enabled = this.store_.getConfig(`telemetry.enabled`)
|
let enabled = this.store_.getConfig(`telemetry.enabled`)
|
||||||
if (enabled === undefined || enabled === null) {
|
if (enabled === undefined || enabled === null) {
|
||||||
showAnalyticsNotification()
|
if (!isCI()) {
|
||||||
|
showAnalyticsNotification()
|
||||||
|
}
|
||||||
enabled = true
|
enabled = true
|
||||||
this.store_.setConfig(`telemetry.enabled`, enabled)
|
this.store_.setConfig(`telemetry.enabled`, enabled)
|
||||||
}
|
}
|
||||||
@@ -63,6 +66,8 @@ class Telemeter {
|
|||||||
platform: os.platform(),
|
platform: os.platform(),
|
||||||
release: os.release(),
|
release: os.release(),
|
||||||
cpus: (cpus && cpus.length > 0 && cpus[0].model) || undefined,
|
cpus: (cpus && cpus.length > 0 && cpus[0].model) || undefined,
|
||||||
|
is_ci: isCI(),
|
||||||
|
ci_name: getCIName(),
|
||||||
arch: os.arch(),
|
arch: os.arch(),
|
||||||
docker: isDocker(),
|
docker: isDocker(),
|
||||||
term_program: getTermProgram(),
|
term_program: getTermProgram(),
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import ci from "ci-info"
|
||||||
|
|
||||||
|
const CI_DEFINITIONS = [
|
||||||
|
getEnvDetect({ key: `NOW_BUILDER_ANNOTATE`, name: `ZEIT Now` }),
|
||||||
|
getEnvDetect({ key: `NOW_REGION`, name: `ZEIT Now v1` }),
|
||||||
|
getEnvDetect({ key: `VERCEL_URL`, name: `Vercel Now` }),
|
||||||
|
getEnvDetect({ key: `NOW_BUILDER`, name: `Vercel Now` }),
|
||||||
|
getEnvDetect({ key: `VERCEL_BUILDER`, name: `Vercel Now` }),
|
||||||
|
getEnvDetect({ key: `CODESANDBOX_SSE`, name: `CodeSandbox` }),
|
||||||
|
getEnvDetect({ key: `GITHUB_ACTIONS`, name: `GitHub Actions` }),
|
||||||
|
getEnvDetect({ key: `CIRCLE_BRANCH`, name: `CircleCI` }),
|
||||||
|
getEnvDetect({ key: `CIRCLECI`, name: `CircleCI` }),
|
||||||
|
envFromCIAndCIName,
|
||||||
|
herokuDetect,
|
||||||
|
getEnvFromCIInfo,
|
||||||
|
envFromCIWithNoName,
|
||||||
|
]
|
||||||
|
|
||||||
|
function lookupCI() {
|
||||||
|
for (const fn of CI_DEFINITIONS) {
|
||||||
|
try {
|
||||||
|
const res = fn()
|
||||||
|
if (res) {
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
const CIName = lookupCI()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether the environment where the code is running is in CI
|
||||||
|
* @return true if the environment is in CI, false otherwise
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function isCI() {
|
||||||
|
return !!CIName
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the name of the CI environment (e.g. "Vercel", "Heroku", etc.)
|
||||||
|
* @return The name of the CI if available. Defaults to null if not in CI
|
||||||
|
*/
|
||||||
|
|
||||||
|
export function getCIName() {
|
||||||
|
if (!isCI()) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return CIName
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEnvFromCIInfo() {
|
||||||
|
if (ci.isCI) return ci.name || `ci-info detected w/o name`
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEnvDetect({ key, name }) {
|
||||||
|
return function() {
|
||||||
|
if (process.env[key]) {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function herokuDetect() {
|
||||||
|
return (
|
||||||
|
typeof process.env.NODE === `string` &&
|
||||||
|
/\.heroku\/node\/bin\/node/.test(process.env.NODE) &&
|
||||||
|
`Heroku`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function envFromCIAndCIName() {
|
||||||
|
if (process.env.CI_NAME && process.env.CI) {
|
||||||
|
return process.env.CI_NAME
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
function envFromCIWithNoName() {
|
||||||
|
if (process.env.CI) {
|
||||||
|
return `CI detected without name`
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
Reference in new issue
Block a user