Skip to content

Commit 033c934

Browse files
Added a new host.ci property that has information about the CI/CD host
1 parent 387a36e commit 033c934

File tree

6 files changed

+117
-3
lines changed

6 files changed

+117
-3
lines changed

package-lock.json

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,8 @@
6767
"tslint": "^6.0.0",
6868
"typescript": "^3.7.5",
6969
"typescript-tslint-plugin": "^0.5.5"
70+
},
71+
"dependencies": {
72+
"@qawolf/ci-info": "^2.1.0"
7073
}
7174
}

src/host.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ export interface Host {
2323
*/
2424
env: EnvironmentVariables;
2525

26+
/**
27+
* Information about the CI/CD host.
28+
* This property is `false` when not running in a known CI/CD host.
29+
*
30+
* @see https://www.npmjs.com/package/@qawolf/ci-info#supported-ci-tools
31+
*/
32+
ci: false | CIInfo;
33+
2634
/**
2735
* Information about the Node host.
2836
* This property is `false` when running in a web browser.
@@ -89,6 +97,54 @@ export interface EnvironmentVariables {
8997
[key: string]: string | undefined;
9098
}
9199

100+
/**
101+
* Information about the CI/CD host.
102+
*/
103+
export interface CIInfo {
104+
/**
105+
* The friendly name of the CI/CD host (e.g. "Travis CI", "GitHub Actions", etc.)
106+
*/
107+
name: string;
108+
109+
/**
110+
* Whether the CI/CD job was triggered by a pull-request.
111+
*/
112+
pr: boolean;
113+
114+
/**
115+
* The CI/CD host name, as a boolean. (e.g. `TRAVIS`, `GITHUB_ACTIONS`, `TEAMCITY`, etc.)
116+
*/
117+
CODEBUILD: boolean | undefined;
118+
APPVEYOR: boolean | undefined;
119+
AZURE_PIPELINES: boolean | undefined;
120+
BAMBOO: boolean | undefined;
121+
BITBUCKET: boolean | undefined;
122+
BITRISE: boolean | undefined;
123+
BUDDY: boolean | undefined;
124+
BUILDKITE: boolean | undefined;
125+
CIRCLE: boolean | undefined;
126+
CIRRUS: boolean | undefined;
127+
CODESHIP: boolean | undefined;
128+
DRONE: boolean | undefined;
129+
DSARI: boolean | undefined;
130+
GITHUB_ACTIONS: boolean | undefined;
131+
GITLAB: boolean | undefined;
132+
GOCD: boolean | undefined;
133+
HUDSON: boolean | undefined;
134+
JENKINS: boolean | undefined;
135+
MAGNUM: boolean | undefined;
136+
NETLIFY: boolean | undefined;
137+
NEVERCODE: boolean | undefined;
138+
SAIL: boolean | undefined;
139+
SEMAPHORE: boolean | undefined;
140+
SHIPPABLE: boolean | undefined;
141+
SOLANO: boolean | undefined;
142+
STRIDER: boolean | undefined;
143+
TASKCLUSTER: boolean | undefined;
144+
TEAMCITY: boolean | undefined;
145+
TRAVIS: boolean | undefined;
146+
}
147+
92148
/**
93149
* Information about the Node host.
94150
*/

src/isomorphic.browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const host: Host = {
1111
node: false,
1212
browser: getBrowserInfo(),
1313
env: {},
14+
ci: false,
1415
merge,
1516
toJSON,
1617
};

src/isomorphic.node.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { Global, Host, NodeInfo, OSInfo } from "./host";
1+
import * as ci from "@qawolf/ci-info";
2+
import { CIInfo, Global, Host, NodeInfo, OSInfo } from "./host";
23
import { merge, mergeGlobalHost } from "./merge";
34
import { toJSON } from "./to-json";
45

@@ -11,6 +12,7 @@ export const host: Host = {
1112
node: getNodeInfo(),
1213
browser: false,
1314
env: process.env,
15+
ci: getCIInfo(),
1416
merge,
1517
toJSON,
1618
};
@@ -45,3 +47,17 @@ function getOSInfo(): OSInfo {
4547
let linux = !windows && !mac;
4648
return { windows, mac, linux };
4749
}
50+
51+
/**
52+
* Returns information about the current CI/CD host.
53+
*/
54+
function getCIInfo(): false | CIInfo {
55+
if (!ci.isCI) {
56+
return false;
57+
}
58+
59+
return {
60+
pr: ci.isPR,
61+
...ci,
62+
};
63+
}

src/types/@qawolf/ci-info/index.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
declare module "@qawolf/ci-info" {
2+
interface CIInfo {
3+
isCI: boolean;
4+
isPR: boolean;
5+
name: string;
6+
CODEBUILD: boolean | undefined;
7+
APPVEYOR: boolean | undefined;
8+
AZURE_PIPELINES: boolean | undefined;
9+
BAMBOO: boolean | undefined;
10+
BITBUCKET: boolean | undefined;
11+
BITRISE: boolean | undefined;
12+
BUDDY: boolean | undefined;
13+
BUILDKITE: boolean | undefined;
14+
CIRCLE: boolean | undefined;
15+
CIRRUS: boolean | undefined;
16+
CODESHIP: boolean | undefined;
17+
DRONE: boolean | undefined;
18+
DSARI: boolean | undefined;
19+
GITHUB_ACTIONS: boolean | undefined;
20+
GITLAB: boolean | undefined;
21+
GOCD: boolean | undefined;
22+
HUDSON: boolean | undefined;
23+
JENKINS: boolean | undefined;
24+
MAGNUM: boolean | undefined;
25+
NETLIFY: boolean | undefined;
26+
NEVERCODE: boolean | undefined;
27+
SAIL: boolean | undefined;
28+
SEMAPHORE: boolean | undefined;
29+
SHIPPABLE: boolean | undefined;
30+
SOLANO: boolean | undefined;
31+
STRIDER: boolean | undefined;
32+
TASKCLUSTER: boolean | undefined;
33+
TEAMCITY: boolean | undefined;
34+
TRAVIS: boolean | undefined;
35+
}
36+
37+
const ci: CIInfo;
38+
export = ci;
39+
}

0 commit comments

Comments
 (0)