@toptal/davinci-ci 6.0.1-alpha-fx-4497-storybook-13e9f909.10 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,460 +0,0 @@
1
- @Library('globalLibrary@master') _
2
-
3
- image = null
4
-
5
- jobHelper = new helpers.JobHelper()
6
-
7
- commitId = params.GITHUB_BRANCH_HEAD_SHA
8
- branch = params.GITHUB_BRANCH_NAME
9
- repositoryUrl = params.GITHUB_REPO_GIT_URL
10
-
11
- repositoryName = repositoryUrl.tokenize('/').last().split("\\.")[0]
12
- repositorySSHUrl = "git@github.com:toptal/${repositoryName}.git"
13
-
14
- prTestsJobName = "${repositoryName}-pr-tests"
15
- buildImageJobName = "${repositoryName}-build-image"
16
- buildReleaseImageJobName = "${repositoryName}-build-release-image"
17
- deployReleaseImageJobName = "${repositoryName}-deploy-helm-run"
18
- deployToStagingReleaseImageJobName = "${repositoryName}-deploy-staging-helm-run"
19
- consumerContractsVerifyJobName = "${repositoryName}-consumer-contracts-verify"
20
- def repoBullhornSlackChannel
21
-
22
- configDavinciYaml = "davinci.yaml"
23
- testsCoverageDirectory = "coverage"
24
- testsPactsDirectory = "pacts"
25
-
26
- testsDataDirectory = "~/${repositoryName}-tests"
27
- jenkinsTestsCoverageDirectory = "${testsDataDirectory}/${commitId}-coverage"
28
- jenkinsTestsPactContractsDirectory = "${testsDataDirectory}/${commitId}-pact"
29
-
30
- Boolean isEnabledInDavinciYaml(String section, String key) {
31
- if (fileExists(configDavinciYaml)) {
32
- configuration = jobHelper.readYaml(configDavinciYaml)
33
-
34
- if (configuration[section] && configuration[section][key]) {
35
- return true
36
- }
37
- }
38
-
39
- return false
40
- }
41
-
42
- String readDavinciYaml(String section, String defaultValue = '') {
43
- if (fileExists(configDavinciYaml)) {
44
- configuration = jobHelper.readYaml(configDavinciYaml)
45
-
46
- if (configuration[section]) {
47
- return "${configuration[section]}"
48
- }
49
- }
50
-
51
- return defaultValue
52
- }
53
-
54
- def getEnvironmentVariables(environmentName) {
55
- def environmentFilename = ".env.${environmentName}"
56
-
57
- if(!fileExists(environmentFilename)) {
58
- return 'ENV=null'
59
- }
60
-
61
- return sh(
62
- script: "egrep -v '^(#|\$)' ${environmentFilename} | sed 's/^/ENV./'| awk '{print}' ORS=',' | sed 's/,*\$//g'",
63
- returnStdout: true
64
- ).trim() as String
65
- }
66
-
67
- String getCommitDetails() {
68
- def shortSha = commitId.substring(0, 12)
69
- def gitCommitLink = "https://github.com/toptal/${repositoryName}/commit/${commitId}"
70
- def author = gitAuthor(commitId)
71
- def pullRequestId = gitHubPullRequestId(commitId)
72
- def pullRequestLink = gitHubPullRequestLink(repositoryName, commitId)
73
-
74
- if (pullRequestId.trim() != "") {
75
- info "pullRequestId: ${pullRequestId}"
76
- info "pullRequestLink: ${pullRequestLink}"
77
- return "Build <${env.BUILD_URL}|#${env.BUILD_NUMBER}> with <${gitCommitLink}|${shortSha}> (PR <${pullRequestLink}|#${pullRequestId}> by ${author})."
78
- }
79
-
80
- return "Build <${env.BUILD_URL}|#${env.BUILD_NUMBER}> with <${gitCommitLink}|${shortSha}> (by ${author})."
81
- }
82
-
83
- def hasParamInDavinciCommand(args) {
84
- def command = args.command
85
- def parameter = args.parameter
86
- def repoName = args.repoName
87
- def tag = args.tag
88
-
89
- def davinciHelpOutput = sh(
90
- script: """
91
- docker run \
92
- --rm \
93
- -u 469:469 \
94
- us-central1-docker.pkg.dev/toptal-hub/containers/${repoName}:${tag} \
95
- yarn davinci help ${command}
96
- """,
97
- returnStdout: true
98
- ).trim() as String
99
-
100
- return davinciHelpOutput.contains(parameter)
101
- }
102
-
103
- pipeline {
104
- agent { label 'slave_aws' }
105
-
106
- options {
107
- ansiColor('xterm')
108
- timestamps()
109
- timeout(time: 120, unit: 'MINUTES')
110
- buildDiscarder(logRotator(numToKeepStr: '20'))
111
- skipDefaultCheckout()
112
- }
113
-
114
- parameters {
115
- string(name: 'SONAR_SERVER_URL', defaultValue: 'https://sonarqube.toptal.net', description: 'URL to the SonarQube instance')
116
- string(name: 'GITHUB_REPO_GIT_URL', defaultValue: '', description: 'Repository URL')
117
- string(name: 'GITHUB_BRANCH_NAME', defaultValue: 'master', description: 'Branch to build')
118
- string(name: 'GITHUB_BRANCH_HEAD_SHA', defaultValue: '', description: 'Commit ID')
119
- }
120
-
121
- environment {
122
- GCE_ACCOUNT_KEY = credentials('jenkins-storage-administrator')
123
- NPM_TOKEN = credentials('npm-token-for-toptal-private-registry')
124
- SONARQUBE_TOKEN = credentials('sonarqube_token')
125
- }
126
-
127
- stages {
128
- stage('Davinci setup') {
129
- steps {
130
- success "=== This job was generated and brought to you by Davinci engine ==="
131
- info "If you want to observe its config check https://github.com/toptal/davinci/blob/master/packages/ci/src/configs/jobs/master-main/Jenkinsfile"
132
- info "If you encounter any issues please reach out #-frontend-exp-core"
133
- }
134
- }
135
-
136
- stage('Git checkout project') {
137
- steps {
138
- info "=== checking out ${branch} ==="
139
- gitCheckout(
140
- branches: branch,
141
- credentials: [username: 'toptal-build', description: "toptal-build-ssh-key"],
142
- url: repositorySSHUrl,
143
- additionalBehaviours: [
144
- cleanBeforeCheckout: true
145
- ])
146
- success "=== checked out ${branch} at ${commitId} ==="
147
-
148
- script {
149
- if (fileExists(configDavinciYaml)) {
150
- info "davinci.yaml file was found in the project root folder"
151
- info "Extracting values from the davinci.yaml file"
152
- repoBullhornSlackChannel = readDavinciYaml('slack_channel', "${repositoryName}-bullhorn")
153
- } else {
154
- info "davinci.yaml file was not found, using standard CI configuration"
155
- }
156
- }
157
- }
158
- } //checkout project
159
-
160
- stage('Build image') {
161
- steps {
162
- script {
163
- buildWithParameters(
164
- jobName: buildImageJobName,
165
- propagate: true,
166
- wait: true,
167
- parameters: [
168
- BRANCH: branch,
169
- VERSION: commitId,
170
- ALIAS_VERSIONS: "latest",
171
- IMAGE_NAME: repositoryName,
172
- REPOSITORY_NAME: repositoryName
173
- ]
174
- )
175
- }
176
- } //steps
177
- } //stage
178
-
179
- stage('Prepare directory to share data from tests run') {
180
- steps {
181
- script {
182
- sh """
183
- mkdir -p ${testsDataDirectory}
184
-
185
- rm -rf ${jenkinsTestsCoverageDirectory}
186
- mkdir ${jenkinsTestsCoverageDirectory}
187
-
188
- rm -rf ${jenkinsTestsPactContractsDirectory}
189
- mkdir ${jenkinsTestsPactContractsDirectory}
190
- """
191
- }
192
- }
193
- }
194
-
195
- stage('Run unit tests') {
196
- when {
197
- expression { return !isEnabledInDavinciYaml("master", "unitTests") }
198
- }
199
-
200
- steps {
201
- script {
202
- sh """
203
- docker run \
204
- --rm \
205
- -u 469:469 \
206
- -v ${jenkinsTestsCoverageDirectory}:/app/${testsCoverageDirectory} \
207
- -v ${jenkinsTestsPactContractsDirectory}:/app/${testsPactsDirectory} \
208
- us-central1-docker.pkg.dev/toptal-hub/containers/${repositoryName}:${commitId} \
209
- yarn test --ci
210
- """
211
- }
212
- } //steps
213
- } //stage
214
-
215
- stage('Publish pact contracts') {
216
- when {
217
- expression { return isEnabledInDavinciYaml("pr", "contract_testing") }
218
- }
219
-
220
- environment {
221
- // load pact broker credentials, also loads variable $PACT_BROKER_PSW
222
- PACT_BROKER = credentials('pact-broker')
223
- }
224
-
225
- steps {
226
- script {
227
- sh """
228
- docker run \
229
- --rm \
230
- -e PACT_BROKER_PSW=${PACT_BROKER_PSW} \
231
- -e GIT_BRANCH=${branch} \
232
- -e GIT_СOMMIT=${commitId} \
233
- -v ${jenkinsTestsPactContractsDirectory}:/app/${testsPactsDirectory} \
234
- us-central1-docker.pkg.dev/toptal-hub/containers/${repositoryName}:${commitId} \
235
- yarn publish-pact
236
- """
237
- }
238
- }
239
- }
240
-
241
- stage('Trigger consumer contracts verification') {
242
- when {
243
- expression { return isEnabledInDavinciYaml("pr", "contract_testing") }
244
- }
245
-
246
- steps {
247
- script {
248
- buildWithParameters(
249
- jobName: consumerContractsVerifyJobName,
250
- propagate: true,
251
- wait: true,
252
- parameters: [
253
- JOB_TYPE: "master",
254
- GIT_COMMIT: commitId
255
- ]
256
- )
257
- }
258
- }
259
- } //stage
260
-
261
- stage('Publish as package') {
262
- when {
263
- expression { return isEnabledInDavinciYaml("master", "publish_as_package") }
264
- }
265
-
266
- environment {
267
- GITHUB_TOKEN = credentials('toptal-devbot-personal-token')
268
- PUBLISH_NPM_TOKEN = credentials('npm-token-for-toptal-private-registry-publish')
269
- GIT_COMMITTER_NAME = 'toptal-bot'
270
- GIT_COMMITTER_EMAIL = 'bot@toptal.com'
271
- }
272
-
273
- steps {
274
- script {
275
- PWD = sh(returnStdout: true, script: 'pwd').trim()
276
- releasePackageCommand = 'yarn davinci-engine release-package'
277
-
278
- def outputVersionParamExistsInDavinci = hasParamInDavinciCommand(
279
- command: 'engine release-package',
280
- parameter: 'outputVersion',
281
- repoName: repositoryName,
282
- tag: commitId
283
- )
284
- if (outputVersionParamExistsInDavinci) {
285
- releasePackageCommand = "${releasePackageCommand} --outputVersion /artifacts/.version"
286
- }
287
- }
288
-
289
- sshagent(credentials: ['toptal-build-ssh-key']) {
290
- // $SSH_AUTH_SOCK - is the ssh key passed from ssh agent
291
- //
292
- // -u 469:469 \
293
- // - all those need to be passed to reuse jenkins user from Jenkins
294
- // and it's .ssh folder, keys and passwords
295
- //
296
- // -v ${PWD}:/artifacts - needs to pass .versions file
297
- //
298
- // -e JENKINS_URL=${JENKINS_URL} \
299
- // -e GIT_BRANCH=${branch} \
300
- // - need to make semantic-release to think
301
- // that we are running it inside CI environment
302
- //
303
- // -e GITHUB_TOKEN needed for semantic-release to authenticated with GitHub
304
- //
305
- sh """
306
- docker run \
307
- --rm \
308
- -e GIT_COMMITTER_EMAIL=${GIT_COMMITTER_EMAIL} \
309
- -e GIT_COMMITTER_NAME=${GIT_COMMITTER_NAME} \
310
- -e GITHUB_TOKEN=${GITHUB_TOKEN} \
311
- -e NPM_TOKEN=${PUBLISH_NPM_TOKEN} \
312
- -e JENKINS_URL=${JENKINS_URL} \
313
- -e GIT_BRANCH=${branch} \
314
- -v ${PWD}:/artifacts \
315
- -u 469:469 \
316
- -v $SSH_AUTH_SOCK:/ssh-agent \
317
- -e SSH_AUTH_SOCK=/ssh-agent \
318
- -v ${PWD}/.git:/app/.git \
319
- us-central1-docker.pkg.dev/toptal-hub/containers/${repositoryName}:${commitId} \
320
- ${releasePackageCommand}
321
- """
322
- }
323
- } //steps
324
- } //stage
325
-
326
- stage('Build release image') {
327
- steps {
328
- script {
329
- buildWithParameters(
330
- jobName: buildReleaseImageJobName,
331
- propagate: true,
332
- wait: true,
333
- parameters: [
334
- IMAGE_TAG: commitId,
335
- REPOSITORY_NAME: repositoryName,
336
- ALIAS_IMAGE_TAGS: 'latest'
337
- ]
338
- )
339
- }
340
- }
341
- } //stage
342
-
343
- stage('Deploy to staging release image') {
344
- when {
345
- expression { return isEnabledInDavinciYaml("master", "deploy_staging") }
346
- }
347
-
348
- steps {
349
- script {
350
- def stagingEnvironmentVariables = getEnvironmentVariables('staging')
351
-
352
- buildWithParameters(
353
- jobName: deployToStagingReleaseImageJobName,
354
- propagate: true,
355
- wait: true,
356
- parameters: [
357
- REPOSITORY_NAME: repositoryName,
358
- TAG: commitId,
359
- // TODO: remove when all legacy jobs deploy-release-image will be refactored to use k8s
360
- DOCKER_TAG: commitId,
361
- ENV: stagingEnvironmentVariables,
362
- RELEASE: 'staging'
363
- ]
364
- )
365
- }
366
- } //steps
367
- } //stage
368
-
369
- stage('Cypress tests') {
370
- when {
371
- expression { return isEnabledInDavinciYaml("master", "cypress") }
372
- }
373
-
374
- steps {
375
- script {
376
- def packageJson = readJSON(file: 'package.json', returnPojo: true)
377
- def hasIntegrationCmd = 'test:integration:ci' in (packageJson.scripts ?: [:])
378
- def testCommand = hasIntegrationCmd ? 'integration' : 'e2e'
379
-
380
- sh """
381
- docker run \
382
- --user="root" \
383
- --rm us-central1-docker.pkg.dev/toptal-hub/containers/${repositoryName}:${commitId} /bin/bash -c "apt update && apt-get -y install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb && yarn cypress install > /dev/null && yarn test:$testCommand:ci"
384
- """
385
- }
386
- } //steps
387
- } //stage
388
-
389
- stage('Deploy release image') {
390
- when {
391
- expression { return isEnabledInDavinciYaml("master", "deploy") }
392
- }
393
-
394
- steps {
395
- script {
396
- def productionEnvironmentVariables = getEnvironmentVariables('production')
397
-
398
- buildWithParameters(
399
- jobName: deployReleaseImageJobName,
400
- propagate: true,
401
- wait: true,
402
- parameters: [
403
- REPOSITORY_NAME: repositoryName,
404
- TAG: commitId,
405
- ENV: productionEnvironmentVariables,
406
- RELEASE: 'internal'
407
- ]
408
- )
409
- }
410
- } //steps
411
- } //stage
412
-
413
- } //stages
414
-
415
- post {
416
- failure {
417
- script {
418
- slackSend color: 'danger',
419
- channel: repoBullhornSlackChannel,
420
- message: "<!here> The current build on `${branch}` branch of `${repositoryName}` is broken :broken_heart:\n${getCommitDetails()}"
421
- }
422
- }
423
-
424
- aborted {
425
- script {
426
- slackSend color: 'warning',
427
- channel: repoBullhornSlackChannel,
428
- message: "The current build on `${branch}` branch of `${repositoryName}` was aborted.\n${getCommitDetails()}"
429
- }
430
- }
431
-
432
- success {
433
- script {
434
- def message = "The current build on `${branch}` branch of `${repositoryName}` is successful :green_heart:\n${getCommitDetails()}"
435
- def isReleasedAsPackage = fileExists('.version')
436
-
437
- if (isReleasedAsPackage) {
438
- NEW_PACKAGE_VERSION = sh(returnStdout: true, script: 'cat .version').trim()
439
- if (NEW_PACKAGE_VERSION) {
440
- message = message + "\n\nNew package: `${NEW_PACKAGE_VERSION}` \nSee <https://github.com/toptal/${repositoryName}/releases/tag/v${NEW_PACKAGE_VERSION}|release notes>"
441
- }
442
- }
443
-
444
- slackSend color: 'good',
445
- channel: repoBullhornSlackChannel,
446
- message: message
447
- }
448
- }
449
-
450
- always {
451
- script {
452
- // clean up created temporary folders
453
- sh "rm -rf ${jenkinsTestsCoverageDirectory}"
454
- sh "rm -rf ${jenkinsTestsPactContractsDirectory}"
455
-
456
- sendBuildData(currentBuild)
457
- }
458
- }
459
- }
460
- }
@@ -1,119 +0,0 @@
1
- <flow-definition plugin="workflow-job@2.35">
2
- <actions>
3
- <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction plugin="pipeline-model-definition@1.3.9"/>
4
- <org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction plugin="pipeline-model-definition@1.3.9">
5
- <jobProperties>
6
- <string>jenkins.model.BuildDiscarderProperty</string>
7
- </jobProperties>
8
- <triggers/>
9
- <parameters>
10
- <string>BRANCH</string>
11
- </parameters>
12
- <options>
13
- <string>skipDefaultCheckout</string>
14
- </options>
15
- </org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
16
- </actions>
17
- <description></description>
18
- <keepDependencies>false</keepDependencies>
19
- <properties>
20
- <hudson.model.ParametersDefinitionProperty>
21
- <parameterDefinitions>
22
- <hudson.model.StringParameterDefinition>
23
- <name>BRANCH</name>
24
- <description>Branch or tag to build</description>
25
- <defaultValue>master</defaultValue>
26
- <trim>false</trim>
27
- <name>GITHUB_REPO_GIT_URL</name>
28
- <description>Repository URL</description>
29
- <defaultValue>$PROJECT_URL</defaultValue>
30
- <trim>false</trim>
31
- </hudson.model.StringParameterDefinition>
32
- </parameterDefinitions>
33
- </hudson.model.ParametersDefinitionProperty>
34
- <jenkins.model.BuildDiscarderProperty>
35
- <strategy class="hudson.tasks.LogRotator">
36
- <daysToKeep>-1</daysToKeep>
37
- <numToKeep>20</numToKeep>
38
- <artifactDaysToKeep>-1</artifactDaysToKeep>
39
- <artifactNumToKeep>-1</artifactNumToKeep>
40
- </strategy>
41
- </jenkins.model.BuildDiscarderProperty>
42
- <hudson.plugins.jira.JiraProjectProperty plugin="jira@3.0.7"/>
43
- <com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty plugin="build-failure-analyzer@1.20.0">
44
- <doNotScan>false</doNotScan>
45
- </com.sonyericsson.jenkins.plugins.bfa.model.ScannerJobProperty>
46
- <com.coravy.hudson.plugins.github.GithubProjectProperty plugin="github@1.29.4">
47
- <projectUrl>$PROJECT_URL</projectUrl>
48
- <displayName></displayName>
49
- </com.coravy.hudson.plugins.github.GithubProjectProperty>
50
- <hudson.plugins.throttleconcurrents.ThrottleJobProperty plugin="throttle-concurrents@2.0.1">
51
- <maxConcurrentPerNode>0</maxConcurrentPerNode>
52
- <maxConcurrentTotal>0</maxConcurrentTotal>
53
- <categories class="java.util.concurrent.CopyOnWriteArrayList"/>
54
- <throttleEnabled>false</throttleEnabled>
55
- <throttleOption>project</throttleOption>
56
- <limitOneJobWithMatchingParams>false</limitOneJobWithMatchingParams>
57
- <paramsToUseForLimit></paramsToUseForLimit>
58
- </hudson.plugins.throttleconcurrents.ThrottleJobProperty>
59
- <org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
60
- <triggers>
61
- <com.github.kostyasha.github.integration.branch.GitHubBranchTrigger plugin="github-pullrequest@0.2.6">
62
- <spec></spec>
63
- <triggerMode>HEAVY_HOOKS</triggerMode>
64
- <cancelQueued>true</cancelQueued>
65
- <abortRunning>false</abortRunning>
66
- <skipFirstRun>false</skipFirstRun>
67
- <repoProviders>
68
- <com.github.kostyasha.github.integration.generic.repoprovider.GitHubPluginRepoProvider>
69
- <cacheConnection>true</cacheConnection>
70
- <manageHooks>true</manageHooks>
71
- <repoPermission>ADMIN</repoPermission>
72
- </com.github.kostyasha.github.integration.generic.repoprovider.GitHubPluginRepoProvider>
73
- </repoProviders>
74
- <events>
75
- <com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchHashChangedEvent/>
76
- <com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchRestrictionFilter>
77
- <exclude>false</exclude>
78
- <matchAsPattern>true</matchAsPattern>
79
- <matchCriteria>
80
- <string>master</string>
81
- </matchCriteria>
82
- </com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchRestrictionFilter>
83
- <com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchCommitMessageCheck>
84
- <exclude>true</exclude>
85
- <matchAsPattern>true</matchAsPattern>
86
- <matchCriteria>
87
- <string>(?s).*\[skip ci\].*</string>
88
- </matchCriteria>
89
- </com.github.kostyasha.github.integration.branch.events.impl.GitHubBranchCommitMessageCheck>
90
- </events>
91
- <preStatus>false</preStatus>
92
- </com.github.kostyasha.github.integration.branch.GitHubBranchTrigger>
93
- </triggers>
94
- </org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
95
- </properties>
96
- <definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.74">
97
- <scm class="hudson.plugins.git.GitSCM" plugin="git@3.10.1">
98
- <configVersion>2</configVersion>
99
- <userRemoteConfigs>
100
- <hudson.plugins.git.UserRemoteConfig>
101
- <url>git@github.com:toptal/davinci.git</url>
102
- <credentialsId>$CREDENTIALS_ID</credentialsId>
103
- </hudson.plugins.git.UserRemoteConfig>
104
- </userRemoteConfigs>
105
- <branches>
106
- <hudson.plugins.git.BranchSpec>
107
- <name>master</name>
108
- </hudson.plugins.git.BranchSpec>
109
- </branches>
110
- <doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations>
111
- <submoduleCfg class="list"/>
112
- <extensions/>
113
- </scm>
114
- <scriptPath>packages/ci/src/configs/jobs/master-main/Jenkinsfile</scriptPath>
115
- <lightweight>false</lightweight>
116
- </definition>
117
- <triggers/>
118
- <disabled>false</disabled>
119
- </flow-definition>