|
1 | 1 | #!/bin/bash |
| 2 | +set -e |
2 | 3 |
|
3 | | -# build.sh - Helper script to build, package, and test the Coverlet project. |
| 4 | +# build.sh - Helper script to build and package the Coverlet project. |
4 | 5 | # |
5 | 6 | # This script performs the following tasks: |
6 | | -# 1. Builds the project in debug configuration and generates a binary log. |
7 | | -# 2. Packages the project in both debug and release configurations. |
8 | | -# 3. Shuts down any running .NET build servers. |
9 | | -# 4. Runs unit tests for various Coverlet components with code coverage enabled, |
10 | | -# generating binary logs and diagnostic outputs. |
11 | | -# 5. Outputs test results in xUnit TRX format and stores them in the specified directories. |
| 7 | +# 1. Cleans up temporary files and build artifacts |
| 8 | +# 2. Builds individual project targets (required for Linux compatibility) |
| 9 | +# 3. Packages the project in both debug and release configurations |
12 | 10 | # |
13 | 11 | # Usage: |
14 | 12 | # ./build.sh |
15 | 13 | # |
16 | 14 | # Note: Ensure that the .NET SDK is installed and available in the system PATH. |
| 15 | +# For running tests, use the separate test.sh script. |
17 | 16 |
|
18 | | -# Build the project |
19 | | -dotnet build -c debug -bl:build.binlog |
20 | | -dotnet pack -c debug |
21 | | -dotnet pack -c release |
22 | | -dotnet build-server shutdown |
| 17 | +# Get the workspace root directory |
| 18 | +WORKSPACE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" |
| 19 | +cd "$WORKSPACE_ROOT" |
23 | 20 |
|
24 | | -# Run tests with code coverage |
25 | | -dotnet test test/coverlet.collector.tests /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*" --results-directory:"./artifacts/reports" --diag:"artifacts/log/debug/coverlet.collector.test.log;tracelevel=verbose" |
26 | | -dotnet build-server shutdown |
27 | | -dotnet test test/coverlet.core.tests /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*" --results-directory:"./artifacts/reports" --verbosity detailed --diag ./artifacts/log/debug/coverlet.core.tests.log |
28 | | -dotnet build-server shutdown |
29 | | -dotnet test test/coverlet.core.coverage.tests /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*" -- --results-directory "$(pwd)/artifacts/reports" --report-xunit-trx --report-xunit-trx-filename "coverlet.core.coverage.tests.trx" --diagnostic-verbosity debug --diagnostic --diagnostic-output-directory "$(pwd)/artifacts/log/debug" |
| 21 | +echo "Please cleanup '/tmp' folder if needed!" |
| 22 | + |
| 23 | +# Shutdown build server and kill any running test processes |
30 | 24 | dotnet build-server shutdown |
31 | | -dotnet test test/coverlet.msbuild.tasks.tests /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[coverlet.core.tests.samples.netstandard]*" --results-directory:"./artifacts/reports" --verbosity detailed --diag ./artifacts/log/debug/coverlet.msbuild.tasks.tests.log |
| 25 | +pkill -f "coverlet.core.tests.exe" 2>/dev/null || true |
| 26 | + |
| 27 | +# Delete coverage files |
| 28 | +find . -name "coverage.cobertura.xml" -delete 2>/dev/null || true |
| 29 | +find . -name "coverage.json" -delete 2>/dev/null || true |
| 30 | +find . -name "coverage.net8.0.json" -delete 2>/dev/null || true |
| 31 | +find . -name "coverage.opencover.xml" -delete 2>/dev/null || true |
| 32 | +find . -name "coverage.net8.0.opencover.xml" -delete 2>/dev/null || true |
| 33 | + |
| 34 | +# Delete binlog files in integration tests |
| 35 | +rm -f test/coverlet.integration.determisticbuild/*.binlog 2>/dev/null || true |
| 36 | + |
| 37 | +# Remove artifacts directory |
| 38 | +rm -rf artifacts |
| 39 | + |
| 40 | +# Clean up local NuGet packages |
| 41 | +rm -rf "$HOME/.nuget/packages/coverlet.msbuild/V1.0.0" 2>/dev/null || true |
| 42 | +rm -rf "$HOME/.nuget/packages/coverlet.collector/V1.0.0" 2>/dev/null || true |
| 43 | + |
| 44 | +# Remove TestResults, bin, and obj directories |
| 45 | +find . -type d \( -name "TestResults" -o -name "bin" -o -name "obj" \) -exec rm -rf {} + 2>/dev/null || true |
| 46 | + |
| 47 | +# Remove preview packages from NuGet cache |
| 48 | +find "$HOME/.nuget/packages" -type d \( -path "*/coverlet.msbuild/8.0.0-preview*" -o -path "*/coverlet.collector/8.0.0-preview*" -o -path "*/coverlet.console/8.0.0-preview*" \) -exec rm -rf {} + 2>/dev/null || true |
| 49 | + |
| 50 | +echo "Cleanup complete. Starting build..." |
| 51 | + |
| 52 | +# Pack initial packages (Debug) |
| 53 | +dotnet pack -c Debug src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj /p:ContinuousIntegrationBuild=true |
| 54 | +dotnet pack -c Debug src/coverlet.collector/coverlet.collector.csproj /p:ContinuousIntegrationBuild=true |
| 55 | + |
| 56 | +# Build individual projects with binlog |
| 57 | +dotnet build src/coverlet.core/coverlet.core.csproj -bl:build.core.binlog /p:ContinuousIntegrationBuild=true |
| 58 | +dotnet build src/coverlet.collector/coverlet.collector.csproj -bl:build.collector.binlog /p:ContinuousIntegrationBuild=true |
| 59 | +dotnet build src/coverlet.console/coverlet.console.csproj -bl:build.console.binlog /p:ContinuousIntegrationBuild=true |
| 60 | +dotnet build src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj -bl:build.msbuild.tasks.binlog /p:ContinuousIntegrationBuild=true |
| 61 | + |
| 62 | +# Build test projects with binlog |
| 63 | +dotnet build test/coverlet.collector.tests/coverlet.collector.tests.csproj -bl:build.collector.tests.binlog /p:ContinuousIntegrationBuild=true |
| 64 | +dotnet build test/coverlet.core.coverage.tests/coverlet.core.coverage.tests.csproj -bl:build.core.coverage.tests.binlog /p:ContinuousIntegrationBuild=true |
| 65 | +dotnet build test/coverlet.core.tests/coverlet.core.tests.csproj -bl:build.coverlet.core.tests.binlog /p:ContinuousIntegrationBuild=true |
| 66 | +dotnet build test/coverlet.msbuild.tasks.tests/coverlet.msbuild.tasks.tests.csproj -bl:build.coverlet.msbuild.tasks.tests.binlog /p:ContinuousIntegrationBuild=true |
| 67 | +dotnet build test/coverlet.integration.tests/coverlet.integration.tests.csproj -f net8.0 -bl:build.coverlet.core.tests.8.0.binlog /p:ContinuousIntegrationBuild=true |
| 68 | + |
| 69 | +# Get the SDK version from global.json |
| 70 | +SDK_VERSION=$(grep -oP '"version"\s*:\s*"\K[^"]+' global.json) |
| 71 | +SDK_MAJOR_VERSION=$(echo "$SDK_VERSION" | cut -d'.' -f1) |
| 72 | + |
| 73 | +# Check if the SDK version is 9.0.* or higher (9.0.*, 10.0.*, etc.) |
| 74 | +if [[ "$SDK_MAJOR_VERSION" -ge 9 ]]; then |
| 75 | + echo "Executing command for SDK version $SDK_VERSION (9.0+ detected)..." |
| 76 | + dotnet build test/coverlet.integration.tests/coverlet.integration.tests.csproj -f net9.0 -bl:build.coverlet.core.tests.9.9.binlog /p:ContinuousIntegrationBuild=true |
| 77 | +fi |
| 78 | + |
| 79 | +# Create NuGet packages (Debug) |
| 80 | +dotnet pack -c Debug src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj /p:ContinuousIntegrationBuild=true |
| 81 | +dotnet pack -c Debug src/coverlet.collector/coverlet.collector.csproj /p:ContinuousIntegrationBuild=true |
| 82 | +dotnet pack -c Debug src/coverlet.console/coverlet.console.csproj /p:ContinuousIntegrationBuild=true |
| 83 | +dotnet pack -c Debug src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj /p:ContinuousIntegrationBuild=true |
| 84 | + |
| 85 | +# Create NuGet packages (Release) |
| 86 | +dotnet pack src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj /p:ContinuousIntegrationBuild=true |
| 87 | +dotnet pack src/coverlet.collector/coverlet.collector.csproj /p:ContinuousIntegrationBuild=true |
| 88 | +dotnet pack src/coverlet.console/coverlet.console.csproj /p:ContinuousIntegrationBuild=true |
| 89 | +dotnet pack src/coverlet.msbuild.tasks/coverlet.msbuild.tasks.csproj /p:ContinuousIntegrationBuild=true |
| 90 | + |
32 | 91 | dotnet build-server shutdown |
33 | | -dotnet test test/coverlet.integration.tests -f net8.0 --results-directory:"./artifacts/reports" --verbosity detailed --diag ./artifacts/log/debug/coverlet.integration.tests.net8.log |
34 | | -dotnet test test/coverlet.integration.tests -f net9.0 --results-directory:"./artifacts/reports" --verbosity detailed --diag ./artifacts/log/debug/coverlet.integration.tests.net9.log |
| 92 | + |
| 93 | +echo "Build complete!" |
0 commit comments