|
| 1 | +#!groovy |
| 2 | +// -*- mode: groovy -*- |
| 3 | +// Jenkins pipeline |
| 4 | +// See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/ |
| 5 | + |
| 6 | +// nnvm libraries |
| 7 | +vta_lib += "lib/libvta.so, lib/libvta.so.json" |
| 8 | +vta_lib += ", nnvm/tvm/lib/libtvm.so, nnvm/tvm/lib/libtopi.so, nnvm/lib/libnnvm_compiler.so" |
| 9 | + |
| 10 | + |
| 11 | +// command to start a docker container |
| 12 | +docker_run = 'tests/ci_build/ci_build.sh' |
| 13 | +// timeout in minutes |
| 14 | +max_time = 60 |
| 15 | + |
| 16 | +// initialize source codes |
| 17 | +def init_git() { |
| 18 | + checkout scm |
| 19 | + retry(5) { |
| 20 | + timeout(time: 2, unit: 'MINUTES') { |
| 21 | + sh 'git submodule update --init --recursive' |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +def init_git_win() { |
| 27 | + checkout scm |
| 28 | + retry(5) { |
| 29 | + timeout(time: 2, unit: 'MINUTES') { |
| 30 | + bat 'git submodule update --init --recursive' |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +stage("Sanity Check") { |
| 36 | + timeout(time: max_time, unit: 'MINUTES') { |
| 37 | + node('linux') { |
| 38 | + ws('workspace/vta/sanity') { |
| 39 | + init_git() |
| 40 | + sh "${docker_run} lint ./tests/scripts/task_lint.sh" |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +// Run make. First try to do an incremental make from a previous workspace in hope to |
| 47 | +// accelerate the compilation. If something wrong, clean the workspace and then |
| 48 | +// build from scratch. |
| 49 | +def make(docker_type, make_flag) { |
| 50 | + timeout(time: max_time, unit: 'MINUTES') { |
| 51 | + sh "${docker_run} ${docker_type} cp make/sim_sample.json config.json" |
| 52 | + try { |
| 53 | + sh "${docker_run} ${docker_type} ./tests/scripts/task_build.sh ${make_flag}" |
| 54 | + } catch (exc) { |
| 55 | + echo 'Incremental compilation failed. Fall back to build from scratch' |
| 56 | + sh "${docker_run} ${docker_type} ./tests/scripts/task_clean.sh" |
| 57 | + sh "${docker_run} ${docker_type} ./tests/scripts/task_build.sh ${make_flag}" |
| 58 | + } |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +// pack libraries for later use |
| 63 | +def pack_lib(name, libs) { |
| 64 | + sh """ |
| 65 | + echo "Packing ${libs} into ${name}" |
| 66 | + echo ${libs} | sed -e 's/,/ /g' | xargs md5sum |
| 67 | + """ |
| 68 | + stash includes: libs, name: name |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | +// unpack libraries saved before |
| 73 | +def unpack_lib(name, libs) { |
| 74 | + unstash name |
| 75 | + sh """ |
| 76 | + echo "Unpacked ${libs} from ${name}" |
| 77 | + echo ${libs} | sed -e 's/,/ /g' | xargs md5sum |
| 78 | + """ |
| 79 | +} |
| 80 | + |
| 81 | +stage('Build') { |
| 82 | + timeout(time: max_time, unit: 'MINUTES') { |
| 83 | + node('linux') { |
| 84 | + ws('workspace/vta/build') { |
| 85 | + init_git() |
| 86 | + make('cpu', '-j2') |
| 87 | + pack_lib('cpu', vta_lib) |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +stage('Tests') { |
| 94 | + parallel 'python': { |
| 95 | + node('linux') { |
| 96 | + ws('workspace/vta/it-python') { |
| 97 | + init_git() |
| 98 | + unpack_lib('cpu', vta_lib) |
| 99 | + timeout(time: max_time, unit: 'MINUTES') { |
| 100 | + sh "${docker_run} cpu ./tests/scripts/task_python_test.sh" |
| 101 | + } |
| 102 | + } |
| 103 | + } |
| 104 | + }, |
| 105 | + 'docs': { |
| 106 | + node('linux') { |
| 107 | + ws('workspace/vta/docs-python') { |
| 108 | + init_git() |
| 109 | + unpack_lib('cpu', vta_lib) |
| 110 | + timeout(time: max_time, unit: 'MINUTES') { |
| 111 | + sh "${docker_run} cpu ./tests/scripts/task_python_docs.sh" |
| 112 | + } |
| 113 | + pack_lib('mydocs', 'docs.tgz') |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +stage('Deploy') { |
| 120 | + node('docker' && 'doc') { |
| 121 | + ws('workspace/vta/deploy-docs') { |
| 122 | + if (env.BRANCH_NAME == "master") { |
| 123 | + unpack_lib('mydocs', 'docs.tgz') |
| 124 | + sh "tar xf docs.tgz -C /var/vta-docs" |
| 125 | + } |
| 126 | + } |
| 127 | + } |
| 128 | +} |
0 commit comments