Compare commits

..

No commits in common. "master" and "inside-ci_v1.1.2" have entirely different histories.

5 changed files with 24 additions and 33 deletions

View file

@ -1,14 +1,12 @@
# inside-ci
Returns true if code is running inside CI, otherwise false.
This also works as a drop-in replacement for anyone currently using `is-ci`.
If your CI is not being detected, feel free to [add an issue for it](https://git.nfp.is/TheThing/inside-ci/issues) or hit me up on [X (formerly Twitter)](https://x.com/TheThing89) or on discord as `thething_89`.
Quick tool to check if we are inside a CI environment
# API
`const inside = require('inside-ci')`
`insideCi()`
Returns true if inside CI. Otherwise returns false.
# CLI
@ -16,7 +14,7 @@ If your CI is not being detected, feel free to [add an issue for it](https://git
Returns error code 0 if inside CI.
`in-ci && echo 'running inside CI'`
* `in-ci && echo 'running inside CI'`
## `not-ci`

12
in.js
View file

@ -1,10 +1,12 @@
#!/usr/bin/env node
// Bail out if CI is overrided
let is = module.exports = process.env.CI === 'false'
? false
: !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x])
let is = module.exports.insideCi = () => {
// Bail out if CI is overrided
return process.env.CI === 'false'
? false
: !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x])
}
if (require.main === module) {
process.exit(is ? 0 : 1)
process.exit(is() ? 0 : 1)
}

2
not.js
View file

@ -1,2 +1,2 @@
#!/usr/bin/env node
process.exit(!require("./in.js") ? 0 : 1)
process.exit(!require("./in.js").insideCi() ? 0 : 1)

View file

@ -1,6 +1,6 @@
{
"name": "inside-ci",
"version": "2.0.1",
"version": "1.1.2",
"description": "Quick tool to check if we are inside CI",
"main": "in.js",
"scripts": {

View file

@ -1,9 +1,8 @@
import { exec } from 'child_process'
import { Eltro as t, assert } from 'eltro'
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
import { insideCi } from './in.js'
t.describe('in.js', function () {
t.describe('#insideCi()', function () {
// Most CI use env.CI (travis, Gitlab, etc.)
// There are some exceptions though:
// CI_APP_ID is used by Appflow: https://ionic.io/docs/appflow/package/environments#predefined-environments
@ -24,35 +23,27 @@ t.describe('in.js', function () {
}
})
let n = 1
function insideCi() {
Object.keys(require.cache).forEach(key => {
delete require.cache[key]
})
return import(`./in.js?${n++}`).then(x => x.default)
}
testVariables.forEach(name => {
t.test(`env.${name} should return true if set`, async function () {
t.test(`env.${name} should return true if set`, function () {
process.env[name] = 'asdf'
assert.ok(await insideCi())
assert.ok(insideCi())
})
})
t.test('should return false by default', async function() {
assert.notOk(await insideCi())
t.test('should return false by default', function() {
assert.notOk(insideCi())
})
t.test('should return false if all are empty strings', async function () {
t.test('should return false if all are empty strings', function () {
for (let name of testVariables) {
process.env[name] = ''
}
assert.notOk(await insideCi())
assert.notOk(insideCi())
})
t.test('should return false if env.CI is specifically "false"', async function () {
t.test('should return false if env.CI is specifically "false"', function () {
process.env.CI = 'false'
assert.notOk(await insideCi())
assert.notOk(insideCi())
})
})