From 24739b19981639a5c1a1b58cb4fd654a5092cf97 Mon Sep 17 00:00:00 2001 From: zhouganqing Date: Fri, 17 Feb 2023 09:41:43 +0800 Subject: [PATCH] Import Upstream version 3.2.0+~cs4.2.0 --- .../ISSUE_TEMPLATE/ci-server-not-detected.md | 33 + .github/workflows/tests.yml | 21 + .gitignore | 3 + .npmignore | 4 + CHANGELOG.md | 118 +++ LICENSE | 21 + README.md | 117 +++ index.d.ts | 62 ++ index.js | 66 ++ is-interactive/.editorconfig | 12 + is-interactive/.gitattributes | 1 + is-interactive/.github/funding.yml | 3 + is-interactive/.gitignore | 2 + is-interactive/.npmrc | 1 + is-interactive/.travis.yml | 5 + is-interactive/index.d.ts | 31 + is-interactive/index.js | 9 + is-interactive/index.test-d.ts | 6 + is-interactive/license | 9 + is-interactive/package.json | 38 + is-interactive/readme.md | 51 ++ is-interactive/test.js | 25 + is-unicode-supported/.editorconfig | 12 + is-unicode-supported/.gitattributes | 1 + .../.github/workflows/main.yml | 22 + is-unicode-supported/.gitignore | 2 + is-unicode-supported/.npmrc | 1 + is-unicode-supported/index.d.ts | 14 + is-unicode-supported/index.js | 13 + is-unicode-supported/index.test-d.ts | 4 + is-unicode-supported/license | 9 + is-unicode-supported/package.json | 41 + is-unicode-supported/readme.md | 35 + is-unicode-supported/test.js | 22 + package.json | 36 + test.js | 743 ++++++++++++++++++ types-ci-info/LICENSE | 21 + types-ci-info/README.md | 3 + types-ci-info/package.json | 13 + vendors.json | 205 +++++ 40 files changed, 1835 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/ci-server-not-detected.md create mode 100644 .github/workflows/tests.yml create mode 100644 .gitignore create mode 100644 .npmignore create mode 100644 CHANGELOG.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 index.d.ts create mode 100644 index.js create mode 100644 is-interactive/.editorconfig create mode 100644 is-interactive/.gitattributes create mode 100644 is-interactive/.github/funding.yml create mode 100644 is-interactive/.gitignore create mode 100644 is-interactive/.npmrc create mode 100644 is-interactive/.travis.yml create mode 100644 is-interactive/index.d.ts create mode 100644 is-interactive/index.js create mode 100644 is-interactive/index.test-d.ts create mode 100644 is-interactive/license create mode 100644 is-interactive/package.json create mode 100644 is-interactive/readme.md create mode 100644 is-interactive/test.js create mode 100644 is-unicode-supported/.editorconfig create mode 100644 is-unicode-supported/.gitattributes create mode 100644 is-unicode-supported/.github/workflows/main.yml create mode 100644 is-unicode-supported/.gitignore create mode 100644 is-unicode-supported/.npmrc create mode 100644 is-unicode-supported/index.d.ts create mode 100644 is-unicode-supported/index.js create mode 100644 is-unicode-supported/index.test-d.ts create mode 100644 is-unicode-supported/license create mode 100644 is-unicode-supported/package.json create mode 100644 is-unicode-supported/readme.md create mode 100644 is-unicode-supported/test.js create mode 100644 package.json create mode 100644 test.js create mode 100644 types-ci-info/LICENSE create mode 100644 types-ci-info/README.md create mode 100644 types-ci-info/package.json create mode 100644 vendors.json diff --git a/.github/ISSUE_TEMPLATE/ci-server-not-detected.md b/.github/ISSUE_TEMPLATE/ci-server-not-detected.md new file mode 100644 index 0000000..c55350b --- /dev/null +++ b/.github/ISSUE_TEMPLATE/ci-server-not-detected.md @@ -0,0 +1,33 @@ +--- +name: CI server not detected +about: Report an issue with detecting a specific CI server + +--- + + + +**Details:** + - Ci name: [e.g. Travis CI] + - Website: [e.g. https://travis-ci.com/] + - Default env variables: [e.g. https://docs.travis-ci.com/user/environment-variables/#default-environment-variables] + +**Environment variables** + + +
+Environment variables example + +``` +// Add a list of actual environment variables available to the build here +// Please keep the blank line above and below the code block +// WARNING: Be careful not to include any private or otherwise sensitive information +``` + +
+ +**Additional context** +Add any other context about the problem here. diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..815dc36 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,21 @@ +name: Tests + +on: [push, pull_request] + +jobs: + build: + + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [8.x, 10.x, 12.x, 14.x, 15.x, 16.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f846c68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +node_modules +package-lock.json +yarn.lock diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..c2ecad0 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +node_modules +.github +.travis.yml +test.js diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..4161320 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,118 @@ +# Changelog + +## v3.2.0 + +- support LayerCI ([#68](https://github.com/watson/ci-info/pull/68)) +- support Appcircle ([#69](https://github.com/watson/ci-info/pull/69)) +- support Codefresh CI ([#65](https://github.com/watson/ci-info/pull/65)) +- Add support for nodejs v16 + +## v3.1.1 + +Bug Fixes: + +- remove duplicate declaration in typings + +## v3.1.0 + +Features: + +- add typings + +## v3.0.0 + +Features: + +- Add support nodejs versions: 14, 15 +- support Nevercode ([#30](https://github.com/watson/ci-info/pull/30)) +- support Render CI ([#36](https://github.com/watson/ci-info/pull/36)) +- support Now CI ([#37](https://github.com/watson/ci-info/pull/37)) +- support GitLab PR ([#59](https://github.com/watson/ci-info/pull/59)) +- support Screwdriver CD ([#60](https://github.com/watson/ci-info/pull/60)) +- support Visual Studio App Center ([#61](https://github.com/watson/ci-info/pull/61)) + +Bug Fixes: + +- update Netlify env constant ([#47](https://github.com/watson/ci-info/pull/47)) + +Breaking changes: + +- Drop support for Node.js end-of-life versions: 6, 13 +- replace `Zeit Now` with `Vercel` ([#55](https://github.com/watson/ci-info/pull/55)) + +## v2.0.0 + +Breaking changes: + +- Drop support for Node.js end-of-life versions: 0.10, 0.12, 4, 5, 7, + and 9 +- Team Foundation Server will now be detected as Azure Pipelines. The + constant `ci.TFS` no longer exists - use `ci.AZURE_PIPELINES` instead +- Remove deprecated `ci.TDDIUM` constant - use `ci.SOLANDO` instead + +New features: + +- feat: support Azure Pipelines ([#23](https://github.com/watson/ci-info/pull/23)) +- feat: support Netlify CI ([#26](https://github.com/watson/ci-info/pull/26)) +- feat: support Bitbucket pipelines PR detection ([#27](https://github.com/watson/ci-info/pull/27)) + +## v1.6.0 + +- feat: add Sail CI support +- feat: add Buddy support +- feat: add Bitrise support +- feat: detect Jenkins PRs +- feat: detect Drone PRs + +## v1.5.1 + +- fix: use full path to vendors.json + +## v1.5.0 + +- feat: add dsari detection ([#15](https://github.com/watson/ci-info/pull/15)) +- feat: add ci.isPR ([#16](https://github.com/watson/ci-info/pull/16)) + +## v1.4.0 + +- feat: add Cirrus CI detection ([#13](https://github.com/watson/ci-info/pull/13)) +- feat: add Shippable CI detection ([#14](https://github.com/watson/ci-info/pull/14)) + +## v1.3.1 + +- chore: reduce npm package size by not including `.github` folder content ([#11](https://github.com/watson/ci-info/pull/11)) + +## v1.3.0 + +- feat: add support for Strider CD +- chore: deprecate vendor constant `TDDIUM` in favor of `SOLANO` +- docs: add missing vendor constant to docs + +## v1.2.0 + +- feat: detect solano-ci ([#9](https://github.com/watson/ci-info/pull/9)) + +## v1.1.3 + +- fix: fix spelling of Hunson in `ci.name` + +## v1.1.2 + +- fix: no more false positive matches for Jenkins + +## v1.1.1 + +- docs: sort lists of CI servers in README.md +- docs: add missing AWS CodeBuild to the docs + +## v1.1.0 + +- feat: add AWS CodeBuild to CI detection ([#2](https://github.com/watson/ci-info/pull/2)) + +## v1.0.1 + +- chore: reduce npm package size by using an `.npmignore` file ([#3](https://github.com/watson/ci-info/pull/3)) + +## v1.0.0 + +- Initial release diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2cc7405 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016-2021 Thomas Watson Steen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d73f258 --- /dev/null +++ b/README.md @@ -0,0 +1,117 @@ +# ci-info + +Get details about the current Continuous Integration environment. + +Please [open an +issue](https://github.com/watson/ci-info/issues/new?template=ci-server-not-detected.md) +if your CI server isn't properly detected :) + +[![npm](https://img.shields.io/npm/v/ci-info.svg)](https://www.npmjs.com/package/ci-info) +[![Tests](https://github.com/watson/ci-info/workflows/Tests/badge.svg)](https://github.com/watson/ci-info/actions) +[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard) + +## Installation + +```bash +npm install ci-info --save +``` + +## Usage + +```js +var ci = require('ci-info') + +if (ci.isCI) { + console.log('The name of the CI server is:', ci.name) +} else { + console.log('This program is not running on a CI server') +} +``` + +## Supported CI tools + +Officially supported CI servers: + +| Name | Constant | isPR | +| ------------------------------------------------------------------------------- | -------------------- | ---- | +| [AWS CodeBuild](https://aws.amazon.com/codebuild/) | `ci.CODEBUILD` | 🚫 | +| [AppVeyor](http://www.appveyor.com) | `ci.APPVEYOR` | ✅ | +| [Azure Pipelines](https://azure.microsoft.com/en-us/services/devops/pipelines/) | `ci.AZURE_PIPELINES` | ✅ | +| [Appcircle](https://appcircle.io/) | `ci.APPCIRCLE` | 🚫 | +| [Bamboo](https://www.atlassian.com/software/bamboo) by Atlassian | `ci.BAMBOO` | 🚫 | +| [Bitbucket Pipelines](https://bitbucket.org/product/features/pipelines) | `ci.BITBUCKET` | ✅ | +| [Bitrise](https://www.bitrise.io/) | `ci.BITRISE` | ✅ | +| [Buddy](https://buddy.works/) | `ci.BUDDY` | ✅ | +| [Buildkite](https://buildkite.com) | `ci.BUILDKITE` | ✅ | +| [CircleCI](http://circleci.com) | `ci.CIRCLE` | ✅ | +| [Cirrus CI](https://cirrus-ci.org) | `ci.CIRRUS` | ✅ | +| [Codefresh](https://codefresh.io/) | `ci.CODEFRESH` | ✅ | +| [Codeship](https://codeship.com) | `ci.CODESHIP` | 🚫 | +| [Drone](https://drone.io) | `ci.DRONE` | ✅ | +| [dsari](https://github.com/rfinnie/dsari) | `ci.DSARI` | 🚫 | +| [GitHub Actions](https://github.com/features/actions/) | `ci.GITHUB_ACTIONS` | ✅ | +| [GitLab CI](https://about.gitlab.com/gitlab-ci/) | `ci.GITLAB` | ✅ | +| [GoCD](https://www.go.cd/) | `ci.GOCD` | 🚫 | +| [Hudson](http://hudson-ci.org) | `ci.HUDSON` | 🚫 | +| [Jenkins CI](https://jenkins-ci.org) | `ci.JENKINS` | ✅ | +| [LayerCI](https://layerci.com/) | `ci.LAYERCI` | ✅ | +| [Magnum CI](https://magnum-ci.com) | `ci.MAGNUM` | 🚫 | +| [Netlify CI](https://www.netlify.com/) | `ci.NETLIFY` | ✅ | +| [Nevercode](http://nevercode.io/) | `ci.NEVERCODE` | ✅ | +| [Render](https://render.com/) | `ci.RENDER` | ✅ | +| [Sail CI](https://sail.ci/) | `ci.SAIL` | ✅ | +| [Screwdriver](https://screwdriver.cd/) | `ci.SCREWDRIVER` | ✅ | +| [Semaphore](https://semaphoreci.com) | `ci.SEMAPHORE` | ✅ | +| [Shippable](https://www.shippable.com/) | `ci.SHIPPABLE` | ✅ | +| [Solano CI](https://www.solanolabs.com/) | `ci.SOLANO` | ✅ | +| [Strider CD](https://strider-cd.github.io/) | `ci.STRIDER` | 🚫 | +| [TaskCluster](http://docs.taskcluster.net) | `ci.TASKCLUSTER` | 🚫 | +| [TeamCity](https://www.jetbrains.com/teamcity/) by JetBrains | `ci.TEAMCITY` | 🚫 | +| [Travis CI](http://travis-ci.org) | `ci.TRAVIS` | ✅ | +| [Vercel](https://vercel.com/) | `ci.VERCEL` | 🚫 | +| [Visual Studio App Center](https://appcenter.ms/) | `ci.APPCENTER` | 🚫 | + +## API + +### `ci.name` + +Returns a string containing name of the CI server the code is running on. +If CI server is not detected, it returns `null`. + +Don't depend on the value of this string not to change for a specific +vendor. If you find your self writing `ci.name === 'Travis CI'`, you +most likely want to use `ci.TRAVIS` instead. + +### `ci.isCI` + +Returns a boolean. Will be `true` if the code is running on a CI server, +otherwise `false`. + +Some CI servers not listed here might still trigger the `ci.isCI` +boolean to be set to `true` if they use certain vendor neutral +environment variables. In those cases `ci.name` will be `null` and no +vendor specific boolean will be set to `true`. + +### `ci.isPR` + +Returns a boolean if PR detection is supported for the current CI server. Will +be `true` if a PR is being tested, otherwise `false`. If PR detection is +not supported for the current CI server, the value will be `null`. + +### `ci.` + +A vendor specific boolean constant is exposed for each support CI +vendor. A constant will be `true` if the code is determined to run on +the given CI server, otherwise `false`. + +Examples of vendor constants are `ci.TRAVIS` or `ci.APPVEYOR`. For a +complete list, see the support table above. + +Deprecated vendor constants that will be removed in the next major +release: + +- `ci.TDDIUM` (Solano CI) This have been renamed `ci.SOLANO` + +## License + +[MIT](LICENSE) diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..04f79c6 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,62 @@ +/** + * Returns a boolean. Will be `true` if the code is running on a CI server, + * otherwise `false`. + * + * Some CI servers not listed here might still trigger the `ci.isCI` + * boolean to be set to `true` if they use certain vendor neutral environment + * variables. In those cases `ci.name` will be `null` and no vendor specific + * boolean will be set to `true`. + */ +export const isCI: boolean; +/** + * Returns a boolean if PR detection is supported for the current CI server. + * Will be `true` if a PR is being tested, otherwise `false`. If PR detection is + * not supported for the current CI server, the value will be `null`. + */ +export const isPR: boolean | null; +/** + * Returns a string containing name of the CI server the code is running on. If + * CI server is not detected, it returns `null`. + * + * Don't depend on the value of this string not to change for a specific vendor. + * If you find your self writing `ci.name === 'Travis CI'`, you most likely want + * to use `ci.TRAVIS` instead. + */ +export const name: string | null; + +export const APPVEYOR: boolean; +export const AZURE_PIPELINES: boolean; +export const APPCIRCLE: boolean; +export const BAMBOO: boolean; +export const BITBUCKET: boolean; +export const BITRISE: boolean; +export const BUDDY: boolean; +export const BUILDKITE: boolean; +export const CIRCLE: boolean; +export const CIRRUS: boolean; +export const CODEBUILD: boolean; +export const CODEFRESH: boolean; +export const CODESHIP: boolean; +export const DRONE: boolean; +export const DSARI: boolean; +export const GITHUB_ACTIONS: boolean; +export const GITLAB: boolean; +export const GOCD: boolean; +export const HUDSON: boolean; +export const JENKINS: boolean; +export const LAYERCI: boolean; +export const MAGNUM: boolean; +export const NETLIFY: boolean; +export const NEVERCODE: boolean; +export const RENDER: boolean; +export const SAIL: boolean; +export const SEMAPHORE: boolean; +export const SCREWDRIVER: boolean; +export const SHIPPABLE: boolean; +export const SOLANO: boolean; +export const STRIDER: boolean; +export const TASKCLUSTER: boolean; +export const TEAMCITY: boolean; +export const TRAVIS: boolean; +export const VERCEL: boolean; +export const APPCENTER: boolean; diff --git a/index.js b/index.js new file mode 100644 index 0000000..b747a89 --- /dev/null +++ b/index.js @@ -0,0 +1,66 @@ +'use strict' + +const vendors = require('./vendors.json') + +const env = process.env + +// Used for testing only +Object.defineProperty(exports, '_vendors', { + value: vendors.map(function (v) { return v.constant }) +}) + +exports.name = null +exports.isPR = null + +vendors.forEach(function (vendor) { + const envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env] + const isCI = envs.every(function (obj) { + return checkEnv(obj) + }) + + exports[vendor.constant] = isCI + + if (isCI) { + exports.name = vendor.name + + switch (typeof vendor.pr) { + case 'string': + // "pr": "CIRRUS_PR" + exports.isPR = !!env[vendor.pr] + break + case 'object': + if ('env' in vendor.pr) { + // "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" } + exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne + } else if ('any' in vendor.pr) { + // "pr": { "any": ["ghprbPullId", "CHANGE_ID"] } + exports.isPR = vendor.pr.any.some(function (key) { + return !!env[key] + }) + } else { + // "pr": { "DRONE_BUILD_EVENT": "pull_request" } + exports.isPR = checkEnv(vendor.pr) + } + break + default: + // PR detection not supported for this vendor + exports.isPR = null + } + } +}) + +exports.isCI = !!( + env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari + env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI + env.BUILD_NUMBER || // Jenkins, TeamCity + env.RUN_ID || // TaskCluster, dsari + exports.name || + false +) + +function checkEnv (obj) { + if (typeof obj === 'string') return !!env[obj] + return Object.keys(obj).every(function (k) { + return env[k] === obj[k] + }) +} diff --git a/is-interactive/.editorconfig b/is-interactive/.editorconfig new file mode 100644 index 0000000..1c6314a --- /dev/null +++ b/is-interactive/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/is-interactive/.gitattributes b/is-interactive/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/is-interactive/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/is-interactive/.github/funding.yml b/is-interactive/.github/funding.yml new file mode 100644 index 0000000..1a630e9 --- /dev/null +++ b/is-interactive/.github/funding.yml @@ -0,0 +1,3 @@ +github: sindresorhus +open_collective: sindresorhus +custom: https://sindresorhus.com/donate diff --git a/is-interactive/.gitignore b/is-interactive/.gitignore new file mode 100644 index 0000000..239ecff --- /dev/null +++ b/is-interactive/.gitignore @@ -0,0 +1,2 @@ +node_modules +yarn.lock diff --git a/is-interactive/.npmrc b/is-interactive/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/is-interactive/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/is-interactive/.travis.yml b/is-interactive/.travis.yml new file mode 100644 index 0000000..f98fed0 --- /dev/null +++ b/is-interactive/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - '12' + - '10' + - '8' diff --git a/is-interactive/index.d.ts b/is-interactive/index.d.ts new file mode 100644 index 0000000..5984dc6 --- /dev/null +++ b/is-interactive/index.d.ts @@ -0,0 +1,31 @@ +/// + +declare namespace isInteractive { + interface Options { + /** + The stream to check. + + @default process.stdout + */ + readonly stream?: NodeJS.WritableStream; + } +} + +/** +Check if stdout or stderr is [interactive](https://unix.stackexchange.com/a/43389/7678). + +It checks that the stream is [TTY](https://jameshfisher.com/2017/12/09/what-is-a-tty/), not a dumb terminal, and not running in a CI. + +This can be useful to decide whether to present interactive UI or animations in the terminal. + +@example +``` +import isInteractive = require('is-interactive'); + +isInteractive(); +//=> true +``` +*/ +declare function isInteractive(options?: isInteractive.Options): boolean; + +export = isInteractive; diff --git a/is-interactive/index.js b/is-interactive/index.js new file mode 100644 index 0000000..99ff823 --- /dev/null +++ b/is-interactive/index.js @@ -0,0 +1,9 @@ +'use strict'; + +module.exports = ({stream = process.stdout} = {}) => { + return Boolean( + stream && stream.isTTY && + process.env.TERM !== 'dumb' && + !('CI' in process.env) + ); +}; diff --git a/is-interactive/index.test-d.ts b/is-interactive/index.test-d.ts new file mode 100644 index 0000000..c108bd0 --- /dev/null +++ b/is-interactive/index.test-d.ts @@ -0,0 +1,6 @@ +import {expectType} from 'tsd'; +import isInteractive = require('.'); + +expectType(isInteractive({ + stream: process.stderr +})); diff --git a/is-interactive/license b/is-interactive/license new file mode 100644 index 0000000..e7af2f7 --- /dev/null +++ b/is-interactive/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/is-interactive/package.json b/is-interactive/package.json new file mode 100644 index 0000000..dc758c6 --- /dev/null +++ b/is-interactive/package.json @@ -0,0 +1,38 @@ +{ + "name": "is-interactive", + "version": "1.0.0", + "description": "Check if stdout or stderr is interactive", + "license": "MIT", + "repository": "sindresorhus/is-interactive", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "interactive", + "stdout", + "stderr", + "detect", + "is", + "terminal", + "shell", + "tty" + ], + "devDependencies": { + "@types/node": "^12.0.12", + "ava": "^2.1.0", + "tsd": "^0.7.3", + "xo": "^0.24.0" + } +} diff --git a/is-interactive/readme.md b/is-interactive/readme.md new file mode 100644 index 0000000..49a8598 --- /dev/null +++ b/is-interactive/readme.md @@ -0,0 +1,51 @@ +# is-interactive [![Build Status](https://travis-ci.com/sindresorhus/is-interactive.svg?branch=master)](https://travis-ci.com/sindresorhus/is-interactive) + +> Check if stdout or stderr is [interactive](https://unix.stackexchange.com/a/43389/7678) + +It checks that the stream is [TTY](https://jameshfisher.com/2017/12/09/what-is-a-tty/), not a dumb terminal, and not running in a CI. + +This can be useful to decide whether to present interactive UI or animations in the terminal. + + +## Install + +``` +$ npm install is-interactive +``` + + +## Usage + +```js +const isInteractive = require('is-interactive'); + +isInteractive(); +//=> true +``` + + +## API + +### isInteractive(options?) + +#### options + +Type: `object` + +##### stream + +Type: [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable)
+Default: [`process.stdout`](https://nodejs.org/api/process.html#process_process_stdout) + +The stream to check. + + +## FAQ + +#### Why are you not using [`ci-info`](https://github.com/watson/ci-info) for the CI check? + +It's silly to have to detect individual CIs. They should identify themselves with the `CI` environment variable, and most do just that. A manually maintained list of detections will easily get out of date. And if a package using `ci-info` doesn't update to the latest version all the time, they will not support certain CIs. It also creates unpredictability as you might assume a CI is not supported and then suddenly it gets supported and you didn't account for that. In addition, some of the manual detections are loose and might cause false-positives which could create hard-to-debug bugs. + +#### Why does this even exist? It's just a few lines. + +It's not about the number of lines, but rather discoverability and documentation. A lot of people wouldn't even know they need this. Feel free to copy-paste the code if you don't want the dependency. You might also want to read [this blog post](https://blog.sindresorhus.com/small-focused-modules-9238d977a92a). diff --git a/is-interactive/test.js b/is-interactive/test.js new file mode 100644 index 0000000..12ddfde --- /dev/null +++ b/is-interactive/test.js @@ -0,0 +1,25 @@ +import {PassThrough as PassThroughStream} from 'stream'; +import test from 'ava'; +import isInteractive from '.'; + +test('tty', t => { + const ci = process.env.CI; + delete process.env.CI; + const stream = new PassThroughStream(); + stream.isTTY = true; + t.true(isInteractive({stream})); + process.env.CI = ci; +}); + +test('non-tty', t => { + const stream = new PassThroughStream(); + stream.isTTY = false; + t.false(isInteractive({stream})); +}); + +test('dumb', t => { + const term = process.env.TERM; + process.env.TERM = 'dumb'; + t.false(isInteractive()); + process.env.TERM = term; +}); diff --git a/is-unicode-supported/.editorconfig b/is-unicode-supported/.editorconfig new file mode 100644 index 0000000..1c6314a --- /dev/null +++ b/is-unicode-supported/.editorconfig @@ -0,0 +1,12 @@ +root = true + +[*] +indent_style = tab +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.yml] +indent_style = space +indent_size = 2 diff --git a/is-unicode-supported/.gitattributes b/is-unicode-supported/.gitattributes new file mode 100644 index 0000000..6313b56 --- /dev/null +++ b/is-unicode-supported/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/is-unicode-supported/.github/workflows/main.yml b/is-unicode-supported/.github/workflows/main.yml new file mode 100644 index 0000000..c1870cf --- /dev/null +++ b/is-unicode-supported/.github/workflows/main.yml @@ -0,0 +1,22 @@ +name: CI +on: + - push + - pull_request +jobs: + test: + name: Node.js ${{ matrix.node-version }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + node-version: + - 14 + - 12 + - 10 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test diff --git a/is-unicode-supported/.gitignore b/is-unicode-supported/.gitignore new file mode 100644 index 0000000..239ecff --- /dev/null +++ b/is-unicode-supported/.gitignore @@ -0,0 +1,2 @@ +node_modules +yarn.lock diff --git a/is-unicode-supported/.npmrc b/is-unicode-supported/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/is-unicode-supported/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/is-unicode-supported/index.d.ts b/is-unicode-supported/index.d.ts new file mode 100644 index 0000000..275b37b --- /dev/null +++ b/is-unicode-supported/index.d.ts @@ -0,0 +1,14 @@ +/** +Detect whether the terminal supports Unicode. + +@example +``` +import isUnicodeSupported = require('is-unicode-supported'); + +isUnicodeSupported(); +//=> true +``` +*/ +declare function isUnicodeSupported(): boolean; + +export = isUnicodeSupported; diff --git a/is-unicode-supported/index.js b/is-unicode-supported/index.js new file mode 100644 index 0000000..b5a11be --- /dev/null +++ b/is-unicode-supported/index.js @@ -0,0 +1,13 @@ +'use strict'; + +module.exports = () => { + if (process.platform !== 'win32') { + return true; + } + + return Boolean(process.env.CI) || + Boolean(process.env.WT_SESSION) || // Windows Terminal + process.env.TERM_PROGRAM === 'vscode' || + process.env.TERM === 'xterm-256color' || + process.env.TERM === 'alacritty'; +}; diff --git a/is-unicode-supported/index.test-d.ts b/is-unicode-supported/index.test-d.ts new file mode 100644 index 0000000..636ca56 --- /dev/null +++ b/is-unicode-supported/index.test-d.ts @@ -0,0 +1,4 @@ +import {expectType} from 'tsd'; +import isUnicodeSupported = require('.'); + +expectType(isUnicodeSupported()); diff --git a/is-unicode-supported/license b/is-unicode-supported/license new file mode 100644 index 0000000..fa7ceba --- /dev/null +++ b/is-unicode-supported/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus (https://sindresorhus.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/is-unicode-supported/package.json b/is-unicode-supported/package.json new file mode 100644 index 0000000..17e4035 --- /dev/null +++ b/is-unicode-supported/package.json @@ -0,0 +1,41 @@ +{ + "name": "is-unicode-supported", + "version": "0.1.0", + "description": "Detect whether the terminal supports Unicode", + "license": "MIT", + "repository": "sindresorhus/is-unicode-supported", + "funding": "https://github.com/sponsors/sindresorhus", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "https://sindresorhus.com" + }, + "engines": { + "node": ">=10" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "terminal", + "unicode", + "detect", + "utf8", + "console", + "shell", + "support", + "supports", + "supported", + "check", + "detection" + ], + "devDependencies": { + "ava": "^2.4.0", + "tsd": "^0.14.0", + "xo": "^0.38.2" + } +} diff --git a/is-unicode-supported/readme.md b/is-unicode-supported/readme.md new file mode 100644 index 0000000..a82e34d --- /dev/null +++ b/is-unicode-supported/readme.md @@ -0,0 +1,35 @@ +# is-unicode-supported + +> Detect whether the terminal supports Unicode + +This can be useful to decide whether to use Unicode characters or fallback ASCII characters in command-line output. + +Note that the check is quite naive. It just assumes all non-Windows terminals support Unicode and hard-codes which Windows terminals that do support Unicode. However, I have been using this logic in some popular packages for years without problems. + +## Install + +``` +$ npm install is-unicode-supported +``` + +## Usage + +```js +const isUnicodeSupported = require('is-unicode-supported'); + +isUnicodeSupported(); +//=> true +``` + +## API + +### isUnicodeSupported() + +Returns a `boolean` for whether the terminal supports Unicode. + +## Related + +- [is-interactive](https://github.com/sindresorhus/is-interactive) - Check if stdout or stderr is interactive +- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color +- [figures](https://github.com/sindresorhus/figures) - Unicode symbols with Windows fallbacks +- [log-symbols](https://github.com/sindresorhus/log-symbols) - Colored symbols for various log levels diff --git a/is-unicode-supported/test.js b/is-unicode-supported/test.js new file mode 100644 index 0000000..6f0f6dd --- /dev/null +++ b/is-unicode-supported/test.js @@ -0,0 +1,22 @@ +import test from 'ava'; +import isUnicodeSupported from './index.js'; + +test.serial('main', t => { + t.true(isUnicodeSupported()); +}); + +test.serial('windows', t => { + delete process.env.CI; + delete process.env.TERM; + delete process.env.TERM_PROGRAM; + + const originalPlatform = process.platform; + + Object.defineProperty(process, 'platform', {value: 'win32'}); + t.false(isUnicodeSupported()); + process.env.WT_SESSION = '1'; + t.true(isUnicodeSupported()); + + Object.defineProperty(process, 'platform', {value: originalPlatform}); + delete process.env.WT_SESSION; +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..500b851 --- /dev/null +++ b/package.json @@ -0,0 +1,36 @@ +{ + "name": "ci-info", + "version": "3.2.0", + "description": "Get details about the current Continuous Integration environment", + "main": "index.js", + "typings": "index.d.ts", + "author": "Thomas Watson Steen (https://twitter.com/wa7son)", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/watson/ci-info.git" + }, + "bugs": { + "url": "https://github.com/watson/ci-info/issues" + }, + "homepage": "https://github.com/watson/ci-info", + "keywords": [ + "ci", + "continuous", + "integration", + "test", + "detect" + ], + "coordinates": [ + 55.778231, + 12.593179 + ], + "scripts": { + "test": "standard && node test.js" + }, + "devDependencies": { + "clear-module": "^4.1.1", + "standard": "^16.0.3", + "tape": "^5.2.2" + } +} diff --git a/test.js b/test.js new file mode 100644 index 0000000..837340b --- /dev/null +++ b/test.js @@ -0,0 +1,743 @@ +'use strict' + +const test = require('tape') +const clearModule = require('clear-module') + +const isActualPR = !!(process.env.GITHUB_EVENT_NAME && process.env.GITHUB_EVENT_NAME === 'pull_request') + +test('Known CI', function (t) { + process.env.GITHUB_ACTIONS = 'true' + + const ci = require('./') + + t.ok(Array.isArray(ci._vendors)) + t.ok(ci._vendors.length > 0) + + t.equal(ci.isCI, true) + t.equal(ci.isPR, isActualPR) + t.equal(ci.name, 'GitHub Actions') + t.equal(ci.GITHUB_ACTIONS, true) + assertVendorConstants('GITHUB_ACTIONS', ci, t) + + t.end() +}) + +test('Not CI', function (t) { + delete process.env.CI + delete process.env.CONTINUOUS_INTEGRATION + delete process.env.BUILD_NUMBER + delete process.env.TRAVIS + delete process.env.GITHUB_ACTIONS + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, false) + t.equal(ci.isPR, null) + t.equal(ci.name, null) + t.equal(ci.TRAVIS, false) + assertVendorConstants(null, ci, t) + + t.end() +}) + +test('Unknown CI', function (t) { + process.env.CI = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, null) + t.equal(ci.name, null) + t.equal(ci.TRAVIS, false) + assertVendorConstants(null, ci, t) + + t.end() +}) + +test('AppVeyor - PR', function (t) { + process.env.APPVEYOR = 'true' + process.env.APPVEYOR_PULL_REQUEST_NUMBER = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'AppVeyor') + t.equal(ci.APPVEYOR, true) + assertVendorConstants('APPVEYOR', ci, t) + + delete process.env.APPVEYOR + delete process.env.APPVEYOR_PULL_REQUEST_NUMBER + + t.end() +}) + +test('AppVeyor - Not PR', function (t) { + process.env.APPVEYOR = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'AppVeyor') + t.equal(ci.APPVEYOR, true) + assertVendorConstants('APPVEYOR', ci, t) + + delete process.env.APPVEYOR + + t.end() +}) + +test('Azure Pipelines - PR', function (t) { + process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = 'https://dev.azure.com/Contoso' + process.env.SYSTEM_PULLREQUEST_PULLREQUESTID = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Azure Pipelines') + t.equal(ci.AZURE_PIPELINES, true) + assertVendorConstants('AZURE_PIPELINES', ci, t) + + delete process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + delete process.env.SYSTEM_PULLREQUEST_PULLREQUESTID + + t.end() +}) + +test('Azure Pipelines - Not PR', function (t) { + process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI = 'https://dev.azure.com/Contoso' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Azure Pipelines') + t.equal(ci.AZURE_PIPELINES, true) + assertVendorConstants('AZURE_PIPELINES', ci, t) + + delete process.env.SYSTEM_TEAMFOUNDATIONCOLLECTIONURI + + t.end() +}) + +test('Bitbucket Pipelines - PR', function (t) { + process.env.BITBUCKET_COMMIT = 'true' + process.env.BITBUCKET_PR_ID = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Bitbucket Pipelines') + t.equal(ci.BITBUCKET, true) + assertVendorConstants('BITBUCKET', ci, t) + + delete process.env.BITBUCKET_COMMIT + delete process.env.BITBUCKET_PR_ID + + t.end() +}) + +test('Bitbucket Pipelines - Not PR', function (t) { + process.env.BITBUCKET_COMMIT = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Bitbucket Pipelines') + t.equal(ci.BITBUCKET, true) + assertVendorConstants('BITBUCKET', ci, t) + + delete process.env.BITBUCKET_COMMIT + + t.end() +}) + +test('Buildkite - PR', function (t) { + process.env.BUILDKITE = 'true' + process.env.BUILDKITE_PULL_REQUEST = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Buildkite') + t.equal(ci.BUILDKITE, true) + assertVendorConstants('BUILDKITE', ci, t) + + delete process.env.BUILDKITE + delete process.env.BUILDKITE_PULL_REQUEST + + t.end() +}) + +test('Buildkite - Not PR', function (t) { + process.env.BUILDKITE = 'true' + process.env.BUILDKITE_PULL_REQUEST = 'false' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Buildkite') + t.equal(ci.BUILDKITE, true) + assertVendorConstants('BUILDKITE', ci, t) + + delete process.env.BUILDKITE + delete process.env.BUILDKITE_PULL_REQUEST + + t.end() +}) + +test('CircleCI - PR', function (t) { + process.env.CIRCLECI = 'true' + process.env.CIRCLE_PULL_REQUEST = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'CircleCI') + t.equal(ci.CIRCLE, true) + assertVendorConstants('CIRCLE', ci, t) + + delete process.env.CIRCLECI + delete process.env.CIRCLE_PULL_REQUEST + + t.end() +}) + +test('CircleCI - Not PR', function (t) { + process.env.CIRCLECI = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'CircleCI') + t.equal(ci.CIRCLE, true) + assertVendorConstants('CIRCLE', ci, t) + + delete process.env.CIRCLECI + + t.end() +}) + +test('Cirrus CI - PR', function (t) { + process.env.CIRRUS_CI = 'true' + process.env.CIRRUS_PR = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Cirrus CI') + t.equal(ci.CIRRUS, true) + assertVendorConstants('CIRRUS', ci, t) + + delete process.env.CIRRUS_CI + delete process.env.CIRRUS_PR + + t.end() +}) + +test('Cirrus CI - Not PR', function (t) { + process.env.CIRRUS_CI = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Cirrus CI') + t.equal(ci.CIRRUS, true) + assertVendorConstants('CIRRUS', ci, t) + + delete process.env.CIRRUS_CI + + t.end() +}) + +test('Codefresh - PR', function (t) { + process.env.CF_BUILD_ID = 'true' + process.env.CF_PULL_REQUEST_ID = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Codefresh') + t.equal(ci.CODEFRESH, true) + assertVendorConstants('CODEFRESH', ci, t) + + delete process.env.CF_BUILD_ID + delete process.env.CF_PULL_REQUEST_ID + + t.end() +}) + +test('Codefresh - Not PR', function (t) { + process.env.CF_BUILD_ID = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Codefresh') + t.equal(ci.CODEFRESH, true) + assertVendorConstants('CODEFRESH', ci, t) + + delete process.env.CF_BUILD_ID + + t.end() +}) + +test('LayerCI - PR', function (t) { + process.env.LAYERCI = 'true' + process.env.LAYERCI_PULL_REQUEST = 'https://link-to-pr/5' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'LayerCI') + t.equal(ci.LAYERCI, true) + assertVendorConstants('LAYERCI', ci, t) + + delete process.env.LAYERCI + delete process.env.LAYERCI_PULL_REQUEST + + t.end() +}) + +test('LayerCI - Not PR', function (t) { + process.env.LAYERCI = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'LayerCI') + t.equal(ci.LAYERCI, true) + assertVendorConstants('LAYERCI', ci, t) + + delete process.env.LAYERCI + + t.end() +}) + +test('Appcircle', function (t) { + process.env.AC_APPCIRCLE = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.name, 'Appcircle') + t.equal(ci.APPCIRCLE, true) + assertVendorConstants('APPCIRCLE', ci, t) + + delete process.env.AC_APPCIRCLE + + t.end() +}) + +test('Render - PR', function (t) { + process.env.RENDER = 'true' + process.env.IS_PULL_REQUEST = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Render') + t.equal(ci.RENDER, true) + assertVendorConstants('RENDER', ci, t) + + delete process.env.RENDER + delete process.env.IS_PULL_REQUEST + + t.end() +}) + +test('Render - Not PR', function (t) { + process.env.RENDER = 'true' + process.env.IS_PULL_REQUEST = 'false' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Render') + t.equal(ci.RENDER, true) + assertVendorConstants('RENDER', ci, t) + + delete process.env.RENDER + delete process.env.IS_PULL_REQUEST + + t.end() +}) + +test('Semaphore - PR', function (t) { + process.env.SEMAPHORE = 'true' + process.env.PULL_REQUEST_NUMBER = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Semaphore') + t.equal(ci.SEMAPHORE, true) + assertVendorConstants('SEMAPHORE', ci, t) + + delete process.env.SEMAPHORE + delete process.env.PULL_REQUEST_NUMBER + + t.end() +}) + +test('Semaphore - Not PR', function (t) { + process.env.SEMAPHORE = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Semaphore') + t.equal(ci.SEMAPHORE, true) + assertVendorConstants('SEMAPHORE', ci, t) + + delete process.env.SEMAPHORE + + t.end() +}) + +test('Shippable - PR', function (t) { + process.env.SHIPPABLE = 'true' + process.env.IS_PULL_REQUEST = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Shippable') + t.equal(ci.SHIPPABLE, true) + assertVendorConstants('SHIPPABLE', ci, t) + + delete process.env.SHIPPABLE + delete process.env.IS_PULL_REQUEST + + t.end() +}) + +test('Semaphore - Not PR', function (t) { + process.env.SHIPPABLE = 'true' + process.env.IS_PULL_REQUEST = 'false' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Shippable') + t.equal(ci.SHIPPABLE, true) + assertVendorConstants('SHIPPABLE', ci, t) + + delete process.env.SHIPPABLE + delete process.env.IS_PULL_REQUEST + + t.end() +}) + +test('Solano CI - PR', function (t) { + process.env.TDDIUM = 'true' + process.env.TDDIUM_PR_ID = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Solano CI') + t.equal(ci.SOLANO, true) + assertVendorConstants('SOLANO', ci, t) + + delete process.env.TDDIUM + delete process.env.TDDIUM_PR_ID + + t.end() +}) + +test('Solano CI - Not PR', function (t) { + process.env.TDDIUM = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Solano CI') + t.equal(ci.SOLANO, true) + assertVendorConstants('SOLANO', ci, t) + + delete process.env.TDDIUM + + t.end() +}) + +test('Travis CI - PR', function (t) { + process.env.TRAVIS = 'true' + process.env.TRAVIS_PULL_REQUEST = '42' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Travis CI') + t.equal(ci.TRAVIS, true) + assertVendorConstants('TRAVIS', ci, t) + + delete process.env.TRAVIS + delete process.env.TRAVIS_PULL_REQUEST + + t.end() +}) + +test('Travis CI - Not PR', function (t) { + process.env.TRAVIS = 'true' + process.env.TRAVIS_PULL_REQUEST = 'false' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Travis CI') + t.equal(ci.TRAVIS, true) + assertVendorConstants('TRAVIS', ci, t) + + delete process.env.TRAVIS + delete process.env.TRAVIS_PULL_REQUEST + + t.end() +}) + +test('Netlify CI - PR', function (t) { + process.env.NETLIFY = 'true' + process.env.PULL_REQUEST = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Netlify CI') + t.equal(ci.NETLIFY, true) + assertVendorConstants('NETLIFY', ci, t) + + delete process.env.NETLIFY + delete process.env.PULL_REQUEST + + t.end() +}) + +test('Netlify CI - Not PR', function (t) { + process.env.NETLIFY = 'true' + process.env.PULL_REQUEST = 'false' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Netlify CI') + t.equal(ci.NETLIFY, true) + assertVendorConstants('NETLIFY', ci, t) + + delete process.env.NETLIFY + delete process.env.PULL_REQUEST + + t.end() +}) + +test('Vercel', function (t) { + process.env.NOW_BUILDER = '1' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, null) + t.equal(ci.name, 'Vercel') + t.equal(ci.VERCEL, true) + assertVendorConstants('VERCEL', ci, t) + + delete process.env.NOW_BUILDER + + t.end() +}) + +test('Nevercode - PR', function (t) { + process.env.NEVERCODE = 'true' + process.env.NEVERCODE_PULL_REQUEST = 'true' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Nevercode') + t.equal(ci.NEVERCODE, true) + assertVendorConstants('NEVERCODE', ci, t) + + delete process.env.NEVERCODE + delete process.env.NEVERCODE_PULL_REQUEST + + t.end() +}) + +test('Nevercode - Not PR', function (t) { + process.env.NEVERCODE = 'true' + process.env.NEVERCODE_PULL_REQUEST = 'false' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Nevercode') + t.equal(ci.NEVERCODE, true) + assertVendorConstants('NEVERCODE', ci, t) + + delete process.env.NEVERCODE + delete process.env.NEVERCODE_PULL_REQUEST + + t.end() +}) + +test('GitHub Actions - PR', function (t) { + process.env.GITHUB_ACTIONS = 'true' + process.env.GITHUB_EVENT_NAME = 'pull_request' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'GitHub Actions') + t.equal(ci.GITHUB_ACTIONS, true) + assertVendorConstants('GITHUB_ACTIONS', ci, t) + + delete process.env.GITHUB_ACTIONS + delete process.env.GITHUB_EVENT_NAME + + t.end() +}) + +test('GitHub Actions - Not PR', function (t) { + process.env.GITHUB_ACTIONS = 'true' + process.env.GITHUB_EVENT_NAME = 'push' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'GitHub Actions') + t.equal(ci.GITHUB_ACTIONS, true) + assertVendorConstants('GITHUB_ACTIONS', ci, t) + + delete process.env.GITHUB_ACTIONS + delete process.env.GITHUB_EVENT_NAME + + t.end() +}) + +test('Screwdriver - PR', function (t) { + process.env.SCREWDRIVER = 'true' + process.env.SD_PULL_REQUEST = '1' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, true) + t.equal(ci.name, 'Screwdriver') + t.equal(ci.SCREWDRIVER, true) + assertVendorConstants('SCREWDRIVER', ci, t) + + delete process.env.SCREWDRIVER + delete process.env.SD_PULL_REQUEST + + t.end() +}) + +test('Screwdriver - Not PR', function (t) { + process.env.SCREWDRIVER = 'true' + process.env.SD_PULL_REQUEST = 'false' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + t.equal(ci.isPR, false) + t.equal(ci.name, 'Screwdriver') + t.equal(ci.SCREWDRIVER, true) + assertVendorConstants('SCREWDRIVER', ci, t) + + delete process.env.SCREWDRIVER + delete process.env.SD_PULL_REQUEST + + t.end() +}) + +test('Visual Studio App Center', function (t) { + process.env.APPCENTER_BUILD_ID = '1' + + clearModule('./') + const ci = require('./') + + t.equal(ci.isCI, true) + // t.equal(ci.isPR, false) + t.equal(ci.name, 'Visual Studio App Center') + t.equal(ci.APPCENTER, true) + assertVendorConstants('APPCENTER', ci, t) + + delete process.env.APPCENTER + + t.end() +}) + +function assertVendorConstants (expect, ci, t) { + ci._vendors.forEach(function (constant) { + let bool = constant === expect + bool = (expect === 'SOLANO' && constant === 'TDDIUM') || bool // support deprecated option + t.equal(ci[constant], bool, 'ci.' + constant) + }) +} diff --git a/types-ci-info/LICENSE b/types-ci-info/LICENSE new file mode 100644 index 0000000..9e841e7 --- /dev/null +++ b/types-ci-info/LICENSE @@ -0,0 +1,21 @@ + MIT License + + Copyright (c) Microsoft Corporation. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE diff --git a/types-ci-info/README.md b/types-ci-info/README.md new file mode 100644 index 0000000..20019e8 --- /dev/null +++ b/types-ci-info/README.md @@ -0,0 +1,3 @@ +This is a stub types definition for @types/ci-info (https://github.com/watson/ci-info). + +ci-info provides its own type definitions, so you don't need @types/ci-info installed! \ No newline at end of file diff --git a/types-ci-info/package.json b/types-ci-info/package.json new file mode 100644 index 0000000..03fb7b1 --- /dev/null +++ b/types-ci-info/package.json @@ -0,0 +1,13 @@ +{ + "name": "@types/ci-info", + "version": "3.1.0", + "typings": null, + "description": "Stub TypeScript definitions entry for ci-info, which provides its own types definitions", + "main": "", + "scripts": {}, + "author": "", + "license": "MIT", + "dependencies": { + "ci-info": "*" + } +} \ No newline at end of file diff --git a/vendors.json b/vendors.json new file mode 100644 index 0000000..a20fe1e --- /dev/null +++ b/vendors.json @@ -0,0 +1,205 @@ +[ + { + "name": "AppVeyor", + "constant": "APPVEYOR", + "env": "APPVEYOR", + "pr": "APPVEYOR_PULL_REQUEST_NUMBER" + }, + { + "name": "Azure Pipelines", + "constant": "AZURE_PIPELINES", + "env": "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI", + "pr": "SYSTEM_PULLREQUEST_PULLREQUESTID" + }, + { + "name": "Appcircle", + "constant": "APPCIRCLE", + "env": "AC_APPCIRCLE" + }, + { + "name": "Bamboo", + "constant": "BAMBOO", + "env": "bamboo_planKey" + }, + { + "name": "Bitbucket Pipelines", + "constant": "BITBUCKET", + "env": "BITBUCKET_COMMIT", + "pr": "BITBUCKET_PR_ID" + }, + { + "name": "Bitrise", + "constant": "BITRISE", + "env": "BITRISE_IO", + "pr": "BITRISE_PULL_REQUEST" + }, + { + "name": "Buddy", + "constant": "BUDDY", + "env": "BUDDY_WORKSPACE_ID", + "pr": "BUDDY_EXECUTION_PULL_REQUEST_ID" + }, + { + "name": "Buildkite", + "constant": "BUILDKITE", + "env": "BUILDKITE", + "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" } + }, + { + "name": "CircleCI", + "constant": "CIRCLE", + "env": "CIRCLECI", + "pr": "CIRCLE_PULL_REQUEST" + }, + { + "name": "Cirrus CI", + "constant": "CIRRUS", + "env": "CIRRUS_CI", + "pr": "CIRRUS_PR" + }, + { + "name": "AWS CodeBuild", + "constant": "CODEBUILD", + "env": "CODEBUILD_BUILD_ARN" + }, + { + "name": "Codefresh", + "constant": "CODEFRESH", + "env": "CF_BUILD_ID", + "pr": { "any": ["CF_PULL_REQUEST_NUMBER", "CF_PULL_REQUEST_ID"] } + }, + { + "name": "Codeship", + "constant": "CODESHIP", + "env": { "CI_NAME": "codeship" } + }, + { + "name": "Drone", + "constant": "DRONE", + "env": "DRONE", + "pr": { "DRONE_BUILD_EVENT": "pull_request" } + }, + { + "name": "dsari", + "constant": "DSARI", + "env": "DSARI" + }, + { + "name": "GitHub Actions", + "constant": "GITHUB_ACTIONS", + "env": "GITHUB_ACTIONS", + "pr": { "GITHUB_EVENT_NAME": "pull_request" } + }, + { + "name": "GitLab CI", + "constant": "GITLAB", + "env": "GITLAB_CI", + "pr": "CI_MERGE_REQUEST_ID" + }, + { + "name": "GoCD", + "constant": "GOCD", + "env": "GO_PIPELINE_LABEL" + }, + { + "name": "LayerCI", + "constant": "LAYERCI", + "env": "LAYERCI", + "pr": "LAYERCI_PULL_REQUEST" + }, + { + "name": "Hudson", + "constant": "HUDSON", + "env": "HUDSON_URL" + }, + { + "name": "Jenkins", + "constant": "JENKINS", + "env": ["JENKINS_URL", "BUILD_ID"], + "pr": { "any": ["ghprbPullId", "CHANGE_ID"] } + }, + { + "name": "Magnum CI", + "constant": "MAGNUM", + "env": "MAGNUM" + }, + { + "name": "Netlify CI", + "constant": "NETLIFY", + "env": "NETLIFY", + "pr": { "env": "PULL_REQUEST", "ne": "false" } + }, + { + "name": "Nevercode", + "constant": "NEVERCODE", + "env": "NEVERCODE", + "pr": { "env": "NEVERCODE_PULL_REQUEST", "ne": "false" } + }, + { + "name": "Render", + "constant": "RENDER", + "env": "RENDER", + "pr": { "IS_PULL_REQUEST": "true" } + }, + { + "name": "Sail CI", + "constant": "SAIL", + "env": "SAILCI", + "pr": "SAIL_PULL_REQUEST_NUMBER" + }, + { + "name": "Semaphore", + "constant": "SEMAPHORE", + "env": "SEMAPHORE", + "pr": "PULL_REQUEST_NUMBER" + }, + { + "name": "Screwdriver", + "constant": "SCREWDRIVER", + "env": "SCREWDRIVER", + "pr": { "env": "SD_PULL_REQUEST", "ne": "false" } + }, + { + "name": "Shippable", + "constant": "SHIPPABLE", + "env": "SHIPPABLE", + "pr": { "IS_PULL_REQUEST": "true" } + }, + { + "name": "Solano CI", + "constant": "SOLANO", + "env": "TDDIUM", + "pr": "TDDIUM_PR_ID" + }, + { + "name": "Strider CD", + "constant": "STRIDER", + "env": "STRIDER" + }, + { + "name": "TaskCluster", + "constant": "TASKCLUSTER", + "env": ["TASK_ID", "RUN_ID"] + }, + { + "name": "TeamCity", + "constant": "TEAMCITY", + "env": "TEAMCITY_VERSION" + }, + { + "name": "Travis CI", + "constant": "TRAVIS", + "env": "TRAVIS", + "pr": { "env": "TRAVIS_PULL_REQUEST", "ne": "false" } + }, + { + "name": "Vercel", + "constant": "VERCEL", + "env": "NOW_BUILDER" + }, + { + "name": "Visual Studio App Center", + "constant": "APPCENTER", + "env": "APPCENTER_BUILD_ID" + } +]