|
| 1 | +pr: |
| 2 | + - master |
| 3 | + |
| 4 | +trigger: |
| 5 | + branches: |
| 6 | + include: |
| 7 | + - master |
| 8 | + |
| 9 | +jobs: |
| 10 | + - job: UnitTest |
| 11 | + pool: |
| 12 | + name: Networking-ContainerNetworking |
| 13 | + demands: agent.os -equals Linux |
| 14 | + |
| 15 | + container: |
| 16 | + image: containernetworking/pipeline-ci:1.0.3 |
| 17 | + options: "--privileged" |
| 18 | + |
| 19 | + # Go setup for the vmImage: |
| 20 | + # https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/linux/scripts/installers/go.sh |
| 21 | + variables: |
| 22 | + GOBIN: "$(GOPATH)/bin" # Go binaries path |
| 23 | + GOPATH: "$(System.DefaultWorkingDirectory)/gopath" # Go workspace path |
| 24 | + modulePath: "$(GOPATH)/src/github.com/Azure/azure-container-networking" # $(build.repository.name)' # Path to the module's code |
| 25 | + |
| 26 | + steps: |
| 27 | + - bash: | |
| 28 | + echo $UID |
| 29 | + sudo apt-get install -y ebtables ipset python3-dev gcc zip iptables ipset |
| 30 | + sudo pip install coverage |
| 31 | + displayName: "Install OS dependencies" |
| 32 | +
|
| 33 | + - bash: | |
| 34 | + go version |
| 35 | + go env |
| 36 | + mkdir -p '$(GOBIN)' |
| 37 | + mkdir -p '$(GOPATH)/pkg' |
| 38 | + mkdir -p '$(modulePath)' |
| 39 | + shopt -s extglob |
| 40 | + shopt -s dotglob |
| 41 | + mv !(gopath) '$(modulePath)' |
| 42 | + echo '##vso[task.prependpath]$(GOBIN)' |
| 43 | + echo '##vso[task.prependpath]$(GOROOT)/bin' |
| 44 | + displayName: "Set up the Go workspace" |
| 45 | +
|
| 46 | + - bash: | |
| 47 | + go get -v -t -d ./... |
| 48 | + if [ -f Gopkg.toml ]; then |
| 49 | + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh |
| 50 | + fi |
| 51 | + go get github.com/docker/libnetwork/driverapi |
| 52 | + go get github.com/gorilla/mux |
| 53 | + go get github.com/jstemmer/go-junit-report |
| 54 | + go get github.com/axw/gocov/gocov |
| 55 | + go get github.com/AlekSi/gocov-xml |
| 56 | + go get -u gopkg.in/matm/v1/gocov-html |
| 57 | + workingDirectory: "$(modulePath)" |
| 58 | + displayName: "Install Go dependencies" |
| 59 | +
|
| 60 | + - bash: | |
| 61 | + sudo rm /run/docker/plugins/test.sock || true |
| 62 | + sudo ip link del dev dummy || true |
| 63 | + workingDirectory: "$(modulePath)" |
| 64 | + displayName: "Workspace setup" |
| 65 | + condition: always() |
| 66 | +
|
| 67 | + - bash: | |
| 68 | + export GOOS=linux |
| 69 | + make all-binaries |
| 70 | + export GOOS=windows |
| 71 | + make all-binaries |
| 72 | + cd output |
| 73 | + sudo find . -mindepth 2 -type f -regextype posix-extended ! -iregex '.*\.(zip|tgz)$' -delete |
| 74 | + sudo find . -mindepth 2 -type f -print -exec mv {} . \; |
| 75 | + sudo rm -R -- */ |
| 76 | + workingDirectory: "$(modulePath)" |
| 77 | + displayName: "Build" |
| 78 | +
|
| 79 | + - bash: | |
| 80 | + # run test, echo exit status code to fd 3, pipe output from test to tee, which splits output to stdout and go-junit-report (which converts test output to report.xml), stdout from tee is redirected to fd 4. Take output written to fd 3 (which is the exit code of test), redirect to stdout, pipe to read from stdout then exit with that status code. Read all output from fd 4 (output from tee) and write to top stdout |
| 81 | + { { { { |
| 82 | + sudo -E env "PATH=$PATH" make test-all; |
| 83 | + echo $? >&3; |
| 84 | + } | tee >(go-junit-report > report.xml) >&4; |
| 85 | + } 3>&1; |
| 86 | + } | { read xs; exit $xs; } |
| 87 | + } 4>&1 |
| 88 | + workingDirectory: "$(modulePath)" |
| 89 | + failOnStderr: true |
| 90 | + displayName: "Run Tests" |
| 91 | +
|
| 92 | + - bash: | |
| 93 | + bash <(curl -s https://codecov.io/bash) |
| 94 | + gocov convert coverage.out > coverage.json |
| 95 | + gocov-xml < coverage.json > coverage.xml |
| 96 | + workingDirectory: "$(modulePath)" |
| 97 | + displayName: "Generate Coverage Reports" |
| 98 | + condition: always() |
| 99 | +
|
| 100 | + - task: PublishTestResults@2 |
| 101 | + inputs: |
| 102 | + testRunner: JUnit |
| 103 | + testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml |
| 104 | + condition: always() |
| 105 | + |
| 106 | + - task: PublishCodeCoverageResults@1 |
| 107 | + inputs: |
| 108 | + codeCoverageTool: Cobertura |
| 109 | + summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml |
| 110 | + condition: always() |
| 111 | + |
| 112 | + - task: CopyFiles@2 |
| 113 | + inputs: |
| 114 | + sourceFolder: "$(modulePath)/output" |
| 115 | + targetFolder: $(Build.ArtifactStagingDirectory) |
| 116 | + condition: succeeded() |
| 117 | + |
| 118 | + - task: PublishBuildArtifacts@1 |
| 119 | + inputs: |
| 120 | + artifactName: "output" |
| 121 | + pathtoPublish: "$(Build.ArtifactStagingDirectory)" |
| 122 | + condition: succeeded() |
0 commit comments