-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile.proto
140 lines (120 loc) · 5.09 KB
/
Jenkinsfile.proto
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
library(
identifier: 'jenkins-shared-library@master',
retriever: modernSCM(
[
$class: 'GitSCMSource',
remote: 'https://github.com/dhanarab/jenkins-pipeline-library.git'
]
)
)
bitbucketNamespace = "accelbyte"
bitbucketCredentialsHttps = "bitbucket-build-extend-https"
bitbucketCredentialsSsh = "bitbucket-build-extend-ssh"
repoName = "accelbyte-api-proto"
repoPath = null
repoBranchName = null
repoCommitHash = null
repoCommitHashShort = null
repoCommitMessage = null
specRepoName = "justice-api-specification"
specRepoPath = null
specRepoCommitHash = null
codegenRepoName = "justice-codegen-modular-sdk"
codegenRepoPath = null
codegenRepoCommitHash = null
toolsRepoName = "accelbyte-api-proto-tools"
toolsRepoPath = null
toolsRepoCommitHash = null
slackActivityChannel = "#activity-extend-engineering"
pipeline {
agent {
label "extend-builder-batch"
}
stages {
stage("Prepare") {
steps {
script {
repoPath = "${env.WORKSPACE}/${repoName}"
specRepoPath = "${env.WORKSPACE}/${specRepoName}"
codegenRepoPath = "${env.WORKSPACE}/${codegenRepoName}"
toolsRepoPath = "${env.WORKSPACE}/${toolsRepoName}"
sh "rm -rf ${specRepoPath}"
sh "rm -rf ${codegenRepoPath}"
sh "rm -rf ${toolsRepoPath}"
sshagent(credentials: [bitbucketCredentialsSsh]) {
sh "git clone --depth 1 git@bitbucket.org:${bitbucketNamespace}/${specRepoName}.git ${specRepoPath}"
sh "git clone --depth 1 git@bitbucket.org:${bitbucketNamespace}/${codegenRepoName}.git ${codegenRepoPath}"
sh "git clone --depth 1 git@bitbucket.org:${bitbucketNamespace}/${toolsRepoName}.git ${toolsRepoPath}"
}
dir(specRepoPath) {
specRepoCommitHash = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}
dir(codegenRepoPath) {
codegenRepoCommitHash = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}
dir(toolsRepoPath) {
toolsRepoCommitHash = sh(returnStdout: true, script: "git rev-parse HEAD").trim()
}
}
}
}
stage("Run") {
steps {
sh "rm -rf asyncapi.old"
sh "cp -r asyncapi asyncapi.old"
dir("${toolsRepoPath}/cicd") {
sh "make dbuild drun_1rpc1s CODEGEN_SDK_PATH=${codegenRepoPath} SPEC_PATH=${specRepoPath}"
}
sh "cp asyncapi.old/buf.yaml asyncapi/buf.yaml" // Restore asyncapi/buf.yaml
sh "rm -rf asyncapi.old"
}
}
stage('Lint') {
steps {
sh "make lint"
}
}
stage('Check Proto Governance') {
steps {
script {
sh 'make governance'
}
}
}
stage("Update") {
steps {
script {
if (sh(script: "git add asyncapi && git status --porcelain asyncapi | grep -v -e 'TIMESTAMP'", returnStatus: true) == 0) {
zip(zipFile: "asyncapi.zip", dir: "asyncapi/", overwrite: true, archive: true)
repoBranchName = sh(script: "echo ${env.GIT_BRANCH} | grep -oP '(?<=origin/).+'", returnStdout: true).trim()
sshagent(credentials: [bitbucketCredentialsSsh]) {
sh "git commit -m \"chore(proto): update proto files \$(cat asyncapi/TIMESTAMP)\" && git push origin HEAD:${repoBranchName}"
}
repoCommitHash = git.getCommitHash()
repoCommitHashShort = git.getCommitHashShort()
repoCommitMessage = git.getCommitMessage()
message = """
:white_check_mark: <${env.BUILD_URL}|${env.JOB_NAME}-${env.BUILD_NUMBER}> *proto files updated*
|*${repoName}:*
|<https://bitbucket.org/accelbyte/${repoName}/commits/${repoCommitHash}|${repoBranchName} ${repoCommitHashShort}>
|${repoCommitMessage}
|*Artifacts:*
|<${env.BUILD_URL}artifact|Build Artifacts>
|""".stripMargin()
slackSend(channel: "${slackActivityChannel}", color: '#36B37E', message: message)
}
}
}
}
}
post {
failure {
script {
message = """
:no_entry: <${env.BUILD_URL}|${env.JOB_NAME}-${env.BUILD_NUMBER}> *proto files update failed*
|""".stripMargin()
slackSend(channel: "${slackActivityChannel}", color: '#FF0000', message: message)
}
}
}
}