-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathmbedtls.groovy
206 lines (180 loc) · 7.18 KB
/
mbedtls.groovy
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
/*
* Copyright (c) 2018-2021, Arm Limited, All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* This file is part of Mbed TLS (https://www.trustedfirmware.org/projects/mbed-tls/)
*/
import hudson.model.Cause
import hudson.model.Result
import hudson.triggers.TimerTrigger
import jenkins.model.CauseOfInterruption
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
import org.mbed.tls.jenkins.BranchInfo
void run_tls_tests(Collection<BranchInfo> infos) {
try {
def jobs = [:]
infos.each { info ->
def label_prefix = infos.size() > 1 ? "$info.branch-" : ''
jobs << gen_jobs.gen_release_jobs(info, label_prefix, false)
if (env.RUN_ABI_CHECK == "true") {
jobs << gen_jobs.gen_abi_api_checking_job(info, 'ubuntu-18.04-amd64', label_prefix)
}
}
jobs = common.wrap_report_errors(jobs)
jobs.failFast = false
analysis.record_inner_timestamps('main', 'run_pr_job') {
parallel jobs
}
} catch (err) {
def failed_names = infos.collectMany({ info -> info.failed_builds}).sort().join(" ")
echo "Caught: ${err}"
echo "Failed jobs: ${failed_names}"
common.maybe_notify_github('FAILURE', "Failures: ${failed_names}")
throw err
}
}
/* main job */
void run_pr_job(String target_repo, boolean is_production, String branches) {
run_pr_job(target_repo, is_production, branches.split(',') as List)
}
void run_pr_job(String target_repo, boolean is_production, List<String> branches) {
analysis.main_record_timestamps('run_pr_job') {
if (is_production) {
// Cancel in-flight jobs for the same PR when a new job is launched
def buildNumber = env.BUILD_NUMBER as int
if (buildNumber > 1)
milestone(buildNumber - 1)
/* If buildNumber > 1, the following statement aborts all builds
* whose most-recently passed milestone was the previous milestone
* passed by this job (buildNumber - 1).
* After this, it checks to see if a later build has already passed
* milestone(buildNumber), and if so aborts the current build as well.
*
* Because of the order of operations, each build is only responsible
* for aborting the one directly before it, and itself if necessary.
* Thus we don't have to iterate over all milestones 1 to buildNumber.
*/
milestone(buildNumber)
/* Discarding old builds has to be individually configured for each
* branch in a multibranch pipeline, so do it from groovy.
*/
properties([
buildDiscarder(
logRotator(
numToKeepStr: '5'
)
)
])
}
environ.set_pr_environment(target_repo, is_production)
boolean is_merge_queue = env.BRANCH_NAME ==~ /gh-readonly-queue\/.*/
if (!is_merge_queue && currentBuild.rawBuild.getCause(Cause.UserIdCause) == null) {
if (!common.pr_author_has_write_access("$env.GITHUB_ORG/$env.GITHUB_REPO", env.CHANGE_ID as int)) {
echo 'PR author not found on allowlist - not building'
throw new FlowInterruptedException(Result.NOT_BUILT, new CauseOfInterruption[0])
}
}
List<BranchInfo> infos
try {
common.maybe_notify_github('PENDING', 'In progress')
if (common.is_open_ci_env && is_merge_queue) {
// Fake required checks that don't run in the merge queue
def skipped_checks = [
'DCO',
'docs/readthedocs.org:mbedtls-versioned',
'Travis CI - Pull Request',
]
for (check in skipped_checks) {
common.maybe_notify_github('SUCCESS', 'Check passed on PR-head', check)
}
}
common.init_docker_images()
stage('branch-info') {
infos = common.get_branch_information(branches)
}
stage('pre-test-checks') {
common.check_every_all_sh_component_will_be_run(infos)
}
} catch (err) {
def description = 'Pre-test checks failed.'
if (err.message?.startsWith('Pre-test checks')) {
description = err.message
}
common.maybe_notify_github('FAILURE', description)
throw (err)
}
try {
stage('tls-testing') {
run_tls_tests(infos)
}
} finally {
stage('result-analysis') {
analysis.analyze_results(infos)
}
}
common.maybe_notify_github('SUCCESS', 'All tests passed')
}
}
/* main job */
void run_job() {
// CHANGE_BRANCH is not set in "branch" jobs, eg. in the merge queue
run_pr_job('tls', true, env.CHANGE_BRANCH ?: env.BRANCH_NAME)
}
void run_framework_pr_job() {
run_pr_job('framework', true, ['development', 'mbedtls-3.6'])
}
void run_release_job(String branches) {
run_release_job(branches.split(',') as List)
}
void run_release_job(List<String> branches) {
analysis.main_record_timestamps('run_release_job') {
List<BranchInfo> infos = []
try {
environ.set_tls_release_environment()
common.init_docker_images()
stage('branch-info') {
infos = common.get_branch_information(branches)
}
try {
stage('tls-testing') {
def jobs = infos.collectEntries { info ->
String prefix = branches.size() > 1 ? "$info.branch-" : ''
return gen_jobs.gen_release_jobs(info, prefix)
}
jobs = common.wrap_report_errors(jobs)
jobs.failFast = false
analysis.record_inner_timestamps('main', 'run_release_job') {
parallel jobs
}
}
}
finally {
stage('result-analysis') {
analysis.analyze_results(infos)
}
}
} finally {
stage('email-report') {
String type
if (currentBuild.rawBuild.getCause(TimerTrigger.TimerTriggerCause) != null) {
type = 'nightly'
} else {
type = 'release'
}
common.maybe_send_email("Mbed TLS $type tests", infos)
}
}
}
}