mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-04-20 01:22:50 +08:00
code coverage working on windows and linux
This commit is contained in:
parent
9cb00ef159
commit
2dcaf27857
64
build.cake
64
build.cake
@ -19,7 +19,7 @@ var artifactsDir = Directory("artifacts");
|
||||
var artifactsForUnitTestsDir = artifactsDir + Directory("UnitTests");
|
||||
var unitTestAssemblies = @"./test/Ocelot.UnitTests/Ocelot.UnitTests.csproj";
|
||||
var minCodeCoverage = 80d;
|
||||
var coverallsRepoToken = "coveralls-repo-token-ocelot";
|
||||
var coverallsRepoToken = "OCELOT_COVERALLS_TOKEN";
|
||||
var coverallsRepo = "https://coveralls.io/github/TomPallister/Ocelot";
|
||||
|
||||
// acceptance testing
|
||||
@ -124,47 +124,49 @@ Task("RunUnitTests")
|
||||
Configuration = compileConfig,
|
||||
ResultsDirectory = artifactsForUnitTestsDir,
|
||||
ArgumentCustomization = args => args
|
||||
// this create the code coverage report
|
||||
.Append("--settings test/Ocelot.UnitTests/UnitTests.runsettings")
|
||||
};
|
||||
|
||||
EnsureDirectoryExists(artifactsForUnitTestsDir);
|
||||
DotNetCoreTest(unitTestAssemblies, testSettings);
|
||||
|
||||
if (IsRunningOnWindows())
|
||||
|
||||
var coverageSummaryFile = GetSubDirectories(artifactsForUnitTestsDir).First().CombineWithFilePath(File("coverage.opencover.xml"));
|
||||
Information(coverageSummaryFile);
|
||||
Information(artifactsForUnitTestsDir);
|
||||
// todo bring back report generator to get a friendly report
|
||||
// ReportGenerator(coverageSummaryFile, artifactsForUnitTestsDir);
|
||||
// https://github.com/danielpalme/ReportGenerator
|
||||
|
||||
if (IsRunningOnCircleCI())
|
||||
{
|
||||
var coverageSummaryFile = GetSubDirectories(artifactsForUnitTestsDir).First().CombineWithFilePath(File("coverage.opencover.xml"));
|
||||
ReportGenerator(coverageSummaryFile, artifactsForUnitTestsDir);
|
||||
|
||||
if (IsRunningOnCircleCI())
|
||||
var repoToken = EnvironmentVariable(coverallsRepoToken);
|
||||
if (string.IsNullOrEmpty(repoToken))
|
||||
{
|
||||
var repoToken = EnvironmentVariable(coverallsRepoToken);
|
||||
if (string.IsNullOrEmpty(repoToken))
|
||||
{
|
||||
throw new Exception(string.Format("Coveralls repo token not found. Set environment variable '{0}'", coverallsRepoToken));
|
||||
}
|
||||
|
||||
Information(string.Format("Uploading test coverage to {0}", coverallsRepo));
|
||||
CoverallsNet(coverageSummaryFile, CoverallsNetReportType.OpenCover, new CoverallsNetSettings()
|
||||
{
|
||||
RepoToken = repoToken
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Information("We are not running on the build server so we won't publish the coverage report to coveralls.io");
|
||||
throw new Exception(string.Format("Coveralls repo token not found. Set environment variable '{0}'", coverallsRepoToken));
|
||||
}
|
||||
|
||||
var sequenceCoverage = XmlPeek(coverageSummaryFile, "//CoverageSession/Summary/@sequenceCoverage");
|
||||
var branchCoverage = XmlPeek(coverageSummaryFile, "//CoverageSession/Summary/@branchCoverage");
|
||||
|
||||
Information("Sequence Coverage: " + sequenceCoverage);
|
||||
|
||||
if(double.Parse(sequenceCoverage) < minCodeCoverage)
|
||||
Information(string.Format("Uploading test coverage to {0}", coverallsRepo));
|
||||
CoverallsNet(coverageSummaryFile, CoverallsNetReportType.OpenCover, new CoverallsNetSettings()
|
||||
{
|
||||
var whereToCheck = !IsRunningOnCircleCI() ? coverallsRepo : artifactsForUnitTestsDir;
|
||||
throw new Exception(string.Format("Code coverage fell below the threshold of {0}%. You can find the code coverage report at {1}", minCodeCoverage, whereToCheck));
|
||||
};
|
||||
RepoToken = repoToken
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
Information("We are not running on the build server so we won't publish the coverage report to coveralls.io");
|
||||
}
|
||||
|
||||
var sequenceCoverage = XmlPeek(coverageSummaryFile, "//CoverageSession/Summary/@sequenceCoverage");
|
||||
var branchCoverage = XmlPeek(coverageSummaryFile, "//CoverageSession/Summary/@branchCoverage");
|
||||
|
||||
Information("Sequence Coverage: " + sequenceCoverage);
|
||||
|
||||
if(double.Parse(sequenceCoverage) < minCodeCoverage)
|
||||
{
|
||||
var whereToCheck = !IsRunningOnCircleCI() ? coverallsRepo : artifactsForUnitTestsDir;
|
||||
throw new Exception(string.Format("Code coverage fell below the threshold of {0}%. You can find the code coverage report at {1}", minCodeCoverage, whereToCheck));
|
||||
};
|
||||
});
|
||||
|
||||
Task("RunAcceptanceTests")
|
||||
|
@ -1,8 +1,11 @@
|
||||
# call from ocelot repo root with
|
||||
# docker build -f ./docker/Dockerfile.build .
|
||||
|
||||
# docker build --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
|
||||
FROM mijitt0m/ocelot-build:0.0.1
|
||||
|
||||
ARG OCELOT_COVERALLS_TOKEN
|
||||
|
||||
ENV OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN
|
||||
|
||||
WORKDIR /src
|
||||
|
||||
COPY ./. .
|
||||
|
@ -1,11 +1,13 @@
|
||||
# call from ocelot repo root with
|
||||
# docker build --build-arg OCELOT_NUTGET_API_KEY=$OCELOT_NUTGET_API_KEY --build-arg OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY -f ./docker/Dockerfile.release .
|
||||
# docker build --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN --build-arg OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.release .
|
||||
|
||||
FROM mijitt0m/ocelot-build:0.0.1
|
||||
|
||||
ARG OCELOT_GITHUB_API_KEY
|
||||
ARG OCELOT_COVERALLS_TOKEN
|
||||
ARG OCELOT_NUTGET_API_KEY
|
||||
ARG OCELOT_GITHUB_API_KEY
|
||||
|
||||
ENV OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN
|
||||
ENV OCELOT_NUTGET_API_KEY=$OCELOT_NUTGET_API_KEY
|
||||
ENV OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user