-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.generate
246 lines (208 loc) · 9.28 KB
/
Jenkinsfile.generate
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
library(
identifier: 'jenkins-shared-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/dhanarab/jenkins-pipeline-library.git'
]
)
)
bitbucketCredentialsHttps = "bitbucket-build-extend-https"
bitbucketCredentialsSsh = "bitbucket-build-extend-ssh"
bitbucketCommitHref = null
sdkSpecRepoName = "justice-codegen-sdk-spec"
sdkCodegenRepoName = "justice-codegen-modular-sdk"
mockServerRepoName = "justice-codegen-sdk-mock-server"
sdkRepoName="justice-codegen-java-modular-sdk"
sdkSpecEnvironmentName = "stage"
sdkCodegenGenerateBranchName = "master"
sdkGenerateBranchName = "rc-nightly"
sdkSpecCommitHash = null
sdkCommitHash = null
sdkSpecPath = null
sdkCodegenPath = null
mockServerPath = null
sdkPath = null
sdkCodegenExe = "accelbyte-codegen-linux_amd64"
breakingChangeCheckExitCode = 0
outstandingDeprecationCount = 0
jobChannel = env.SLACK_CHANNEL_ACTIVITY_EXTEND_CODEGEN_MODULAR_SDK ? env.SLACK_CHANNEL_ACTIVITY_EXTEND_CODEGEN_MODULAR_SDK : "#activity-justice-codegen-modular-sdk"
def getTimestampUtc() {
now = new Date()
return now.format("yyyy-MM-dd'T'HH:mm:ss+00:00", TimeZone.getTimeZone('UTC'))
}
pipeline {
agent {
label "extend-builder-batch"
}
stages {
// -------------------------------------- Prepare --------------------------------------
stage("Prepare") {
steps {
script {
sdkCodegenPath = "${env.WORKSPACE}/${sdkCodegenRepoName}"
mockServerPath = "${env.WORKSPACE}/${mockServerRepoName}"
sdkSpecPath = "${env.WORKSPACE}/${sdkSpecRepoName}"
sdkPath = "${env.WORKSPACE}/${sdkRepoName}"
sh "rm -rf ${sdkCodegenRepoName}"
sh "rm -rf ${mockServerRepoName}"
sh "rm -rf ${sdkSpecRepoName}"
sshagent(credentials: [bitbucketCredentialsSsh]) {
sh "git clone --branch ${sdkCodegenGenerateBranchName} --depth 1 [email protected]:accelbyte/${sdkCodegenRepoName}.git ${sdkCodegenPath}"
sh "git clone --depth 1 [email protected]:accelbyte/${mockServerRepoName}.git ${mockServerPath}"
sh "git clone --depth 50 [email protected]:accelbyte/${sdkSpecRepoName}.git ${sdkSpecPath}"
}
dir(sdkSpecPath) {
sdkSpecCommitHash = sh(returnStdout: true, script: "git rev-list -1 HEAD spec/${sdkSpecEnvironmentName}_extend-sdk/TIMESTAMP").trim()
}
}
}
}
// -------------------------------------- Generate --------------------------------------
stage("Generate SDK") {
steps {
// Setup generate branch
dir(sdkRepoName) {
sh "git branch ${sdkGenerateBranchName}"
sh "git checkout ${sdkGenerateBranchName}"
}
// Copy latest OpenAPI spec from spec repository to SDK repository
sh "rm -fv ${sdkPath}/spec/*"
sh "find ${sdkSpecPath}/spec/${sdkSpecEnvironmentName}_extend-sdk/ -maxdepth 1 -type f -exec cp -v -t ${sdkPath}/spec/ {} \\;"
sh "cp -v ${sdkSpecPath}/docs/openapi-2.0-vendor-extensions.md ${sdkPath}/spec/"
// Build Linux Executable
dir(sdkCodegenPath) {
sh script: "make build-linux", label: "Build Linux Executable"
}
// Generate SDK (SDK only)
dir(sdkCodegenPath) {
sh script: "cd templates/java-modular-extend-sdk && make sdk_all CODEGEN_PATH=${sdkCodegenPath}/${sdkCodegenExe} SDK_PATH=${sdkPath} SPEC_PATH=${sdkPath}/spec", label: "Generate SDK (SDK only)"
}
// Check code-level breaking changes
dir(sdkPath) {
script {
breakingChangeCheckExitCode = sh script: "make samples", returnStatus: true, label: "Check code-level breaking changes"
}
}
// Generate SDK (CLI, CLI tests, Docs, Style, Revision)
dir(sdkCodegenPath) {
sh script: "cd templates/java-modular-extend-sdk && make cli_cmd_all cli_test_all doc_index_all style revision CODEGEN_PATH=${sdkCodegenPath}/${sdkCodegenExe} SDK_PATH=${sdkPath} SPEC_PATH=${sdkPath}/spec", label: "Generate SDK (CLI, CLI tests, Docs, Style, Revision)"
}
// Bump SDK version and commit the generated code to generate branch (overwrite existing)
dir(sdkRepoName) {
sh '''git ls-files | grep -E '^module[^/]*/.*(version.txt)$' | xargs git restore'''
sh "make version"
sh "git add --all"
sh "git commit -m 'chore(sdk): generate java extend sdk (${getTimestampUtc()})' -m 'generated from openapi spec commit: ${sdkSpecCommitHash}'"
sshagent(credentials: [bitbucketCredentialsSsh]) {
sh "git push --set-upstream origin +${sdkGenerateBranchName}:${sdkGenerateBranchName}"
}
script {
sdkCommitHash = git.getCommitHash()
bitbucketCommitHref = "https://api.bitbucket.org/2.0/repositories/accelbyte/${sdkRepoName}/commit/${sdkCommitHash}"
bitbucket.setBuildStatus(bitbucketCredentialsHttps, bitbucketCommitHref, "INPROGRESS", env.JOB_NAME.take(30), "${env.JOB_NAME}-${env.BUILD_NUMBER}", "Jenkins", "${env.BUILD_URL}console")
}
}
// Check outstanding deprecation
script {
dir(sdkRepoName) {
// Ignore exit code, just need the outstanding_deprecation.out file
sh script: "make outstanding_deprecation || true", label: "Check outstanding deprecation"
if (!fileExists('outstanding_deprecation.out')) {
error("File 'outstanding_deprecation.out' is not found")
}
outstandingDeprecationCount = sh(returnStdout: true, script: "grep -c '^not ok' outstanding_deprecation.out || true").trim() as Integer
}
}
}
}
// -------------------------------------- Tests --------------------------------------
stage('Core Tests') {
steps {
dir(sdkRepoName) {
sh "make test_core SDK_MOCK_SERVER_PATH=${mockServerPath}"
}
}
}
stage('CLI Tests') {
steps {
dir(sdkRepoName) {
sh "make test_cli SDK_MOCK_SERVER_PATH=${mockServerPath}"
}
}
post {
always {
script {
dir(sdkRepoName) {
archiveArtifacts artifacts: 'samples/cli/tests/*.tap'
step([$class: "TapPublisher", testResults: "samples/cli/tests/*.tap"])
}
}
}
}
}
stage('Integration Tests') {
options {
lock("justice-demo-serversdktest")
}
environment {
DEFAULT_IFACE = sh(script: 'ip route get 1.1.1.1 | awk \'NR==2 {print $1}\' RS=dev', returnStdout: true)
}
steps {
sh 'sudo tc qdisc add dev $DEFAULT_IFACE root netem delay 100ms' // Delay sending packets due to database eventual consistency
dir(sdkRepoName) {
withCredentials([file(credentialsId: 'justice-codegen-sdk-integration-test-env', variable: 'ENV_FILE_PATH')]) {
sh 'make test_integration ENV_FILE_PATH=$ENV_FILE_PATH'
}
}
}
post {
always {
sh 'sudo tc qdisc del dev $DEFAULT_IFACE root netem delay 100ms'
dir(sdkRepoName) {
junit 'all-module/build/test-results/testIntegration/*.xml'
}
}
}
}
}
post{
success {
script {
if (bitbucketCommitHref != null) {
bitbucket.setBuildStatus(bitbucketCredentialsHttps, bitbucketCommitHref, "SUCCESSFUL", env.JOB_NAME.take(30), "${env.JOB_NAME}-${env.BUILD_NUMBER}", "Jenkins", "${env.BUILD_URL}console")
}
additionalInfo = ""
if (breakingChangeCheckExitCode != 0) {
additionalInfo += """
| :warning: Possible Breaking Changes Detected: <${env.BUILD_URL}/flowGraphTable/#:~:text=Check%20code%2Dlevel%20breaking%20changes|here>"""
}
if (outstandingDeprecationCount != 0) {
additionalInfo += """
| :warning: Outstanding Deprecation Detected: <${env.BUILD_URL}/flowGraphTable/#:~:text=Check%20outstanding%20deprecation|${outstandingDeprecationCount}>"""
}
specLink = "https://bitbucket.org/accelbyte/justice-codegen-sdk-spec/commits/${sdkSpecCommitHash}"
sdkLink = "https://bitbucket.org/accelbyte/${sdkRepoName}/commits/${sdkCommitHash}"
message = """
:white_check_mark: <${env.BUILD_URL}|${env.JOB_NAME}-${env.BUILD_NUMBER}> *Generate Java Extend SDK Successful :coffee:*
|*OpenAPI Spec:* <${specLink}|${sdkSpecCommitHash}>
|*Generated SDK:* <${sdkLink}|${sdkCommitHash}>
|<https://bitbucket.org/accelbyte/${sdkRepoName}/pull-requests/new?source=${sdkGenerateBranchName}|Compare or Create Pull Request>
${additionalInfo}
|""".stripMargin()
slackSend(channel: jobChannel, color: '#36B37E', message: message)
}
}
failure {
script {
if (bitbucketCommitHref != null) {
bitbucket.setBuildStatus(bitbucketCredentialsHttps, bitbucketCommitHref, "FAILED", env.JOB_NAME.take(30), "${env.JOB_NAME}-${env.BUILD_NUMBER}", "Jenkins", "${env.BUILD_URL}console")
}
message = """
:no_entry: <${env.BUILD_URL}|${env.JOB_NAME}-${env.BUILD_NUMBER}> *failed*
|""".stripMargin()
slackSend(channel: jobChannel, color: '#FF0000', message: message)
}
}
}
}