-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile
218 lines (188 loc) · 8.54 KB
/
Jenkinsfile
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
@Library('pipeline-library')
import com.genesys.jenkins.Notifications
def getPublishOptions(isMainBranch, isMaintenanceReleaseBranch, isBetaBranch) {
if (isMainBranch) {
return '--tag latest'
} else if (isMaintenanceReleaseBranch) {
return '--tag maintenance'
} else if (isBetaBranch) {
return '--tag beta'
}
return '--tag error'
}
Boolean isMainBranch = env.BRANCH_NAME == 'main'
Boolean isMaintenanceReleaseBranch = env.BRANCH_NAME.startsWith('maintenance/')
Boolean isBetaBranch = env.BRANCH_NAME.startsWith('beta/')
Boolean isFeatureBranch = env.BRANCH_NAME.startsWith('feature/')
Boolean isReleaseBranch = isMainBranch || isMaintenanceReleaseBranch || isBetaBranch
Boolean isPublicBranch = isReleaseBranch || isFeatureBranch
String releaseOptions = isBetaBranch ? '--prerelease beta' : ''
String publishOptions = getPublishOptions(isMainBranch, isMaintenanceReleaseBranch, isBetaBranch)
// We track this globally because it will later be passed to the documentation build
String componentAssetsPath = ''
String charComponentAssetsPath = ''
webappPipeline {
projectName = 'spark-components'
versionClosure = {
// If this is a release branch, bump the version before reading it. The conditional is not
// technically required, as the version closure is ignored for feature branches. However,
// it may protect against problems if the pipeline behavior changes in the future.
if (isReleaseBranch) {
sh('npm ci')
sh(
label: 'Version bump & changelog generation',
script: "npm run release -- ${releaseOptions}"
)
String releaseVersion = sh(
script: 'npm run --silent current-version',
returnStdout: true
).trim()
sh(
label: 'Sync package versions',
script: """
npm run version-sync ${releaseVersion}
npm install --package-lock-only
"""
)
sh(
label: 'Commit changes and tag release',
script: """
git add packages/**/package.json web-apps/**/package.json package-lock.json
git commit --amend --no-edit --no-verify
git tag -a \"v${releaseVersion}\" -m \"chore(release): ${releaseVersion}\"
"""
)
String unexpectedChanges = sh(
label: 'Check for untracked / unexpected changes',
script: 'git status --porcelain',
returnStdout: true
).trim()
if (unexpectedChanges != "") {
error("I found uncommited changes that should not exist:\n${unexpectedChanges}")
}
}
return readJSON(file: 'package.json').version
}
team = 'Core UI'
mailer = '[email protected]'
chatGroupId = 'adhoc-30ab1aa8-d42e-4590-b2a4-c9f7cef6d51c'
nodeVersion = '20.x multiarch'
testJob = 'no-tests'
deployConfig = [:]
manifest = customManifest('./dist') {
sh('./scripts/create-manifest.js')
readJSON(file: './manifest.json')
}
buildType = {
if (isReleaseBranch) {
return 'MAINLINE'
}
return isFeatureBranch ? 'FEATURE' : 'CI'
}
checkoutStep = {
checkout(scm)
sh("git checkout ${env.BRANCH_NAME}")
// Make sure we have tags, which are required for version bumps
sshagent(credentials: [constants.credentials.github.inin_dev_evangelists]) {
sh('git fetch --tags')
}
}
ciTests = {
// Skip module install if it ran during the version check
if (!fileExists('node_modules')) {
sh('npm ci')
}
sh('npm run test.ci')
sh('npm run build --workspace=packages/genesys-spark-tokens')
sh('npm run build --workspace=packages/genesys-spark')
sh('npm run stencil --workspace=packages/genesys-spark-components')
sh('npm run lint')
}
buildStep = { assetPrefix ->
// All of the useful stencil output lives under /genesys-webcomponents, so
// we add it to the loading path here to simplify internal code
componentAssetsPath = "${assetPrefix}genesys-webcomponents/"
chartComponentAssetsPath = "${assetPrefix}chart/genesys-chart-webcomponents/"
env.COMPONENT_ASSETS_PATH = componentAssetsPath
env.CHART_COMPONENT_ASSETS_PATH = chartComponentAssetsPath
sh('npm run build')
}
onSuccess = {
if (isReleaseBranch) {
stage('NPM Publish Packages') {
withCredentials([
string(credentialsId: constants.credentials.npm, variable: 'NPM_TOKEN')
]) {
def failures = new ArrayList<String>()
def componentStatCode = sh(script: "npm publish --workspace=packages/genesys-spark-components ${publishOptions}",
label: 'Publish Components',
returnStatus: true
)
if(componentStatCode > 0) {
failures.add('Publish Components')
}
def chartStatCode = sh(script: "npm publish --workspace=packages/genesys-spark-chart-components ${publishOptions}",
label: 'Publish Chart Components',
returnStatus: true
)
if(chartStatCode > 0) {
failures.add('Publish Chart Components')
}
def mainPackageStatCode = sh(script: "npm publish --workspace=packages/genesys-spark ${publishOptions}",
label: 'Publish Main Package',
returnStatus: true
)
if(mainPackageStatCode > 0) {
failures.add('Publish Main Package')
}
sh(script: '''
RELEASE_VERSION="$(npm run --silent current-version)"
npm install --no-progress -P -E genesys-spark-components@${RELEASE_VERSION} --workspace=packages/genesys-spark-components-react
npm install --no-progress -P -E genesys-spark-chart-components@${RELEASE_VERSION} --workspace=packages/genesys-spark-chart-components-react
''',
label: 'Set exact version dependency in React Components and Chart React Components',
)
def reactStatCode = sh(script: "npm publish --workspace=packages/genesys-spark-components-react ${publishOptions}",
label: 'Publish React Components',
returnStatus: true
)
if(reactStatCode > 0) {
failures.add('Publish React Components')
}
def chartReactStatCode = sh(script: "npm publish --workspace=packages/genesys-spark-chart-components-react ${publishOptions}",
label: 'Publish Chart React Components',
returnStatus: true
)
if(chartReactStatCode > 0) {
failures.add('Publish Chart React Components')
}
def notification = new com.genesys.jenkins.Notifications()
if (failures.size()) {
notification.sendEmailViaMailchomp("Spark NPM Publish failures", mailer, "These packages failed to publish to NPM:\n" + failures.join('\n'))
}
}
}
stage('Push Changes') {
sshagent(credentials: [constants.credentials.github.inin_dev_evangelists]) {
// Make sure we have the latest version of the branch so we can push our changes
sh("""
git pull
git push --follow-tags -u origin ${env.BRANCH_NAME}
""")
}
}
}
stage('Run Docs Build') {
if (isPublicBranch) {
build(job: 'spark-monorepo-examples',
parameters: [
string(name: 'BRANCH_NAME', value: env.BRANCH_NAME),
string(name: 'COMPONENT_ASSETS_PATH', value: componentAssetsPath),
string(name: 'CHART_COMPONENT_ASSETS_PATH', value: chartComponentAssetsPath)
],
propagate: false,
wait: false)
}
}
}
}