Compare commits
2 commits
inside-ci_
...
master
Author | SHA1 | Date | |
---|---|---|---|
a79e6cca09 | |||
9fb1f9e926 |
5 changed files with 33 additions and 24 deletions
12
README.md
12
README.md
|
@ -1,12 +1,14 @@
|
||||||
# inside-ci
|
# inside-ci
|
||||||
|
|
||||||
Quick tool to check if we are inside a CI environment
|
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`.
|
||||||
|
|
||||||
# API
|
# API
|
||||||
|
|
||||||
`insideCi()`
|
`const inside = require('inside-ci')`
|
||||||
|
|
||||||
Returns true if inside CI. Otherwise returns false.
|
|
||||||
|
|
||||||
# CLI
|
# CLI
|
||||||
|
|
||||||
|
@ -14,7 +16,7 @@ Returns true if inside CI. Otherwise returns false.
|
||||||
|
|
||||||
Returns error code 0 if inside CI.
|
Returns error code 0 if inside CI.
|
||||||
|
|
||||||
* `in-ci && echo 'running inside CI'`
|
`in-ci && echo 'running inside CI'`
|
||||||
|
|
||||||
## `not-ci`
|
## `not-ci`
|
||||||
|
|
||||||
|
|
8
in.js
8
in.js
|
@ -1,12 +1,10 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
let is = module.exports.insideCi = () => {
|
// Bail out if CI is overrided
|
||||||
// Bail out if CI is overrided
|
let is = module.exports = process.env.CI === 'false'
|
||||||
return process.env.CI === 'false'
|
|
||||||
? false
|
? false
|
||||||
: !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x])
|
: !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x])
|
||||||
}
|
|
||||||
|
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
process.exit(is() ? 0 : 1)
|
process.exit(is ? 0 : 1)
|
||||||
}
|
}
|
||||||
|
|
2
not.js
2
not.js
|
@ -1,2 +1,2 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
process.exit(!require("./in.js").insideCi() ? 0 : 1)
|
process.exit(!require("./in.js") ? 0 : 1)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "inside-ci",
|
"name": "inside-ci",
|
||||||
"version": "1.1.2",
|
"version": "2.0.1",
|
||||||
"description": "Quick tool to check if we are inside CI",
|
"description": "Quick tool to check if we are inside CI",
|
||||||
"main": "in.js",
|
"main": "in.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
29
test.mjs
29
test.mjs
|
@ -1,8 +1,9 @@
|
||||||
import { exec } from 'child_process'
|
import { exec } from 'child_process'
|
||||||
import { Eltro as t, assert } from 'eltro'
|
import { Eltro as t, assert } from 'eltro'
|
||||||
import { insideCi } from './in.js'
|
import { createRequire } from 'node:module';
|
||||||
|
const require = createRequire(import.meta.url);
|
||||||
|
|
||||||
t.describe('#insideCi()', function () {
|
t.describe('in.js', function () {
|
||||||
// Most CI use env.CI (travis, Gitlab, etc.)
|
// Most CI use env.CI (travis, Gitlab, etc.)
|
||||||
// There are some exceptions though:
|
// There are some exceptions though:
|
||||||
// CI_APP_ID is used by Appflow: https://ionic.io/docs/appflow/package/environments#predefined-environments
|
// CI_APP_ID is used by Appflow: https://ionic.io/docs/appflow/package/environments#predefined-environments
|
||||||
|
@ -23,27 +24,35 @@ t.describe('#insideCi()', 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 => {
|
testVariables.forEach(name => {
|
||||||
t.test(`env.${name} should return true if set`, function () {
|
t.test(`env.${name} should return true if set`, async function () {
|
||||||
process.env[name] = 'asdf'
|
process.env[name] = 'asdf'
|
||||||
assert.ok(insideCi())
|
assert.ok(await insideCi())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should return false by default', function() {
|
t.test('should return false by default', async function() {
|
||||||
assert.notOk(insideCi())
|
assert.notOk(await insideCi())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should return false if all are empty strings', function () {
|
t.test('should return false if all are empty strings', async function () {
|
||||||
for (let name of testVariables) {
|
for (let name of testVariables) {
|
||||||
process.env[name] = ''
|
process.env[name] = ''
|
||||||
}
|
}
|
||||||
assert.notOk(insideCi())
|
assert.notOk(await insideCi())
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should return false if env.CI is specifically "false"', function () {
|
t.test('should return false if env.CI is specifically "false"', async function () {
|
||||||
process.env.CI = 'false'
|
process.env.CI = 'false'
|
||||||
assert.notOk(insideCi())
|
assert.notOk(await insideCi())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue