Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage, Linux & macOS leg to Azure CI #264

Merged
merged 1 commit into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 53 additions & 27 deletions .azure-pipelines.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
jobs:

- job: build_xamarin
- job: xamarin_build
pool:
vmImage: 'VS2017-Win2016'
steps:
Expand All @@ -21,11 +21,10 @@ jobs:
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)/nupkg/'

- job: Build
- job: windows_build
pool:
vmImage: 'VS2017-Win2016'


steps:
- task: DotNetCoreCLI@2
displayName: 'dotnet restore'
Expand All @@ -37,22 +36,6 @@ jobs:
inputs:
projects: '**/*.sln'

# - task: MSBuild@1
# displayName: 'Build solution **/*.sln'
# inputs:
# msbuildArchitecture: x64

# configuration: Release

# - task: VSTest@2
# displayName: 'VsTest - testAssemblies'
# inputs:
# testAssemblyVer2: |
# tests\**\*Tests*.dll
# !**\obj\**

# codeCoverageEnabled: true

- task: DotNetCoreCLI@2
displayName: 'dotnet test'
inputs:
Expand All @@ -64,15 +47,13 @@ jobs:
displayName: 'publish coverage results'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.cobertura.xml'
summaryFileLocation: '$(System.DefaultWorkingDirectory)/**/coverage.cobertura.xml'

- task: alanwales.resharper-code-analysis.custom-build-task.ResharperCli@1
displayName: 'Automated code quality checks'
inputs:
SolutionOrProjectPath: 'kubernetes-client.sln'

FailBuildOnCodeIssues: false

continueOnError: true

- task: DotNetCoreCLI@2
Expand All @@ -81,15 +62,60 @@ jobs:
command: pack
packagesToPack: src/KubernetesClient/KubernetesClient.csproj
packDirectory: '$(Build.ArtifactStagingDirectory)/nupkg'
majorVersion: 1
minorVersion: 4
versioningScheme: byPrereleaseNumber
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why versioning was removed?
it is to replace git verison

Copy link
Contributor Author

@qmfrederik qmfrederik Mar 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version numbers are embedded in the assemblies and NuGet packages you create. If you use build numbers which depend on external factors (such as the date and time the package was built or the CI job number), your build output (the binaries) will be different every time you build, even if you build from the same source.

This breaks reproducible builds. Having reproducible builds means I can clone this repository, build locally, get the SHA hash of the NuGet package it builds, and make sure it's the same which is uploaded on NuGet. It helps create trust.

The Kubernetes project is working towards reproducible builds - see kubernetes/kubernetes#70131, and I think it would be good if the same holds true for the .NET client.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, I prefer to each build is an individual.
The build machine cannot be exactly the same.
For example, when your update dotnet 1 to dotnet 2, the output/nuget of compiler might be changed even the source codes are totally the same.

The nuget is a snapshot and the release team is responsible for the official release.

Maybe something like docker image could make the build reproducible.

@brendandburns what is your opinion?



- task: PublishBuildArtifacts@1
displayName: 'Publish Artifact: drop'
inputs:
PathtoPublish: '$(build.artifactstagingdirectory)/nupkg'
PathtoPublish: '$(Build.ArtifactStagingDirectory)/nupkg'

- job: macos_build
pool:
vmImage: 'xcode9-macos10.13'
steps:
- script: |
brew install coreutils
which realpath
./ci.sh
displayName: 'Build & Test'

- task: PublishTestResults@1
displayName: 'Publish Test Results'
inputs:
testRunner: VSTest
testResultsFiles: '$(Build.SourcesDirectory)/tests/**/*.xunit.trx'
condition: succeededOrFailed()

- task: PublishCodeCoverageResults@1
displayName: 'publish coverage results'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/tests/coveragereport/Cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/tests/coveragereport/'
condition: succeededOrFailed()

- job: ubuntu_build
pool:
vmImage: 'ubuntu-16.04'
steps:
- script: |
./install-linux.sh
displayName: 'Install .NET & set up minikube'

- script: |
./ci.sh
displayName: 'Build & Test'

- task: PublishTestResults@1
displayName: 'Publish Test Results'
inputs:
testRunner: VSTest
testResultsFiles: '$(Build.SourcesDirectory)/tests/**/*.xunit.trx'
condition: succeededOrFailed()

- task: PublishCodeCoverageResults@1
displayName: 'publish coverage results'
inputs:
codeCoverageTool: 'cobertura'
summaryFileLocation: '$(Build.SourcesDirectory)/tests/coveragereport/Cobertura.xml'
reportDirectory: '$(Build.SourcesDirectory)/tests/coveragereport/'
condition: succeededOrFailed()
24 changes: 22 additions & 2 deletions ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ cd ../..
# Execute Unit tests
cd tests/KubernetesClient.Tests
dotnet restore
dotnet test
# Save the test results to a file
# Collect code coverage of the KuberetsClient assembly, but exclude the
# auto-generated models from the coverage reports.
dotnet test \
-l "trx;LogFileName=KubernetesClient.Tests.xunit.trx" \
/p:CollectCoverage=true \
/p:Include="[KubernetesClient]*" \
/p:Exclude="[KubernetesClient]k8s.Models.*" \
/p:Exclude="[KubernetesClient]k8s.Internal.*" \
/p:CoverletOutputFormat="opencover" \
/p:CoverletOutput="KubernetesClient.Tests.opencover.xml"

cd ../..
cd ..
echo Generating Code Coverage reports
export PATH="$PATH:$HOME/.dotnet/tools"
export DOTNET_ROOT=$(dirname $(realpath $(which dotnet))) # https://github.com/dotnet/cli/issues/9114#issuecomment-401670622
dotnet tool install --global dotnet-reportgenerator-globaltool --version 4.0.15
reportgenerator "-reports:**/*.opencover.xml" "-targetdir:coveragereport" "-reporttypes:HTMLInline;Cobertura"

ls coveragereport
ls coveragereport/Cobertura.xml

cd ..
3 changes: 3 additions & 0 deletions install-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ echo 'Creating the minikube cluster'
sudo minikube start --vm-driver=none --kubernetes-version=v1.13.4 --extra-config=apiserver.authorization-mode=RBAC
sudo chown -R $USER $HOME/.minikube
sudo chgrp -R $USER $HOME/.minikube
sudo chown -R $USER $HOME/.kube
sudo chgrp -R $USER $HOME/.kube

minikube update-context

echo 'Waiting for the cluster nodes to be ready'
Expand Down