├── .npmrc ├── .gitattributes ├── .gitignore ├── test.js ├── cli.js ├── .github ├── security.md └── workflows │ └── main.yml ├── index.js ├── .editorconfig ├── index.d.ts ├── package.json ├── license └── readme.md /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import isInCi from './index.js'; 3 | 4 | test('main', t => { 5 | t.true(isInCi); 6 | }); 7 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import process from 'node:process'; 3 | import isInCi from './index.js'; 4 | 5 | process.exit(isInCi ? 0 : 1); 6 | -------------------------------------------------------------------------------- /.github/security.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import {env} from 'node:process'; 2 | 3 | const check = key => key in env && env[key] !== '0' && env[key] !== 'false'; 4 | 5 | const isInCi = check('CI') || check('CONTINUOUS_INTEGRATION'); 6 | 7 | export default isInCi; 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | Check if the process is running in a Continuous Integration (CI) environment. 3 | 4 | @example 5 | ``` 6 | import isInCi from 'is-in-ci'; 7 | 8 | if (isInCi) { 9 | console.log('Running in a CI environment'); 10 | } 11 | ``` 12 | */ 13 | declare const isInCi: boolean; 14 | 15 | export default isInCi; 16 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 20 14 | - 18 15 | steps: 16 | - uses: actions/checkout@v4 17 | - uses: actions/setup-node@v4 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - run: npm install 21 | - run: npm test 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "is-in-ci", 3 | "version": "2.0.0", 4 | "description": "Check if the process is running in a Continuous Integration (CI) environment", 5 | "license": "MIT", 6 | "repository": "sindresorhus/is-in-ci", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "bin": "./cli.js", 15 | "exports": { 16 | "types": "./index.d.ts", 17 | "default": "./index.js" 18 | }, 19 | "sideEffects": false, 20 | "engines": { 21 | "node": ">=20" 22 | }, 23 | "scripts": { 24 | "test": "xo && CI=1 ava && tsc index.d.ts" 25 | }, 26 | "files": [ 27 | "index.js", 28 | "index.d.ts", 29 | "cli.js" 30 | ], 31 | "keywords": [ 32 | "ci", 33 | "continuous", 34 | "integration", 35 | "environment", 36 | "server", 37 | "check", 38 | "detect", 39 | "determine", 40 | "test", 41 | "cli", 42 | "cli-app" 43 | ], 44 | "devDependencies": { 45 | "ava": "^6.4.1", 46 | "typescript": "^5.9.2", 47 | "xo": "^0.60.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # is-in-ci 2 | 3 | > Check if the process is running in a [Continuous Integration](https://en.wikipedia.org/wiki/Continuous_integration) (CI) environment 4 | 5 | ## Install 6 | 7 | ```sh 8 | npm install is-in-ci 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | import isInCi from 'is-in-ci'; 15 | 16 | if (isInCi) { 17 | console.log('Running in a CI environment'); 18 | } 19 | ``` 20 | 21 | It looks for these environment variables: `CI` and `CONTINUOUS_INTEGRATION`. 22 | 23 | ## CLI 24 | 25 | ```sh 26 | is-in-ci && echo 'Running in a CI environment' 27 | ``` 28 | 29 | Exits with code `0` in CI environments and `1` otherwise. 30 | 31 | ## FAQ 32 | 33 | ### How can I add a CI service? 34 | 35 | Request the CI service to include the `CI` environment variable. Most already do. 36 | 37 | ### How is this different from [`is-ci`](https://github.com/watson/is-ci)? 38 | 39 | The `is-ci` package attempts to detect every CI service, which is unsustainable. It also has a higher risk of false-positives. For example, it detects the environment variable `RUN_ID` as CI-specific, although other services could use it. Constant updates for new CIs create version fragmentation, resulting in inconsistent behavior across dependent packages. Pushing for CI services to use a standardized CI environment variable is a more robust solution. 40 | 41 | ## Related 42 | 43 | - [is-inside-container](https://github.com/sindresorhus/is-inside-container) - Check if the process is running inside a container 44 | - [is-interactive](https://github.com/sindresorhus/is-interactive) - Check if stdout or stderr is interactive 45 | --------------------------------------------------------------------------------