-
Notifications
You must be signed in to change notification settings - Fork 6
/
Jenkinsfile.generate
223 lines (193 loc) · 8.34 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
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
sdkRepoName="justice-codegen-go-sdk"
sdkGenerateBranchName = "rc-nightly"
sdkSpecCommitHash = null
sdkCommitHash = null
sdkSpecPath = null
sdkCodegenPath = null
mockServerPath = null
sdkPath = null
breakingChangeCheckExitCode = 0
outstandingDeprecationCount = 0
jobChannel = env.SLACK_CHANNEL_ACTIVITY_EXTEND_CODEGEN_SDK ? env.SLACK_CHANNEL_ACTIVITY_EXTEND_CODEGEN_SDK : "#activity-justice-codegen-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}/justice-codegen-sdk"
mockServerPath = "${env.WORKSPACE}/justice-codegen-sdk-mock-server"
sdkSpecPath = "${env.WORKSPACE}/justice-codegen-sdk-spec"
sdkPath = "${env.WORKSPACE}/${sdkRepoName}"
sh "rm -rf justice-codegen-sdk"
sh "rm -rf justice-codegen-sdk-mock-server"
sh "rm -rf justice-codegen-sdk-spec"
sshagent(credentials: [bitbucketCredentialsSsh]) {
sh "git clone --depth 1 [email protected]:accelbyte/justice-codegen-sdk.git ${sdkCodegenPath}"
sh "git clone --depth 1 [email protected]:accelbyte/justice-codegen-sdk-mock-server.git ${mockServerPath}"
sh "git clone --depth 50 [email protected]:accelbyte/justice-codegen-sdk-spec.git ${sdkSpecPath}"
}
dir(sdkSpecPath) {
sdkSpecCommitHash = sh(returnStdout: true, script: "git rev-list -1 HEAD spec/stage_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/stage_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/"
// Generate SDK only
dir(sdkCodegenPath) {
sh script: "make -f Makefile.sdk-go sdk_all SDK_PATH=${sdkPath}", label: "Generate SDK only"
}
// Check code-level breaking changes
dir(sdkPath) {
script {
breakingChangeCheckExitCode = sh script: "make samples", returnStatus: true, label: "Check code-level breaking changes"
}
}
// Generate the rest of the SDK
dir(sdkCodegenPath) {
sh script: "make -f Makefile.sdk-go cli_all cli_test_all doc_operation_all doc_common_use_cases beautify changelog SDK_PATH=${sdkPath}", label: "Generate the rest of SDK release"
}
// Bump SDK version and commit the generated code to generate branch (overwrite existing)
dir(sdkRepoName) {
sh "make version"
sh "git add --all"
sh "git commit -m 'chore(sdk): generate go 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, "${env.JOB_NAME}-${env.BUILD_NUMBER}", "Jenkins", "${env.BUILD_URL}console")
}
}
// Check outstanding deprecation
script {
dir(sdkRepoName) {
sh script: "make outstanding_deprecation || true", label: "Check outstanding deprecation" // Ignore exit code, just need the outstanding_deprecation.out file
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 {
dir(sdkRepoName) {
sh 'sudo tc qdisc add dev $DEFAULT_IFACE root netem delay 100ms' // Delay sending packets due to database eventual consistency
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'
}
}
}
}
post{
success {
script {
if (bitbucketCommitHref != null) {
bitbucket.setBuildStatus(bitbucketCredentialsHttps, bitbucketCommitHref, "SUCCESSFUL", env.JOB_NAME, "${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 Go Extend SDK Successful :gopher:*
|*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, "${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)
}
}
}
}