diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index ab630fa..33a22ed 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -27,6 +27,9 @@ jobs: echo "" echo "------------------------------------" echo "" + mv package.json package-dev.json + mv package-build.json package.json + CURR_VER="$(cat package.json | jq -r .name)_v$(cat package.json | jq -r .version)" CURR_NAME="$(cat package.json | jq -r .name) v$(cat package.json | jq -r .version)" diff --git a/README.md b/README.md index 82ce035..40e74cd 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ Returns true if inside CI. Otherwise returns false. Returns code 0 if inside CI. Otherwise returns an error code of 1. `inside-ci || echo 'We are not inside CI, install some stuff'` + `inside-ci && echo 'We are inside CI, install some stuff'` Example: diff --git a/index.d.ts b/index.d.ts index e156733..4ad18c3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,2 +1,2 @@ /** Returns true if current environment is running inside CI. Otherwise returns false. */ -export function insideCi() +export function insideCi(): boolean diff --git a/index.js b/index.js index c670aef..42fbaab 100755 --- a/index.js +++ b/index.js @@ -1,22 +1,12 @@ #!/usr/bin/env node -/** Returns true if current environment is running inside CI. Otherwise returns false. */ -function insideCi() { +module.exports.insideCi = function insideCi() { // Bail out if this is specifically overwritten to false. - // Some users seem to wanna be able to do that if (process.env.CI === 'false') return false - // 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 - // CI_NAME is used by Codeship:https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables - // BUILD_NUMBER is used by TeamCity: https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters - // RUN_ID is used by Taskcluster: https://docs.taskcluster.net/docs/reference/workers/docker-worker/environment - return Boolean(['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x])) + return !!['CI','CI_APP_ID','BUILD_NUMBER','CI_NAME','RUN_ID'].some(x => process.env[x]) } -module.exports.insideCi = insideCi - if (require.main === module) { process.exit(insideCi() ? 0 : 1) } diff --git a/package-build.json b/package-build.json new file mode 100644 index 0000000..71bb684 --- /dev/null +++ b/package-build.json @@ -0,0 +1 @@ +{"name":"inside-ci","version":"1.0.1","description":"Quick tool to check if we are inside CI","main":"index.js","bin":{"inside-ci":"./index.js"},"repository":{"type":"git","url":"https://git.nfp.is/TheThing/inside-ci.git"},"keywords":["ci","is-ci","inside-ci","environment"],"author":"Jonatan Nilsson","license":"WTFPL","files":["index.js","index.d.ts","README.md","LICENSE"]} \ No newline at end of file diff --git a/package.json b/package.json index 1581dd6..75082a1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "inside-ci", - "version": "1.0.0", + "version": "1.0.1", "description": "Quick tool to check if we are inside CI", "main": "index.js", "scripts": { diff --git a/test.mjs b/test.mjs index 5c26af9..f06a2aa 100644 --- a/test.mjs +++ b/test.mjs @@ -3,6 +3,12 @@ import { Eltro as t, assert } from 'eltro' import { insideCi } from './index.js' 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 + // CI_NAME is used by Codeship:https://docs.cloudbees.com/docs/cloudbees-codeship/latest/pro-builds-and-configuration/environment-variables + // BUILD_NUMBER is used by TeamCity: https://www.jetbrains.com/help/teamcity/predefined-build-parameters.html#Predefined+Server+Build+Parameters + // RUN_ID is used by Taskcluster: https://docs.taskcluster.net/docs/reference/workers/docker-worker/environment const testVariables = [ 'CI', 'CI_APP_ID',