Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 1 | #!/usr/bin/env groovy |
| 2 | //------------------------------------------------------------------------------- |
| 3 | // Copyright (c) 2020, Arm Limited and Contributors. All rights reserved. |
| 4 | // |
| 5 | // SPDX-License-Identifier: BSD-3-Clause |
| 6 | // |
| 7 | //------------------------------------------------------------------------------- |
| 8 | |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 9 | @Library('trustedfirmware') _ |
| 10 | import org.trustedfirmware.Gerrit |
| 11 | import org.trustedfirmware.Summary |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 12 | |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 13 | def listConfigs(ci_scripts_dir, config_list, filter_group) { |
| 14 | dir(ci_scripts_dir) { |
| 15 | echo "Obtaining list of configs." |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 16 | echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")}" |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 17 | def build_config_list_raw = sh(script: """\ |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 18 | python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 19 | """, returnStdout: true).trim() |
| 20 | def build_config_list = build_config_list_raw.tokenize('\n') |
| 21 | config_list.addAll(build_config_list) |
| 22 | } |
| 23 | } |
| 24 | |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 25 | def buildConfig(ci_scripts_dir, config, filter_group, results) { |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 26 | def params = [] |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 27 | def params_collection = [:] |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 28 | def build_config_params |
| 29 | dir(ci_scripts_dir) { |
| 30 | echo "Obtaining build configuration for config ${config}" |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 31 | echo "Running: python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config}" |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 32 | build_config_params = sh(script: """\ |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 33 | python3 ./configs.py -g ${filter_group.replace(" ", " -g ")} ${config} |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 34 | """, returnStdout: true).trim() |
| 35 | } |
| 36 | def lines = build_config_params.tokenize('\n') |
| 37 | for (String line : lines) { |
| 38 | def key, value |
| 39 | (key, value) = line.tokenize('=') |
| 40 | params += string(name: key, value: value) |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 41 | params_collection[key] = value |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 42 | } |
| 43 | params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH) |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 44 | params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST) |
| 45 | params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER) |
| 46 | params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 47 | params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC) |
| 48 | params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION) |
| 49 | params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION) |
| 50 | params += string(name: 'CODE_REPO', value: env.CODE_REPO) |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 51 | return { -> results |
| 52 | def build_res = build(job: 'tf-m-build-config', parameters: params, propagate: false) |
| 53 | def build_info = [build_res, config, params_collection] |
| 54 | results['builds'][build_res.number] = build_info |
| 55 | def build_url = build_res.getAbsoluteUrl() |
| 56 | print("${build_res.number}: ${config} ${build_res.result} ${build_url}") |
| 57 | failure_states = ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"] |
| 58 | if (build_res.result in failure_states) { |
| 59 | error("Build failed at ${build_url}") |
| 60 | } |
| 61 | else { |
| 62 | print("Doing LAVA stuff for ${build_url}") |
| 63 | params += string(name: 'BUILD_NUMBER', value: "${build_res.number}") |
| 64 | params += string(name: 'BUILD_URL', value: build_url) |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 65 | params += string(name: 'LAVA_URL', value: env.LAVA_URL) |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 66 | def lava_res = build(job: 'tf-m-lava-submit', parameters: params, propagate: false) |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 67 | if (lava_res.result in failure_states) { |
| 68 | error("LAVA Create and Submit failed at ${lava_res.getAbsoluteUrl()}") |
| 69 | } |
| 70 | else { |
| 71 | results['lava_jobs'] += lava_res.getDescription() |
| 72 | } |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
Matthew Hart | 06340d7 | 2020-06-15 16:08:20 +0100 | [diff] [blame^] | 77 | def buildDocs(results) { |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 78 | def params = [] |
| 79 | params += string(name: 'GERRIT_BRANCH', value: env.GERRIT_BRANCH) |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 80 | params += string(name: 'GERRIT_HOST', value: env.GERRIT_HOST) |
| 81 | params += string(name: 'GERRIT_CHANGE_NUMBER', value: env.GERRIT_CHANGE_NUMBER) |
| 82 | params += string(name: 'GERRIT_PATCHSET_REVISION', value: env.GERRIT_PATCHSET_REVISION) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 83 | params += string(name: 'GERRIT_REFSPEC', value: env.GERRIT_REFSPEC) |
| 84 | params += string(name: 'CMSIS_VERSION', value: env.CMSIS_VERSION) |
| 85 | params += string(name: 'MBEDCRYPTO_VERSION', value: env.MBEDCRYPTO_VERSION) |
| 86 | params += string(name: 'CODE_REPO', value: env.CODE_REPO) |
Matthew Hart | 06340d7 | 2020-06-15 16:08:20 +0100 | [diff] [blame^] | 87 | return { -> results |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 88 | def res = build(job: 'tf-m-build-docs', parameters: params, propagate:false) |
| 89 | print("${res.number}: Docs ${res.result} ${res.getAbsoluteUrl()}") |
Matthew Hart | 06340d7 | 2020-06-15 16:08:20 +0100 | [diff] [blame^] | 90 | results['docs'] = [res.number, res.result, params] |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 91 | if (res.result in ["FAILURE", "ABORTED", "UNSTABLE", "NOT_BUILT"]) { |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 92 | error("Build failed at ${res.getAbsoluteUrl()}") |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 97 | |
| 98 | def buildCsv(results) { |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 99 | def summary = new Summary(); |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 100 | def csvContent = summary.getBuildCsv(results) |
| 101 | node("master") { |
| 102 | writeCSV file: 'build_results.csv', records: csvContent, format: CSVFormat.EXCEL |
| 103 | archiveArtifacts 'build_results.csv' |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | def writeSummary(results) { |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 108 | def summary = new Summary(); |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 109 | def buildLinks = summary.getLinks(results) |
| 110 | node("master") { |
| 111 | writeFile file: "build_links.html", text: buildLinks |
| 112 | archiveArtifacts 'build_links.html' |
| 113 | } |
| 114 | } |
| 115 | |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 116 | def lineInString(string, match) { |
| 117 | def lines = string.split("\n") |
| 118 | def result = lines.findAll { it.contains(match) } |
| 119 | return result[0] |
| 120 | } |
| 121 | |
| 122 | def getResult(string, match) { |
| 123 | line = lineInString(string, match) |
Dean Birch | 1d545c0 | 2020-05-29 14:09:21 +0100 | [diff] [blame] | 124 | a = line.split(match)[1].split(' ') |
| 125 | score = a[0] |
| 126 | if (a.size() > 1) |
| 127 | { |
| 128 | fail_text = a[1..-1].join(" ") |
| 129 | return [score, fail_text] |
| 130 | } |
| 131 | return [score, ""] |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | def submitJobsToList(results) { |
| 135 | def all_jobs = [] |
| 136 | for (String result : results){ |
| 137 | jobs_s = result.split('JOBS: ') |
| 138 | if (jobs_s.size() > 1) { |
| 139 | all_jobs += jobs_s[1] |
| 140 | } |
| 141 | } |
| 142 | return(all_jobs) |
| 143 | } |
| 144 | |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 145 | def configs = [] |
| 146 | def builds = [:] |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 147 | def results = [:] |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 148 | |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 149 | node("docker-amd64-xenial") { |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 150 | stage("Init") { |
| 151 | cleanWs() |
| 152 | dir("tf-m-ci-scripts") { |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 153 | git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY' |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | stage("Configs") { |
| 157 | // Populate configs |
| 158 | listConfigs('tf-m-ci-scripts', configs, env.FILTER_GROUP) |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 159 | results['builds'] = [:] |
| 160 | results['lava_jobs'] = [] |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 161 | for (config in configs) { |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 162 | builds[config] = buildConfig("tf-m-ci-scripts", config, env.FILTER_GROUP, results) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 163 | } |
Matthew Hart | 06340d7 | 2020-06-15 16:08:20 +0100 | [diff] [blame^] | 164 | builds["docs"] = buildDocs(results) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | stage("Builds") { |
| 168 | def verify = 1 |
| 169 | try { |
| 170 | parallel(builds) |
| 171 | } catch (Exception e) { |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 172 | print(e) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 173 | manager.buildFailure() |
| 174 | verify = -1 |
| 175 | } finally { |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 176 | print("Verifying status") |
Dean Birch | d0f9f8c | 2020-03-26 11:10:33 +0000 | [diff] [blame] | 177 | g = new Gerrit() |
| 178 | g.verifyStatus(verify, 'tf-m-build', 'build') |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 179 | print("Building CSV") |
| 180 | buildCsv(results['builds']) |
| 181 | writeSummary(results['builds']) |
Dean Birch | 62c4f08 | 2020-01-17 16:13:26 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
Matthew Hart | 06340d7 | 2020-06-15 16:08:20 +0100 | [diff] [blame^] | 184 | |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 185 | node("docker-amd64-xenial") { |
Matthew Hart | 06340d7 | 2020-06-15 16:08:20 +0100 | [diff] [blame^] | 186 | stage("Copy Docs") { |
| 187 | step([$class: 'CopyArtifact', projectName: 'tf-m-build-docs', |
| 188 | selector: specific("${results['docs'][0]}"), target: './docs/', |
| 189 | optional: true]) |
| 190 | archiveArtifacts artifacts: 'docs/**', allowEmptyArchive: true |
| 191 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 192 | stage("Tests") { |
| 193 | dir("tf-m-ci-scripts") { |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 194 | git url: '$CI_SCRIPTS_REPO', branch: '$CI_SCRIPTS_BRANCH', credentialsId: 'GIT_SSH_KEY' |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 195 | } |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 196 | def all_jobs = [] |
| 197 | def success = true |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 198 | print("Wait for LAVA results here...") |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 199 | try { |
| 200 | all_jobs = submitJobsToList(results['lava_jobs']) |
| 201 | if (all_jobs.size() > 0) { |
| 202 | dir("tf-m-ci-scripts") { |
| 203 | withCredentials([usernamePassword(credentialsId: 'LAVA_CREDENTIALS', passwordVariable: 'LAVA_TOKEN', usernameVariable: 'LAVA_USER')]) { |
| 204 | output = sh(script: """./lava_helper/lava_wait_jobs.py --job-ids ${all_jobs.join(",")} \ |
| 205 | --lava-url ${env.LAVA_URL} --lava-user ${LAVA_USER} --lava-token ${LAVA_TOKEN} \ |
Matthew Hart | 05a59b5 | 2020-05-27 17:54:51 +0100 | [diff] [blame] | 206 | --artifacts-path lava_artifacts --lava-timeout 7200 \ |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 207 | """, returnStdout: true).trim() |
| 208 | archiveArtifacts artifacts: 'test_summary.*', allowEmptyArchive: true |
| 209 | print(output) |
| 210 | g = new Gerrit() |
Dean Birch | 1d545c0 | 2020-05-29 14:09:21 +0100 | [diff] [blame] | 211 | def (boot_result, boot_output) = getResult(output, 'BOOT_RESULT: ') |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 212 | if (boot_result) { |
| 213 | g.verifyStatus(boot_result, "lava_boot", "test") |
| 214 | } |
Dean Birch | 1d545c0 | 2020-05-29 14:09:21 +0100 | [diff] [blame] | 215 | def (test_result, test_output) = getResult(output, 'TEST_RESULT: ') |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 216 | if (test_result) { |
| 217 | g.verifyStatus(test_result, "lava_test", "test") |
| 218 | } |
| 219 | if (boot_result.toInteger() < 1 || test_result.toInteger() < 1) { |
Dean Birch | 1d545c0 | 2020-05-29 14:09:21 +0100 | [diff] [blame] | 220 | error("Marking job as failed due to failed boots: ${boot_output} or tests: ${test_output}") |
Matthew Hart | fb6fd36 | 2020-03-04 21:03:59 +0000 | [diff] [blame] | 221 | } |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | else { |
| 226 | print("There were no LAVA jobs to test.") |
| 227 | } |
| 228 | } |
| 229 | catch (Exception e) { |
| 230 | print("ERROR: ${e}") |
| 231 | success = false |
| 232 | } finally { |
| 233 | archiveArtifacts artifacts: 'tf-m-ci-scripts/lava_artifacts/**', allowEmptyArchive: true |
| 234 | cleanWs() |
| 235 | if (!success) { |
| 236 | error("There was an Error waiting for LAVA jobs") |
| 237 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 238 | } |
| 239 | } |
Dean Birch | a6ede7e | 2020-03-13 14:00:33 +0000 | [diff] [blame] | 240 | } |