Skip to content

Commit

Permalink
fix: provider name type
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 3, 2021
1 parent 9310fce commit 5681ed4
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { detectProvider } from './providers'
import { detectProvider, ProviderName } from './providers'

export type { ProviderName, ProviderInfo } from './providers'

Expand All @@ -11,7 +11,7 @@ const nodeENV = envShim.NODE_ENV || ''
export const platform = processShim.platform

/** Current current provider name */
export const provider = providerInfo.name
export const provider: ProviderName = providerInfo.name

/** Detect if `CI` environment variable is set or a provider CI detected */
export const isCI = toBoolean(envShim.CI) || providerInfo.ci !== false
Expand Down
93 changes: 51 additions & 42 deletions src/providers.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,60 @@
// Reference: https://github.com/watson/ci-info/blob/v3.2.0/vendors.json

type InternalProvider = [vendorName: string, envName?: string, meta?: Record<string, any>]

export type ProviderName =
'appveyor' | 'azure_pipelines' | 'azure_static' | 'appcircle' | 'bamboo' |
'bitbucket' | 'bitrise' | 'buddy' | 'buildkite' | 'circle' | 'cirrus' |
'codebuild' | 'codefresh' | 'drone' | 'drone' | 'dsari' | 'github_actions' |
'gitlab' | 'gitlab' | 'gocd' | 'layerci' | 'hudson' | 'jenkins' | 'magnum' |
'netlify' | 'netlify' | 'nevercode' | 'render' | 'sail' | 'semaphore' |
'screwdriver' | 'shippable' | 'solano' | 'strider' | 'teamcity' | 'travis' |
'vercel' | 'appcenter' | 'codesandbox' | 'stackblitz'

type InternalProvider = [providerName: Uppercase<ProviderName>, envName?: string, meta?: Record<string, any>]

const providers: InternalProvider[] = [
["APPVEYOR"],
["AZURE_PIPELINES", "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI"],
["AZURE_STATIC", "INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN"],
["APPCIRCLE", "AC_APPCIRCLE"],
["BAMBOO", "bamboo_planKey"],
["BITBUCKET", "BITBUCKET_COMMIT"],
["BITRISE", "BITRISE_IO"],
["BUDDY", "BUDDY_WORKSPACE_ID"],
["BUILDKITE"],
["CIRCLE", "CIRCLECI"],
["CIRRUS", "CIRRUS_CI"],
["CODEBUILD", "CODEBUILD_BUILD_ARN"],
["CODEFRESH", "CF_BUILD_ID"],
["DRONE"],
["DRONE", "DRONE_BUILD_EVENT"],
["DSARI"],
["GITHUB_ACTIONS"],
["GITLAB", "GITLAB_CI"],
["GITLAB", "CI_MERGE_REQUEST_ID"],
["GOCD", "GO_PIPELINE_LABEL"],
["LAYERCI"],
["HUDSON", "HUDSON_URL"],
["JENKINS", "JENKINS_URL"],
["MAGNUM"],
["NETLIFY"],
["NETLIFY", "NETLIFY_LOCAL", { ci: false }],
["NEVERCODE"],
["RENDER"],
["SAIL", "SAILCI"],
["SEMAPHORE"],
["SCREWDRIVER"],
["SHIPPABLE"],
["SOLANO", "TDDIUM"],
["STRIDER"],
["TEAMCITY", "TEAMCITY_VERSION"],
["TRAVIS"],
["VERCEL", "NOW_BUILDER"],
["APPCENTER", "APPCENTER_BUILD_ID"],
["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }],
["STACKBLITZ"],
['APPVEYOR'],
['AZURE_PIPELINES', 'SYSTEM_TEAMFOUNDATIONCOLLECTIONURI'],
['AZURE_STATIC', 'INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN'],
['APPCIRCLE', 'AC_APPCIRCLE'],
['BAMBOO', 'bamboo_planKey'],
['BITBUCKET', 'BITBUCKET_COMMIT'],
['BITRISE', 'BITRISE_IO'],
['BUDDY', 'BUDDY_WORKSPACE_ID'],
['BUILDKITE'],
['CIRCLE', 'CIRCLECI'],
['CIRRUS', 'CIRRUS_CI'],
['CODEBUILD', 'CODEBUILD_BUILD_ARN'],
['CODEFRESH', 'CF_BUILD_ID'],
['DRONE'],
['DRONE', 'DRONE_BUILD_EVENT'],
['DSARI'],
['GITHUB_ACTIONS'],
['GITLAB', 'GITLAB_CI'],
['GITLAB', 'CI_MERGE_REQUEST_ID'],
['GOCD', 'GO_PIPELINE_LABEL'],
['LAYERCI'],
['HUDSON', 'HUDSON_URL'],
['JENKINS', 'JENKINS_URL'],
['MAGNUM'],
['NETLIFY'],
['NETLIFY', 'NETLIFY_LOCAL', { ci: false }],
['NEVERCODE'],
['RENDER'],
['SAIL', 'SAILCI'],
['SEMAPHORE'],
['SCREWDRIVER'],
['SHIPPABLE'],
['SOLANO', 'TDDIUM'],
['STRIDER'],
['TEAMCITY', 'TEAMCITY_VERSION'],
['TRAVIS'],
['VERCEL', 'NOW_BUILDER'],
['APPCENTER', 'APPCENTER_BUILD_ID'],
['CODESANDBOX', 'CODESANDBOX_SSE', { ci: false }],
['STACKBLITZ'],
]

export type ProviderName = Lowercase<(typeof providers)[number][0]>
export type ProviderInfo = { name: ProviderName, [meta: string]: any }

export function detectProvider(env: Record<string, string>): ProviderInfo | null {
Expand Down

0 comments on commit 5681ed4

Please sign in to comment.