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