// Reference: https://github.com/watson/ci-info/blob/v3.2.0/vendors.json import { env, process } from "./env.ts"; /** * Represents the name of a CI/CD or Deployment provider. */ export type ProviderName = | (string & {}) | "appveyor" | "aws_amplify" | "azure_pipelines" | "azure_static" | "appcircle" | "bamboo" | "bitbucket" | "bitrise" | "buddy" | "buildkite" | "circle" | "cirrus" | "cloudflare_pages" | "cloudflare_workers" | "google_cloudrun" | "google_cloudrun_job" | "codebuild" | "codefresh" | "drone" | "drone" | "dsari" | "github_actions" | "gitlab" | "gocd" | "layerci" | "hudson" | "jenkins" | "magnum" | "netlify" | "nevercode" | "render" | "sail" | "semaphore" | "screwdriver" | "shippable" | "solano" | "strider" | "teamcity" | "travis" | "vercel" | "appcenter" | "codesandbox" | "stackblitz" | "stormkit" | "cleavr" | "zeabur" | "codesphere" | "railway" | "deno-deploy" | "firebase_app_hosting"; type InternalProvider = [ providerName: Uppercase, envName?: string, meta?: Record, ]; const providers: InternalProvider[] = [ ["APPVEYOR"], ["AWS_AMPLIFY", "AWS_APP_ID", { ci: true }], ["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"], ["CLOUDFLARE_PAGES", "CF_PAGES", { ci: true }], ["CLOUDFLARE_WORKERS", "WORKERS_CI", { ci: true }], ["GOOGLE_CLOUDRUN", "K_SERVICE"], ["GOOGLE_CLOUDRUN_JOB", "CLOUD_RUN_JOB"], ["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"], // Jenkins must be validated before Hudson ["JENKINS", "JENKINS_URL"], ["HUDSON", "HUDSON_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"], ["VERCEL", "VERCEL", { ci: false }], ["VERCEL", "VERCEL_ENV", { ci: false }], ["APPCENTER", "APPCENTER_BUILD_ID"], ["CODESANDBOX", "CODESANDBOX_SSE", { ci: false }], ["CODESANDBOX", "CODESANDBOX_HOST", { ci: false }], ["STACKBLITZ"], ["STORMKIT"], ["CLEAVR"], ["ZEABUR"], ["CODESPHERE", "CODESPHERE_APP_ID", { ci: true }], ["RAILWAY", "RAILWAY_PROJECT_ID"], ["RAILWAY", "RAILWAY_SERVICE_ID"], ["DENO-DEPLOY", "DENO_DEPLOY"], ["DENO-DEPLOY", "DENO_DEPLOYMENT_ID"], ["FIREBASE_APP_HOSTING", "FIREBASE_APP_HOSTING", { ci: true }], ]; /** * Provides information about a CI/CD or Deployment provider, including its name and possibly other metadata. */ export type ProviderInfo = { /** * The name of the CI/CD or Deployment provider. See {@link ProviderName} for possible values. */ name: ProviderName; /** * If is set to `true`, the environment is recognised as a CI/CD provider. */ ci?: boolean; /** * Arbitrary metadata associated with the provider. */ [meta: string]: any; }; /** * Detects the current CI/CD or Deployment provider from environment variables. */ export function detectProvider(): ProviderInfo { // Based on env for (const provider of providers) { const envName = provider[1] || provider[0]; if (env[envName]) { return { name: provider[0].toLowerCase(), ...(provider[2] as any), }; } } // Stackblitz / Webcontainer if (env.SHELL === "/bin/jsh" && process.versions?.webcontainer) { return { name: "stackblitz", ci: false, }; } return { name: "", ci: false, }; } /** * The detected provider information for the current execution context. * This value is evaluated once at module initialisation. */ export const providerInfo: ProviderInfo = /* #__PURE__ */ detectProvider(); /** * Name of the detected provider, defaults to an empty string if no provider is detected. */ export const provider: ProviderName = providerInfo.name;