forked from HaikuTeam/animator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
269 lines (262 loc) · 11.6 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
final String STATUS_PENDING = 'PENDING'
final String STATUS_SUCCESS = 'SUCCESS'
final String STATUS_FAILURE = 'FAILURE'
final String CONTEXT_HEALTH = 'health'
final String CONTEXT_LINT = 'health/lint'
final String CONTEXT_TEST_MAC = 'health/test/macOS'
final String CONTEXT_BUILD = 'build'
final String CONTEXT_BUILD_MAC = 'build/macOS'
final String CONTEXT_PUSH = 'release/push'
final String CONTEXT_SYNDICATION = 'release/syndication'
pipeline {
agent any
environment {
// Reverse the timestamp for squirrel ordering.
HAIKU_RELEASE_COUNTDOWN = "${10.power(13) - new Date().getTime()}"
}
stages {
// Sets up Node and Yarn at the correct versions.
stage('Provision-macOS') {
agent {
label 'master'
}
steps {
setBuildStatus(CONTEXT_HEALTH, 'health checks started', STATUS_PENDING)
sh '''#!/bin/bash -x
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
. $HOME/.bash_profile >> /dev/null 2>&1
nvm install 8.15.1
nvm use 8.15.1
curl -o- -L https://yarnpkg.com/install.sh | bash -s -- --version 1.9.4'''
}
}
stage('Test') {
parallel {
stage('Test-macOS') {
agent {
label 'master'
}
steps {
setBuildStatus(CONTEXT_TEST_MAC, 'tests started', STATUS_PENDING)
yarnInstallUnixLike()
yarnRun('compile-all')
yarnRun('test-report')
}
post {
always {
archiveArtifacts artifacts: 'packages/**/test-result.tap', fingerprint: true
step([
$class: 'TapPublisher',
testResults: 'packages/**/test-result.tap',
verbose: true,
planRequired: true
])
cobertura autoUpdateHealth: false, autoUpdateStability: false, coberturaReportFile: '**/coverage/cobertura-coverage.xml', failNoReports: false, failUnhealthy: false, failUnstable: false, maxNumberOfBuilds: 0, onlyStable: false, sourceEncoding: 'ASCII', zoomCoverageChart: false
}
success {
setBuildStatus(CONTEXT_TEST_MAC, 'all tests pass', STATUS_SUCCESS)
}
failure {
setBuildStatus(CONTEXT_TEST_MAC, 'tests are failing', STATUS_FAILURE)
setBuildStatus(CONTEXT_HEALTH, 'not all health checks passed', STATUS_FAILURE)
slackSend([
channel: 'engineering-feed',
color: 'danger',
message: ":jenkins-rage: PR #${env.GITHUB_PR_NUMBER} (https://github.com/HaikuTeam/mono/pull/${env.GITHUB_PR_NUMBER}) has failing tests!"
])
}
}
}
}
}
stage('Lint') {
agent {
label 'master'
}
steps {
setBuildStatus(CONTEXT_LINT, 'lint started', STATUS_PENDING)
yarnInstallUnixLike()
yarnRun('lint-report')
}
post {
always {
checkstyle canRunOnFailed: true, defaultEncoding: '', healthy: '', pattern: '**/checkstyle-result.xml', unHealthy: ''
}
success {
setBuildStatus(CONTEXT_LINT, 'no lint errors', STATUS_SUCCESS)
setBuildStatus(CONTEXT_HEALTH, 'all health checks passed', STATUS_SUCCESS)
slackSend([
channel: 'engineering-feed',
color: 'good',
message: ":jenkins-hero: PR #${env.GITHUB_PR_NUMBER} (https://github.com/HaikuTeam/mono/pull/${env.GITHUB_PR_NUMBER}) is healthy!"
])
}
failure {
setBuildStatus(CONTEXT_LINT, 'lint errors found', STATUS_FAILURE)
setBuildStatus(CONTEXT_HEALTH, 'not all health checks passed', STATUS_FAILURE)
slackSend([
channel: 'engineering-feed',
color: 'warning',
message: ":professor-farnsworth: PR #${env.GITHUB_PR_NUMBER} (https://github.com/HaikuTeam/mono/pull/${env.GITHUB_PR_NUMBER}) has lint errors!"
])
}
}
}
stage('Build-Advance') {
when { expression { env.GITHUB_PR_SOURCE_BRANCH.startsWith('rc-') } }
steps {
milestone 1
notifyAdvancementRequest()
timeout(time: 1, unit: 'HOURS') {
script {
env.haikuExplicitSemver = input message: 'Build for syndication?', submitter: 'sasha@haiku.ai,roberto@haiku.ai,zack@haiku.ai', parameters: [string(defaultValue: (env.GITHUB_PR_SOURCE_BRANCH =~ /^rc-\d+\.\d+\.\d+$/) ? env.GITHUB_PR_SOURCE_BRANCH.replace('rc-', '') : '', description: 'Optionally, you may set an explicit semver here.', name: 'haikuExplicitSemver', trim: true)]
}
setBuildStatus(CONTEXT_BUILD, 'builds started', STATUS_PENDING)
}
milestone 2
}
}
stage('Build') {
when { expression { env.GITHUB_PR_SOURCE_BRANCH.startsWith('rc-') } }
parallel {
stage('macOS') {
agent {
label 'master'
}
steps {
setBuildStatus(CONTEXT_BUILD_MAC, 'build started', STATUS_PENDING)
setupBuild()
nodeRun('./scripts/distro-prepare.js')
nodeRun('./scripts/distro-build.js')
nodeRun('./scripts/distro-upload.js')
}
post {
success {
setBuildStatus(CONTEXT_BUILD_MAC, 'build complete', STATUS_SUCCESS)
}
failure {
setBuildStatus(CONTEXT_BUILD_MAC, 'build failed', STATUS_FAILURE)
}
}
}
}
post {
success {
setBuildStatus(CONTEXT_BUILD, 'all targets built', STATUS_SUCCESS)
}
failure {
setBuildStatus(CONTEXT_BUILD, 'not all targets built', STATUS_FAILURE)
}
}
}
stage('Push') {
when { expression { env.GITHUB_PR_SOURCE_BRANCH.startsWith('rc-') } }
steps {
milestone 3
notifyAdvancementRequest()
timeout(time: 1, unit: 'DAYS') {
input message: 'Push to NPM and CDN?', submitter: 'sasha@haiku.ai,roberto@haiku.ai,zack@haiku.ai'
setBuildStatus(CONTEXT_PUSH, 'pushing to NPM and CDN...', STATUS_PENDING)
setupBuild()
// sh """echo "//registry.npmjs.org/:_authToken=${env.NPM_AUTH_TOKEN}" > ~/.npmrc"""
nodeRun('./scripts/distro-push.js')
}
milestone 4
}
post {
success {
setBuildStatus(CONTEXT_PUSH, 'pushed to NPM and CDN', STATUS_SUCCESS)
slackSend([
channel: 'engineering-feed',
color: 'good',
message: ":1up: ${env.GITHUB_PR_SOURCE_BRANCH} was pushed to NPM and CDN!"
])
}
failure {
setBuildStatus(CONTEXT_PUSH, 'pushing to NPM and CDN failed', STATUS_FAILURE)
slackSend([
channel: 'engineering-feed',
color: 'danger',
message: ":-1up: ${env.GITHUB_PR_SOURCE_BRANCH} failed during push to NPM and CDN"
])
}
}
}
stage('Syndicate') {
when { expression { env.GITHUB_PR_SOURCE_BRANCH.startsWith('rc-') } }
steps {
milestone 5
notifyAdvancementRequest()
timeout(time: 1, unit: 'DAYS') {
input message: 'Syndicate release?', submitter: 'sasha@haiku.ai,roberto@haiku.ai,zack@haiku.ai'
setBuildStatus(CONTEXT_SYNDICATION, 'syndicating...', STATUS_PENDING)
setupBuild()
nodeRun('./scripts/distro-syndicate.js --non-interactive')
}
milestone 6
}
post {
success {
slackSend([
channel: 'engineering-feed',
color: 'good',
message: ":1up: :animator: ${env.GITHUB_PR_SOURCE_BRANCH} was syndicated!"
])
setBuildStatus(CONTEXT_SYNDICATION, 'syndicated', STATUS_SUCCESS)
}
failure {
slackSend([
channel: 'engineering-feed',
color: 'danger',
message: ":-1up: ${env.GITHUB_PR_SOURCE_BRANCH} failed during syndication!"
])
setBuildStatus(CONTEXT_SYNDICATION, 'syndication failed', STATUS_FAILURE)
}
}
}
}
}
void notifyAdvancementRequest() {
slackSend([
channel: 'engineering-feed',
color: 'good',
message: ":powerup: A build would like to advance | countdown: ${env.HAIKU_RELEASE_COUNTDOWN}\n\n" +
"https://ci.haiku.ai/blue/organizations/jenkins/Haiku/detail/Haiku/${env.BUILD_NUMBER}/pipeline"
])
}
void setBuildStatus(String context, String message, String state) {
step([
$class: 'GitHubCommitStatusSetter',
commitShaSource: [$class: "ManuallyEnteredShaSource", sha: env.GITHUB_PR_HEAD_SHA],
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: context],
reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/HaikuTeam/mono'],
errorHandlers: [[$class: 'ChangingBuildStatusErrorHandler', result: 'UNSTABLE']],
statusResultSource: [
$class: 'ConditionalStatusResultSource',
results: [[$class: 'AnyBuildResult', message: message, state: state]]
]
])
}
void setupBuild() {
yarnInstallUnixLike()
nodeRun("./scripts/semver.js ${(env.haikuExplicitSemver == '') ? '--non-interactive' : "--explicit=${env.haikuExplicitSemver}"}")
nodeRun('./scripts/distro-configure.js --non-interactive')
nodeRun('./scripts/distro-download-secrets.js')
}
void yarnInstallUnixLike() {
sh '''#!/bin/bash -x
. $HOME/.bash_profile
if [ ! -d node_modules ]; then
yarn install --frozen-lockfile --force
fi'''
}
void yarnRun(String command) {
sh '''#!/bin/bash -x
. $HOME/.bash_profile
''' + "yarn ${command}"
}
void nodeRun(String command) {
sh '''#!/bin/bash -x
. $HOME/.bash_profile
''' + "node ${command}"
}