This repository has been archived by the owner on Sep 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
provider_buildkite.ts
136 lines (127 loc) · 3.9 KB
/
provider_buildkite.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import { setSlug } from '../helpers/provider'
import { IServiceParams, UploaderEnvs, UploaderInputs } from '../types'
/**
* Detects if this CI provider is being used
*
* @param {*} envs an object of enviromental variable key/value pairs
* @returns boolean
*/
export function detect(envs: UploaderEnvs): boolean {
return Boolean(envs.BUILDKITE)
}
/**
* Determine the build number, based on args and envs
*
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs
* @returns {string}
*/
function _getBuild(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
return args.build || envs.BUILDKITE_BUILD_NUMBER || ''
}
/**
* Determine the build URL for use in the codasove UI
*
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs
* @returns {string}
*/
function _getBuildURL(inputs: UploaderInputs): string {
return inputs.environment.BUILDKITE_BUILD_URL || ''
}
/**
* Determine the branch of the repository, based on args and envs
*
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs
* @returns {string}
*/
function _getBranch(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
return args.branch || envs.BUILDKITE_BRANCH || ''
}
/**
* Determine the job number, based on args or envs
*
* @param {*} envs an object of enviromental variable key/value pairs
* @returns {string}
*/
function _getJob(envs: UploaderEnvs): string {
return envs.BUILDKITE_JOB_ID || ''
}
/**
* Determine the PR number, based on args and envs
*
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs
* @returns {string}
*/
function _getPR(inputs: UploaderInputs): string {
const { args } = inputs
return args.pr || ''
}
/**
* The CI service name that gets sent to the codasove uploader as part of the query string
*
* @returns {string}
*/
export function _getService(): string {
return 'buildkite'
}
/**
* The CI Service name that gets displayed when running the uploader
*
* @returns
*/
export function getServiceName(): string {
return 'Buildkite'
}
/**
* Determine the commit SHA that is being uploaded, based on args or envs
*
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs
* @returns {string}
*/
function _getSHA(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
if (Boolean(args.sha) || Boolean(envs.BUILDKITE_COMMIT)) {
return args.sha || envs.BUILDKITE_COMMIT || ''
}
throw new Error('Unable to detect sha, please set manually with the -C flag')
}
/**
* Determine the slug (org/repo) based on args or envs
*
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs
* @returns {string}
*/
function _getSlug(inputs: UploaderInputs): string {
const { args, environment: envs } = inputs
return setSlug(args.slug, envs.BUILDKITE_ORGANIZATION_SLUG, envs.BUILDKITE_PIPELINE_SLUG)
}
/**
* Generates and return the serviceParams object
*
* @param {args: {}, envs: {}} inputs an object of arguments and enviromental variable key/value pairs
* @returns {{ branch: string, build: string, buildURL: string, commit: string, job: string, pr: string, service: string, slug: string }}
*/
export function getServiceParams(inputs: UploaderInputs): IServiceParams {
return {
branch: _getBranch(inputs),
build: _getBuild(inputs),
buildURL: _getBuildURL(inputs),
commit: _getSHA(inputs),
job: _getJob(inputs.environment),
pr: _getPR(inputs),
service: _getService(),
slug: _getSlug(inputs),
}
}
export function getEnvVarNames(): string[] {
return [
'BUILDKITE',
'BUILDKITE_BRANCH',
'BUILDKITE_BUILD_NUMBER',
'BUILDKITE_BUILD_URL',
'BUILDKITE_COMMIT',
'BUILDKITE_JOB_ID',
'BUILDKITE_PROJECT_SLUG',
]
}