Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
152 changes: 0 additions & 152 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -25,82 +25,14 @@ var artifactsPackagesDirectory = artifactsDirectory.Combine("packages");
var srcDirectory = solutionDirectory.Combine("src");
var testsDirectory = solutionDirectory.Combine("tests");
var outputDirectory = solutionDirectory.Combine("build");
var toolsDirectory = solutionDirectory.Combine("tools");
var toolsHugoDirectory = toolsDirectory.Combine("Hugo");
var mongoDbDriverPackageName = "MongoDB.Driver";

var solutionFile = solutionDirectory.CombineWithFilePath("CSharpDriver.sln");
var solutionFullPath = solutionFile.FullPath;

Task("Default")
.IsDependentOn("Test");

Task("Release")
.IsDependentOn("Build")
.IsDependentOn("Package");

Task("Restore")
.Does(() =>
{
// disable parallel restore to work around apparent bugs in restore
var restoreSettings = new DotNetRestoreSettings
{
DisableParallel = true
};
DotNetRestore(solutionFullPath, restoreSettings);
});

Task("Build")
.IsDependentOn("Restore")
.Does<BuildConfig>((buildConfig) =>
{
var settings = new DotNetBuildSettings
{
NoRestore = true,
Configuration = configuration,
EnvironmentVariables = new Dictionary<string, string>
{
{ "Version", gitVersion.LegacySemVer },
{ "SourceRevisionId", gitVersion.Sha }
}
};

DotNetBuild(solutionFullPath, settings);
});

Task("BuildArtifacts")
.IsDependentOn("Build")
.Does(() =>
{
foreach (var targetFramework in new[] { "net472", "netstandard2.0", "netstandard2.1" })
{
var toDirectory = artifactsBinDirectory.Combine(targetFramework);
CleanDirectory(toDirectory);

var projects = new[] { "MongoDB.Bson", "MongoDB.Driver" };
foreach (var project in projects)
{
var fromDirectory = srcDirectory.Combine(project).Combine("bin").Combine(configuration).Combine(targetFramework);

var fileNames = new List<string>();
foreach (var extension in new[] { "dll", "pdb", "xml" })
{
var fileName = $"{project}.{extension}";
fileNames.Add(fileName);
}

foreach (var fileName in fileNames)
{
var fromFile = fromDirectory.CombineWithFilePath(fileName);
var toFile = toDirectory.CombineWithFilePath(fileName);
CopyFile(fromFile, toFile);
}
}
}
});

Task("Test")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/*.Tests.csproj").Where(name => !name.ToString().Contains("Atlas")),
action: (BuildConfig buildConfig, Path testProject) =>
Expand All @@ -121,68 +53,58 @@ Task("Test")
.DeferOnError();

Task("TestAwsAuthentication")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"AwsMechanism\""));

Task("TestPlainAuthentication")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"PlainMechanism\""));

Task("TestAtlasConnectivity")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/AtlasConnectivity.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) => RunTests(buildConfig, testProject));

Task("TestAtlasSearch")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"AtlasSearch\""));

Task("TestAtlasSearchIndexHelpers")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"AtlasSearchIndexHelpers\""));

Task("TestOcsp")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"OCSP\""));

Task("TestGssapi")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"GssapiMechanism\""));

Task("TestMongoDbOidc")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"MongoDbOidc\""));

Task("TestLibMongoCrypt")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Encryption.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) => RunTests(buildConfig, testProject));

Task("TestLoadBalanced")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/*.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
Expand Down Expand Up @@ -217,91 +139,17 @@ Task("TestCsfleWithGcpKms")
RunTests(buildConfig, testProject, filter: "Category=\"CsfleGCPKMS\""));

Task("TestX509")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/MongoDB.Driver.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"X509\""));

Task("TestSocks5Proxy")
.IsDependentOn("Build")
.DoesForEach(
items: GetFiles("./**/*.Tests.csproj"),
action: (BuildConfig buildConfig, Path testProject) =>
RunTests(buildConfig, testProject, filter: "Category=\"Socks5Proxy\""));

Task("Package")
.IsDependentOn("PackageNugetPackages");

Task("PackageNugetPackages")
.IsDependentOn("Build")
.Does<BuildConfig>((buildConfig) =>
{
EnsureDirectoryExists(artifactsPackagesDirectory);
CleanDirectory(artifactsPackagesDirectory);

var projects = new[]
{
"MongoDB.Bson",
"MongoDB.Driver",
"MongoDB.Driver.Encryption"
};

foreach (var project in projects)
{
var projectPath = $"{srcDirectory}\\{project}\\{project}.csproj";
var settings = new DotNetPackSettings
{
Configuration = configuration,
OutputDirectory = artifactsPackagesDirectory,
NoBuild = true, // SetContinuousIntegrationBuild is enabled for nupkg on the Build step
IncludeSymbols = true,
MSBuildSettings = new DotNetMSBuildSettings()
// configure deterministic build for better compatibility with debug symbols (used in Package/Build tasks). Affects: *.snupkg
.SetContinuousIntegrationBuild(continuousIntegrationBuild: true)
.WithProperty("PackageVersion", buildConfig.PackageVersion)
};
DotNetPack(projectPath, settings);
}
});

Task("PushToNuGet")
.Does(() =>
{
var nugetApiKey = EnvironmentVariable("NUGETAPIKEY");
if (nugetApiKey == null)
{
throw new Exception("NUGETAPIKEY environment variable missing");
}

var packageFiles = new List<FilePath>();

var projects = new[]
{
"MongoDB.Bson",
"MongoDB.Driver"
};

foreach (var project in projects)
{
var packageFileName = $"{project}.{gitVersion.LegacySemVer}.nupkg";
var packageFile = artifactsPackagesDirectory.CombineWithFilePath(packageFileName);
packageFiles.Add(packageFile);
}

NuGetPush(packageFiles, new NuGetPushSettings
{
ApiKey = nugetApiKey,
Source = "https://api.nuget.org/v3/index.json"
});
});

Task("DumpGitVersion")
.Does(() =>
{
Information(gitVersion.Dump());
});

Task("SmokeTests")
.DoesForEach(
GetFiles("./**/SmokeTests/**/*.SmokeTests*.csproj"),
Expand Down
26 changes: 26 additions & 0 deletions evergreen/compile-sources.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -o errexit # Exit the script with error if any of the commands fail

RESTORE_MAX_RETRIES=5
RESTORE_RETRY_DELAY_SECONDS_MULTIPLIER=10

for (( ATTEMPT=1; ATTEMPT<=RESTORE_MAX_RETRIES; ATTEMPT++ ))
do
echo "Attempt $ATTEMPT of $RESTORE_MAX_RETRIES to run dotnet restore..."
dotnet restore || exit_status=$?
if [[ "$exit_status" -eq 0 ]]; then
echo "dotnet restore succeeded."
break
fi

if [[ $ATTEMPT -eq $RESTORE_MAX_RETRIES ]]; then
echo "Failed to restore packages after $RESTORE_MAX_RETRIES retries."
exit 1
fi

DELAY=$((ATTEMPT * RESTORE_RETRY_DELAY_SECONDS_MULTIPLIER))
echo "dotnet restore failed. Retrying in $DELAY seconds..."
sleep $DELAY
done

dotnet build -c Release --no-restore
Loading