-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathci.ts
77 lines (67 loc) · 1.71 KB
/
ci.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
interface Provider {
matcher(): boolean;
ci: CI;
}
interface CI {
repo: string;
refName: string;
sha: string;
user: string;
}
const GITHUB = {
matcher: () => !!process.env.GITHUB_ACTIONS,
ci: {
repo: process.env.GITHUB_REPOSITORY ?? "",
refName: process.env.GITHUB_HEAD_REF ?? process.env.GITHUB_REF_NAME ?? "",
sha: process.env.GITHUB_SHA ?? "",
user: process.env.GITHUB_ACTOR ?? "",
},
};
const GITLAB = {
matcher: () => !!process.env.GITLAB_CI,
ci: {
repo: process.env.CI_PROJECT_PATH ?? "",
refName: process.env.CI_COMMIT_REF_NAME ?? "",
sha: process.env.CI_COMMIT_SHA ?? "",
user: process.env.GITLAB_USER_LOGIN ?? "",
},
};
const JENKINS = {
matcher: () => !!process.env.JENKINS_URL,
ci: {
repo: process.env.GIT_URL ?? "",
refName: process.env.GIT_BRANCH ?? "",
sha: process.env.GIT_COMMIT ?? "",
user: "",
},
};
const BITBUCKET = {
matcher: () => !!process.env.BITBUCKET_BUILD_NUMBER,
ci: {
repo: process.env.BITBUCKET_REPO_FULL_NAME ?? "",
refName: process.env.BITBUCKET_BRANCH ?? "",
sha: process.env.BITBUCKET_COMMIT ?? "",
user: process.env.BITBUCKET_STEP_TRIGGERER_UUID ?? "",
},
};
const CIRCLECI = {
matcher: () => !!process.env.CIRCLECI,
ci: {
repo: process.env.CIRCLE_REPOSITORY_URL ?? "",
refName: process.env.CIRCLE_BRANCH ?? "",
sha: process.env.CIRCLE_SHA1 ?? "",
user: process.env.CIRCLE_USERNAME ?? "",
},
};
const DEFAULT = {
matcher: () => true,
ci: {
repo: "",
refName: "",
sha: "",
user: "",
},
};
const providers: Provider[] = [GITHUB, GITLAB, JENKINS, BITBUCKET, CIRCLECI];
const provider = providers.find((p) => p.matcher());
export const CI = provider?.ci ?? DEFAULT.ci;