Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Nov 26, 2024
1 parent 8cbf1a7 commit 534bbe8
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 52 deletions.
80 changes: 46 additions & 34 deletions node_modules/ci-info/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Object.defineProperty(exports, '_vendors', {

exports.name = null
exports.isPR = null
exports.id = null

vendors.forEach(function (vendor) {
const envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env]
Expand All @@ -27,45 +28,23 @@ vendors.forEach(function (vendor) {
}

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.isPR = checkPR(vendor)
exports.id = vendor.constant
})

exports.isCI = !!(
env.CI !== 'false' && // Bypass all checks if CI env is explicitly set to 'false'
(env.BUILD_ID || // Jenkins, Cloudbees
env.BUILD_NUMBER || // Jenkins, TeamCity
env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
env.CI_APP_ID || // Appflow
env.CI_BUILD_ID || // Appflow
env.CI_BUILD_NUMBER || // Appflow
env.CI_NAME || // Codeship and others
env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
env.RUN_ID || // TaskCluster, dsari
exports.name ||
false)
env.BUILD_NUMBER || // Jenkins, TeamCity
env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
env.CI_APP_ID || // Appflow
env.CI_BUILD_ID || // Appflow
env.CI_BUILD_NUMBER || // Appflow
env.CI_NAME || // Codeship and others
env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
env.RUN_ID || // TaskCluster, dsari
exports.name ||
false)
)

function checkEnv (obj) {
Expand All @@ -79,12 +58,45 @@ function checkEnv (obj) {
return env[obj.env] && env[obj.env].includes(obj.includes)
// }
}

if ('any' in obj) {
return obj.any.some(function (k) {
return !!env[k]
})
}

return Object.keys(obj).every(function (k) {
return env[k] === obj[k]
})
}

function checkPR (vendor) {
switch (typeof vendor.pr) {
case 'string':
// "pr": "CIRRUS_PR"
return !!env[vendor.pr]
case 'object':
if ('env' in vendor.pr) {
if ('any' in vendor.pr) {
// "pr": { "env": "CODEBUILD_WEBHOOK_EVENT", "any": ["PULL_REQUEST_CREATED", "PULL_REQUEST_UPDATED"] }
return vendor.pr.any.some(function (key) {
return env[vendor.pr.env] === key
})
} else {
// "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
return vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne
}
} else if ('any' in vendor.pr) {
// "pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
return vendor.pr.any.some(function (key) {
return !!env[key]
})
} else {
// "pr": { "DRONE_BUILD_EVENT": "pull_request" }
return checkEnv(vendor.pr)
}
default:
// PR detection not supported for this vendor
return null
}
}
28 changes: 17 additions & 11 deletions node_modules/ci-info/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ci-info",
"version": "4.0.0",
"version": "4.1.0",
"description": "Get details about the current Continuous Integration environment",
"main": "index.js",
"typings": "index.d.ts",
Expand All @@ -9,6 +9,18 @@
"repository": "https://github.com/watson/ci-info.git",
"bugs": "https://github.com/watson/ci-info/issues",
"homepage": "https://github.com/watson/ci-info",
"contributors": [
{
"name": "Sibiraj",
"url": "https://github.com/sibiraj-s"
}
],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/sibiraj-s"
}
],
"keywords": [
"ci",
"continuous",
Expand All @@ -22,22 +34,16 @@
"index.d.ts",
"CHANGELOG.md"
],
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/sibiraj-s"
}
],
"scripts": {
"lint:fix": "standard --fix",
"test": "standard && node test.js",
"prepare": "husky install"
"prepare": "husky install || true"
},
"devDependencies": {
"clear-module": "^4.1.2",
"husky": "^8.0.3",
"standard": "^17.1.0",
"tape": "^5.7.0"
"husky": "^9.1.6",
"standard": "^17.1.2",
"tape": "^5.9.0"
},
"engines": {
"node": ">=8"
Expand Down
16 changes: 14 additions & 2 deletions node_modules/ci-info/vendors.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
{
"name": "Appcircle",
"constant": "APPCIRCLE",
"env": "AC_APPCIRCLE"
"env": "AC_APPCIRCLE",
"pr": {
"env": "AC_GIT_PR",
"ne": "false"
}
},
{
"name": "AppVeyor",
Expand All @@ -19,7 +23,15 @@
{
"name": "AWS CodeBuild",
"constant": "CODEBUILD",
"env": "CODEBUILD_BUILD_ARN"
"env": "CODEBUILD_BUILD_ARN",
"pr": {
"env": "CODEBUILD_WEBHOOK_EVENT",
"any": [
"PULL_REQUEST_CREATED",
"PULL_REQUEST_UPDATED",
"PULL_REQUEST_REOPENED"
]
}
},
{
"name": "Azure Pipelines",
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"archy": "~1.0.0",
"cacache": "^19.0.1",
"chalk": "^5.3.0",
"ci-info": "^4.0.0",
"ci-info": "^4.1.0",
"cli-columns": "^4.0.0",
"fastest-levenshtein": "^1.0.16",
"fs-minipass": "^3.0.3",
Expand Down Expand Up @@ -5810,9 +5810,9 @@
}
},
"node_modules/ci-info": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.0.0.tgz",
"integrity": "sha512-TdHqgGf9odd8SXNuxtUBVx8Nv+qZOejE6qyqiy5NtbYYQOeFa6zmHkxlPzmaLxWWHsU6nJmB7AETdVPi+2NBUg==",
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/ci-info/-/ci-info-4.1.0.tgz",
"integrity": "sha512-HutrvTNsF48wnxkzERIXOe5/mlcfFcbfCmwcg6CJnizbSue78AbDt+1cgl26zwn61WFxhcPykPfZrbqjGmBb4A==",
"funding": [
{
"type": "github",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"archy": "~1.0.0",
"cacache": "^19.0.1",
"chalk": "^5.3.0",
"ci-info": "^4.0.0",
"ci-info": "^4.1.0",
"cli-columns": "^4.0.0",
"fastest-levenshtein": "^1.0.16",
"fs-minipass": "^3.0.3",
Expand Down

0 comments on commit 534bbe8

Please sign in to comment.