forked from sora-xor/sora2-network
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
266 lines (262 loc) · 11.5 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
@Library('jenkins-library')
String agentLabel = 'docker-build-agent'
String registry = 'docker.soramitsu.co.jp'
String dockerBuildToolsUserId = 'bot-build-tools-ro'
String dockerRegistryRWUserId = 'bot-sora2-rw'
String cargoAuditImage = registry + '/build-tools/cargo_audit'
String envImageName = registry + '/sora2/env:sub4'
String rustcVersion = 'nightly-2021-12-10'
String wasmReportFile = 'subwasm_report.json'
String palletListFile = 'pallet_list.txt'
String appImageName = 'docker.soramitsu.co.jp/sora2/substrate'
String secretScannerExclusion = '.*Cargo.toml\$|.*pr.sh\$'
Boolean disableSecretScanner = false
int sudoCheckStatus = 0
String featureList = 'private-net include-real-files reduced-pswap-reward-periods'
Map pushTags = ['master': 'latest', 'develop': 'dev','substrate-4.0.0': 'sub4']
String contractsPath = 'ethereum-bridge-contracts'
String contractsEnvFile = 'env.template'
String solcVersion = '0.8.14'
String nodeVersion = '14.16.1'
String gitHubUser = 'sorabot'
String gitHubRepo = 'github.com/sora-xor/sora2-network.git'
String gitHubBranch = 'doc'
String gitHubEmail = '[email protected]'
String cargoDocImage = 'rust:1.62.0-slim-bullseye'
String githubPrCreator = 'ubuntu:jammy-20221020'
String checkChangesToRegexp = '(Jenkinsfile|housekeeping|liquidity-proxy|common|pallets|)'
Boolean hasChanges(String regexp) {
echo "Comparing current changes with origin/${env.CHANGE_TARGET}"
return !env.CHANGE_TARGET || sh(
returnStatus: true,
returnStdout: true,
script: "(git diff-tree --name-only origin/${env.CHANGE_TARGET} ${env.GIT_COMMIT} | egrep '${regexp}')"
) == 0
}
Boolean prStatusNotif = true
String telegramChatId = 'telegram-deploy-chat-id'
String telegramChatIdPswap = 'telegramChatIdPswap'
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '20'))
timestamps()
disableConcurrentBuilds()
}
agent {
label agentLabel
}
stages {
stage('Secret scanner') {
steps {
script {
gitNotify('main-CI', 'PENDING', 'This commit is being built')
docker.withRegistry('https://' + registry, dockerBuildToolsUserId) {
secretScanner(disableSecretScanner, secretScannerExclusion)
}
}
}
}
stage('Audit') {
steps {
script {
docker.withRegistry( 'https://' + registry, dockerBuildToolsUserId) {
docker.image(cargoAuditImage + ':latest').inside(){
sh '''
rm -rf ~/.cargo/.package-cache
rm Cargo.lock
cargo audit > cargoAuditReport.txt || exit 0
'''
archiveArtifacts artifacts: "cargoAuditReport.txt"
}
}
}
}
}
stage('Solidity Static Scanner') {
steps {
script {
docker.withRegistry('https://' + registry, dockerBuildToolsUserId) {
slither(contractsPath, contractsEnvFile, solcVersion, nodeVersion)
}
}
}
}
stage('Build & Tests') {
environment {
PACKAGE = 'framenode-runtime'
RUSTFLAGS = '-Dwarnings'
RUNTIME_DIR = 'runtime'
RUSTC_VERSION = "${rustcVersion}"
}
steps {
script {
docker.withRegistry('https://' + registry, dockerRegistryRWUserId) {
if (getPushVersion(pushTags)) {
docker.image(envImageName).inside() {
if (env.TAG_NAME =~ 'benchmarking.*') {
featureList = 'runtime-benchmarks main-net-coded'
sudoCheckStatus = 101
}
else if (env.TAG_NAME =~ 'stage.*') {
featureList = 'private-net include-real-files'
sudoCheckStatus = 0
}
else if (env.TAG_NAME =~ 'test.*') {
featureList = 'private-net include-real-files reduced-pswap-reward-periods'
sudoCheckStatus = 0
}
else if (env.TAG_NAME) {
featureList = 'include-real-files'
sudoCheckStatus = 101
}
sh """
cargo test --release --features runtime-benchmarks
rm -rf target
cargo build --release --features \"${featureList}\"
mv ./target/release/framenode .
mv ./target/release/relayer ./relayer.bin
mv ./target/release/wbuild/framenode-runtime/framenode_runtime.compact.compressed.wasm ./framenode_runtime.compact.compressed.wasm
wasm-opt -Os -o ./framenode_runtime.compact.wasm ./target/release/wbuild/framenode-runtime/framenode_runtime.compact.wasm
subwasm --json info framenode_runtime.compact.wasm > ${wasmReportFile}
subwasm metadata framenode_runtime.compact.wasm > ${palletListFile}
set +e
subwasm metadata -m Sudo target/release/wbuild/framenode-runtime/framenode_runtime.compact.wasm
if [ \$(echo \$?) -eq \"${sudoCheckStatus}\" ]; then echo "sudo check is successful!"; else echo "sudo check is failed!"; exit 1; fi
"""
archiveArtifacts artifacts:
"framenode_runtime.compact.wasm, framenode_runtime.compact.compressed.wasm, ${wasmReportFile}, ${palletListFile}"
}
} else {
docker.image(envImageName).inside() {
sh '''
rm -rf ~/.cargo/.package-cache
rm Cargo.lock
cargo fmt -- --check > /dev/null
cargo test
cargo test --features private-net
cargo test --features runtime-benchmarks
'''
}
}
}
}
}
}
stage('Code Coverage') {
when {
expression { getPushVersion(pushTags) || env.BRANCH_NAME.startsWith('PR-') }
}
steps {
script {
docker.withRegistry('https://' + registry, dockerRegistryRWUserId) {
docker.image(envImageName).inside() {
sh './housekeeping/coverage.sh'
cobertura coberturaReportFile: 'cobertura_report'
}
}
}
}
}
stage('Push Image') {
when {
expression { getPushVersion(pushTags) }
}
steps {
script {
sh "docker build -f housekeeping/docker/release/Dockerfile -t ${appImageName} ."
baseImageTag = "${getPushVersion(pushTags)}"
docker.withRegistry('https://' + registry, dockerRegistryRWUserId) {
sh """
docker tag ${appImageName} ${appImageName}:${baseImageTag}
docker push ${appImageName}:${baseImageTag}
"""
}
docker.withRegistry('https://index.docker.io/v1/', 'docker-hub-credentials') {
sh """
docker tag ${appImageName} sora2/substrate:${baseImageTag}
docker push sora2/substrate:${baseImageTag}
"""
}
}
}
}
stage('Build docs & publish') {
when {
expression { return (env.GIT_BRANCH == "master" || env.TAG_NAME) }
}
environment {
GH_USER = "${gitHubUser}"
GH_TOKEN = credentials('sorabot-github-token')
GH_REPOSITORY = "${gitHubRepo}"
GH_BRANCH = "${gitHubBranch}"
GH_EMAIL = "${gitHubEmail}"
}
steps {
script {
docker.image("${cargoDocImage}").inside() {
sh './housekeeping/docs.sh'
}
}
}
}
stage('Assign reviewers to PR') {
when {
allOf {
expression { hasChanges(checkChangesToRegexp) }
expression { env.BRANCH_NAME.startsWith('PR-') }
}
}
environment {
GH_USER = "${gitHubUser}"
GH_TOKEN = credentials('sorabot-github-token')
GH_REPOSITORY = "${gitHubRepo}"
GH_EMAIL = "${gitHubEmail}"
BRANCH_NAME_PR = "${env.BRANCH_NAME.startsWith('PR-')}"
BRANCH_NAME = "${env.BRANCH_NAME}"
BRANCH_NAME_TO_SWITCH = "${env.GIT_BRANCH}"
CHANGE_TARGET = "${env.CHANGE_TARGET}"
GIT_COMMIT = "${env.GIT_COMMIT}"
GIT_AUTHOR = "${env.GIT_AUTHOR_NAME}"
}
steps {
script {
docker.image("${githubPrCreator}").inside() {
sh './housekeeping/pr.sh'
RESULT=sh (
script : 'git diff-tree --name-only origin/$CHANGE_TARGET $GIT_COMMIT',
returnStdout: true
).trim()
}
}
}
}
stage ('Send Notification about PR') {
when {
allOf {
expression { prStatusNotif }
expression { env.BRANCH_NAME.startsWith('PR-') }
}
}
environment {
TELEGRAM_CHAT_ID = credentials("${telegramChatId}")
TELEGRAM_CHAT_ID_PSWAP = credentials("${telegramChatIdPswap}")
RESULT = "${RESULT}"
}
steps {
pushNotiTelegram(
prStatusNotif: prStatusNotif,
telegramChatId: "${TELEGRAM_CHAT_ID}",
telegramChatIdPswap: "${TELEGRAM_CHAT_ID_PSWAP}"
)
}
}
}
post {
always {
script{
gitNotify('main-CI', currentBuild.result, currentBuild.result)
}
}
cleanup { cleanWs() }
}
}