diff --git a/.codecov/codecov.yml b/.codecov/codecov.yml new file mode 100644 index 0000000000..e2a23c23d8 --- /dev/null +++ b/.codecov/codecov.yml @@ -0,0 +1,3 @@ +codecov: + notify: + require_ci_to_pass: no diff --git a/.gitignore b/.gitignore index 331501803f..c9274d2f13 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,6 @@ ipam-*.xml # Environment .vscode/* + +# Coverage +*.out \ No newline at end of file diff --git a/.pipelines/pipeline.yml b/.pipelines/pipeline.yml new file mode 100644 index 0000000000..2820f83d00 --- /dev/null +++ b/.pipelines/pipeline.yml @@ -0,0 +1,102 @@ +pr: +- master + +trigger: + branches: + include: + - master + +jobs: +- job: Test + pool: + vmImage: 'Ubuntu-16.04' + + # Go setup for the vmImage: + # https://github.com/Microsoft/azure-pipelines-image-generation/blob/master/images/linux/scripts/installers/go.sh + variables: + GOBIN: '$(GOPATH)/bin' # Go binaries path + GOPATH: '$(System.DefaultWorkingDirectory)/gopath' # Go workspace path + modulePath: '$(GOPATH)/src/github.com/Azure/azure-container-networking' # $(build.repository.name)' # Path to the module's code + + steps: + - script: | + echo $UID + sudo apt-get update + sudo apt-get install -y ebtables ipset python3-dev gcc zip + sudo pip install coverage + displayName: 'Install OS dependencies' + + - script: | + go version + go env + mkdir -p '$(GOBIN)' + mkdir -p '$(GOPATH)/pkg' + mkdir -p '$(modulePath)' + shopt -s extglob + shopt -s dotglob + mv !(gopath) '$(modulePath)' + echo '##vso[task.prependpath]$(GOBIN)' + echo '##vso[task.prependpath]$(GOROOT)/bin' + displayName: 'Set up the Go workspace' + + - script: | + go get -v -t -d ./... + if [ -f Gopkg.toml ]; then + curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh + dep ensure + fi + go get github.com/docker/libnetwork/driverapi + go get github.com/gorilla/mux + go get github.com/jstemmer/go-junit-report + go get github.com/axw/gocov/gocov + go get github.com/AlekSi/gocov-xml + go get -u gopkg.in/matm/v1/gocov-html + workingDirectory: '$(modulePath)' + displayName: 'Install Go dependencies' + + - script: | + set -o pipefail + set -e + sudo -E env "PATH=$PATH" make test-all 2>&1 | tee >(go-junit-report > report.xml) + bash <(curl -s https://codecov.io/bash) + gocov convert coverage.out > coverage.json + gocov-xml < coverage.json > coverage.xml + workingDirectory: '$(modulePath)' + displayName: 'RunTest' + + - task: PublishTestResults@2 + inputs: + testRunner: JUnit + testResultsFiles: $(System.DefaultWorkingDirectory)/**/report.xml + condition: always() + + - task: PublishCodeCoverageResults@1 + inputs: + codeCoverageTool: Cobertura + summaryFileLocation: $(System.DefaultWorkingDirectory)/**/coverage.xml + condition: always() + + - script: | + export GOOS=linux + sudo -E env "PATH=$PATH" make all-binaries + export GOOS=windows + sudo -E env "PATH=$PATH" make all-binaries + cd output + sudo find . -mindepth 2 -type f -print -exec mv {} . \; + sudo rm -R -- */ + sudo find . -type f -regextype posix-extended ! -iregex '.*\.(zip|tgz)$' -delete + workingDirectory: '$(modulePath)' + displayName: 'Build' + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + + - task: CopyFiles@2 + inputs: + sourceFolder: '$(modulePath)/output' + targetFolder: $(Build.ArtifactStagingDirectory) + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + + - task: PublishBuildArtifacts@1 + inputs: + artifactName: 'output' + pathtoPublish: '$(Build.ArtifactStagingDirectory)' + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) diff --git a/Makefile b/Makefile index 0e1e284670..fb6fb3d616 100644 --- a/Makefile +++ b/Makefile @@ -275,4 +275,20 @@ ifeq ($(GOOS),linux) chmod 0755 $(NPM_BUILD_DIR)/azure-npm$(EXE_EXT) cd $(NPM_BUILD_DIR) && $(ARCHIVE_CMD) $(NPM_ARCHIVE_NAME) azure-npm$(EXE_EXT) chown $(BUILD_USER):$(BUILD_USER) $(NPM_BUILD_DIR)/$(NPM_ARCHIVE_NAME) -endif \ No newline at end of file +endif + +# run all tests +.PHONY: test-all +test-all: + go test -v -covermode count -coverprofile=coverage.out \ + ./ipam/ \ + ./log/ \ + ./netlink/ \ + ./store/ \ + ./telemetry/ \ + ./cnm/network/ \ + ./cni/ipam/ \ + ./cns/ipamclient/ \ + ./npm/iptm/ \ + ./npm/ipsm/ \ + ./npm \ No newline at end of file