|
| 1 | +/* |
| 2 | +# Copyright (c) 2021, NVIDIA CORPORATION. All rights reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +podTemplate (cloud:'sw-gpu-cloudnative', |
| 18 | + containers: [ |
| 19 | + containerTemplate(name: 'docker', image: 'docker:dind', ttyEnabled: true, privileged: true), |
| 20 | + containerTemplate(name: 'golang', image: 'golang:1.14.2', ttyEnabled: true) |
| 21 | + ]) { |
| 22 | + node(POD_LABEL) { |
| 23 | + stage('checkout') { |
| 24 | + checkout scm |
| 25 | + } |
| 26 | + stage('dependencies') { |
| 27 | + container('golang') { |
| 28 | + sh 'GO111MODULE=off go get -u github.com/client9/misspell/cmd/misspell' |
| 29 | + sh 'GO111MODULE=off go get -u github.com/gordonklaus/ineffassign' |
| 30 | + sh 'GO111MODULE=off go get -u golang.org/x/lint/golint' |
| 31 | + } |
| 32 | + container('docker') { |
| 33 | + sh 'apk add --no-cache make bash' |
| 34 | + } |
| 35 | + } |
| 36 | + stage('check') { |
| 37 | + parallel ( |
| 38 | + getGolangStages(["assert-fmt", "lint", "vet", "ineffassign", "misspell"]) |
| 39 | + ) |
| 40 | + } |
| 41 | + stage('test') { |
| 42 | + parallel ( |
| 43 | + getGolangStages(["test"]) |
| 44 | + ) |
| 45 | + } |
| 46 | + stage('build-one') { |
| 47 | + parallel ( |
| 48 | + getSingleBuildForArchitectures(["amd64", "ppc64le", "arm64"]) |
| 49 | + ) |
| 50 | + } |
| 51 | + stage('build-all') { |
| 52 | + parallel ( |
| 53 | + getAllBuildForArchitectures(["amd64", "ppc64le", "arm64", "x86_64", "aarch64"]) |
| 54 | + ) |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +def getGolangStages(def targets) { |
| 60 | + stages = [:] |
| 61 | + |
| 62 | + for (t in targets) { |
| 63 | + stages[t] = getLintClosure(t) |
| 64 | + } |
| 65 | + |
| 66 | + return stages |
| 67 | +} |
| 68 | + |
| 69 | +def getSingleBuildForArchitectures(def architectures) { |
| 70 | + return getBuildStagesForArchitectures(architectures, "make", "ubuntu18.04") |
| 71 | +} |
| 72 | + |
| 73 | +def getAllBuildForArchitectures(def architectures) { |
| 74 | + // TODO: For the time being we only echo the command for the "all" stages |
| 75 | + return getBuildStagesForArchitectures(architectures, "echo make", "docker") |
| 76 | +} |
| 77 | + |
| 78 | +def getBuildStagesForArchitectures(def architectures, def makeCommand, def makeTargetPrefix) { |
| 79 | + stages = [:] |
| 80 | + |
| 81 | + for (a in architectures) { |
| 82 | + stages[a] = getBuildClosure(a, makeCommand, "${makeTargetPrefix}-${a}") |
| 83 | + } |
| 84 | + |
| 85 | + return stages |
| 86 | +} |
| 87 | + |
| 88 | +def getBuildClosure(def architecture, def makeCommand, def makeTarget) { |
| 89 | + return { |
| 90 | + container('docker') { |
| 91 | + stage(architecture) { |
| 92 | + sh "${makeCommand} ${makeTarget}" |
| 93 | + } |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +def getLintClosure(def target) { |
| 99 | + return { |
| 100 | + container('golang') { |
| 101 | + stage(target) { |
| 102 | + sh "make ${target}" |
| 103 | + } |
| 104 | + } |
| 105 | + } |
| 106 | +} |
0 commit comments