Skip to content

Commit

Permalink
Updated packages and build.sh (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
gfoidl authored Nov 4, 2022
1 parent 792eebc commit 666e1c1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 86 deletions.
86 changes: 14 additions & 72 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# build builds the solution
# test runs all tests under ./tests
# test-coverage test + determines code coverage with coverlet.msbuild
# coverage determines code coverage with coverlet and uploads to codecov
# pack creates the NuGet-package
# deploy deploys to $2, which must be either nuget or custom
# * when CI_SKIP_DEPLOY is set, no deploy is done
Expand All @@ -22,19 +21,16 @@
# TEST_DIR directory in which to search for test-assemblies
# TEST_FRAMEWORK when set only the specified test-framework (dotnet test -f) will be used
# TESTS_TO_SKIP a list of test-projects to skip / ignore, separated by ;
# CODECOV_TOKEN the token for codecov to uploads the opencover-xml
# MOVE_TRX moves the test-results (trx) to tests/TestResults
#
# Functions (sorted alphabetically):
# build builds the solution
# coverage code coverage
# deploy deploys the solution either to nuget or custom
# main entry-point
# pack creates the NuGet-package
# setBuildEnv sets the environment variables regarding the build-environment
# test runs tests for projects in ./tests
# test-coverage runs tests for projects in ./tests and collects code-coverage
# _coverageCore helper -- used by coverage
# _deployCore helper -- used by deploy
# _testCore helper -- used by test
#
Expand All @@ -51,7 +47,6 @@ help() {
echo " build builds the solution"
echo " test runs all tests under ./tests"
echo " test-coverage test + determines code coverage with coverlet.msbuild"
echo " coverage determines code coverage with coverlet and uploads to codecov"
echo " pack creates the NuGet-package"
echo " deploy [nuget|custom] deploys to the destination"
}
Expand Down Expand Up @@ -129,20 +124,20 @@ _testCore() {
dotnetTestArgs+=("-f ${TEST_FRAMEWORK}")
fi

# Must be before adding args for code coverage.
dotnetTestArgs+=("${testFullName}")

# It's a bit strange, but doesn't work otherwise due to : "Unable to find a datacollector with friendly name 'XPlat'."
if [[ -n "$collectCoverage" ]]; then
echo "running tests and collecting code coverage"
echo "invoke test with args: ${dotnetTestArgs[@]} --collect:\"XPlat Code Coverage\""
echo ""

# Strange but git-bash (Windows) needs double-escapes, so //p:CollectCoverage=true
# whereas non-Windows just needs /p:CollectCoverage=true
# To avoid platform detection like [[ $(uname | grep mingw -i | wc -l) -ge 0 ]]
# use -p instead to be on the safe side.
dotnetTestArgs+=("-p:CollectCoverage=true" "-p:CoverletOutputFormat=cobertura")
dotnet test ${dotnetTestArgs[@]} --collect:"XPlat Code Coverage"
else
echo "invoke test with args: ${dotnetTestArgs[@]}"
echo ""
dotnet test ${dotnetTestArgs[@]}
fi

dotnetTestArgs+=("${testFullName}")
dotnet test ${dotnetTestArgs[@]}

local result=$?

if [[ -n "$MOVE_TRX" ]]; then
Expand Down Expand Up @@ -193,63 +188,10 @@ test_coverage() {

echo ""

reportgenerator -reports:tests/**/*.cobertura.xml -targetdir:tests/Coverage -reporttypes:"Cobertura;HtmlInline_AzurePipelines"
}
#------------------------------------------------------------------------------
_coverageCore() {
local testFullName
local testDir
local targetFramework

testFullName="$1"
testDir=$(dirname "$testFullName")

cd "$testDir"

for test in ./bin/$BUILD_CONFIG/**/*.Tests*.dll; do
targetFramework=$(basename $(dirname $test))
mkdir -p "coverage/$targetFramework"
coverlet "$test" --target "dotnet" --targetargs "test --no-build -c $BUILD_CONFIG" --format opencover -o "./coverage/$targetFramework/coverage.opencover.xml"
done

cd "$workingDir"
}
#------------------------------------------------------------------------------
coverage() {
local testDir
testDir="./tests"

if [[ ! -d "$testDir" ]]; then
echo "test-directory not existing -> no coverage need to run"
return
fi

echo "check if coverlet.console is installed..."
if [[ $(dotnet tool list -g | grep coverlet.console | wc -l) -eq 0 ]]; then
echo "not installed -> will install it"
export PATH="$PATH:$HOME/.dotnet/tools"
dotnet tool install -g coverlet.console
else
echo "already installed"
fi

for testProject in "$testDir"/**/*.csproj; do
_coverageCore "$testProject"
done

# when $CODECOV_TOKEN is set via env-variable, so it may be omitted as argument
if [[ -n "$CODECOV_TOKEN" ]]; then
if [[ ! -f codecov.sh ]]; then
echo "codecov.sh does not exists -- fetching..."
curl -s https://codecov.io/bash > codecov.sh
chmod u+x codecov.sh
fi

# a cool script, does quite a lot without any args :-)
./codecov.sh -Z
else
echo "CODECOV_TOKEN not set -- skipping upload"
fi
reportgenerator \
-reports:tests/**/coverage.cobertura.xml \
-targetdir:tests/Coverage \
-reporttypes:"Cobertura;HtmlInline_AzurePipelines"
}
#------------------------------------------------------------------------------
pack() {
Expand Down
2 changes: 1 addition & 1 deletion samples/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions samples/MsTestSample/MsTestSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions samples/NUnitSample/NUnitSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0">
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions samples/XUnitSample/XUnitSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

Expand Down
7 changes: 7 additions & 0 deletions source/trx2junit.Core/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ public class Worker
private readonly IFileSystem _fileSystem;
private readonly IGlobHandler _globHandler;

/// <summary>
/// Event that is fired when the worker triggers a notification.
/// </summary>
public event EventHandler<WorkerNotificationEventArgs>? WorkerNotification;

/// <summary>
/// Event that is fired when the worker triggers an error.
/// </summary>
public event EventHandler<WorkerNotificationEventArgs>? WorkerErrorNotification;
//-------------------------------------------------------------------------
/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NUnit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="4.1.0">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.3.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion tests/trx2junit.Core.Tests/trx2junit.Core.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>$(TestTfm)</TargetFrameworks>
Expand Down

0 comments on commit 666e1c1

Please sign in to comment.