Skip to content

Commit ced1e3a

Browse files
authored
CSHARP-5784: Execute dotnet restore with retries on Evergreen (#1816)
1 parent 1ef7fcc commit ced1e3a

21 files changed

+75
-233
lines changed

build.cake

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -25,82 +25,14 @@ var artifactsPackagesDirectory = artifactsDirectory.Combine("packages");
2525
var srcDirectory = solutionDirectory.Combine("src");
2626
var testsDirectory = solutionDirectory.Combine("tests");
2727
var outputDirectory = solutionDirectory.Combine("build");
28-
var toolsDirectory = solutionDirectory.Combine("tools");
29-
var toolsHugoDirectory = toolsDirectory.Combine("Hugo");
30-
var mongoDbDriverPackageName = "MongoDB.Driver";
3128

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

3532
Task("Default")
3633
.IsDependentOn("Test");
3734

38-
Task("Release")
39-
.IsDependentOn("Build")
40-
.IsDependentOn("Package");
41-
42-
Task("Restore")
43-
.Does(() =>
44-
{
45-
// disable parallel restore to work around apparent bugs in restore
46-
var restoreSettings = new DotNetRestoreSettings
47-
{
48-
DisableParallel = true
49-
};
50-
DotNetRestore(solutionFullPath, restoreSettings);
51-
});
52-
53-
Task("Build")
54-
.IsDependentOn("Restore")
55-
.Does<BuildConfig>((buildConfig) =>
56-
{
57-
var settings = new DotNetBuildSettings
58-
{
59-
NoRestore = true,
60-
Configuration = configuration,
61-
EnvironmentVariables = new Dictionary<string, string>
62-
{
63-
{ "Version", gitVersion.LegacySemVer },
64-
{ "SourceRevisionId", gitVersion.Sha }
65-
}
66-
};
67-
68-
DotNetBuild(solutionFullPath, settings);
69-
});
70-
71-
Task("BuildArtifacts")
72-
.IsDependentOn("Build")
73-
.Does(() =>
74-
{
75-
foreach (var targetFramework in new[] { "net472", "netstandard2.0", "netstandard2.1" })
76-
{
77-
var toDirectory = artifactsBinDirectory.Combine(targetFramework);
78-
CleanDirectory(toDirectory);
79-
80-
var projects = new[] { "MongoDB.Bson", "MongoDB.Driver" };
81-
foreach (var project in projects)
82-
{
83-
var fromDirectory = srcDirectory.Combine(project).Combine("bin").Combine(configuration).Combine(targetFramework);
84-
85-
var fileNames = new List<string>();
86-
foreach (var extension in new[] { "dll", "pdb", "xml" })
87-
{
88-
var fileName = $"{project}.{extension}";
89-
fileNames.Add(fileName);
90-
}
91-
92-
foreach (var fileName in fileNames)
93-
{
94-
var fromFile = fromDirectory.CombineWithFilePath(fileName);
95-
var toFile = toDirectory.CombineWithFilePath(fileName);
96-
CopyFile(fromFile, toFile);
97-
}
98-
}
99-
}
100-
});
101-
10235
Task("Test")
103-
.IsDependentOn("Build")
10436
.DoesForEach(
10537
items: GetFiles("./**/*.Tests.csproj").Where(name => !name.ToString().Contains("Atlas")),
10638
action: (BuildConfig buildConfig, Path testProject) =>
@@ -121,68 +53,58 @@ Task("Test")
12153
.DeferOnError();
12254

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

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

13767
Task("TestAtlasConnectivity")
138-
.IsDependentOn("Build")
13968
.DoesForEach(
14069
items: GetFiles("./**/AtlasConnectivity.Tests.csproj"),
14170
action: (BuildConfig buildConfig, Path testProject) => RunTests(buildConfig, testProject));
14271

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

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

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

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

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

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

184107
Task("TestLoadBalanced")
185-
.IsDependentOn("Build")
186108
.DoesForEach(
187109
items: GetFiles("./**/*.Tests.csproj"),
188110
action: (BuildConfig buildConfig, Path testProject) =>
@@ -217,91 +139,17 @@ Task("TestCsfleWithGcpKms")
217139
RunTests(buildConfig, testProject, filter: "Category=\"CsfleGCPKMS\""));
218140

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

226147
Task("TestSocks5Proxy")
227-
.IsDependentOn("Build")
228148
.DoesForEach(
229149
items: GetFiles("./**/*.Tests.csproj"),
230150
action: (BuildConfig buildConfig, Path testProject) =>
231151
RunTests(buildConfig, testProject, filter: "Category=\"Socks5Proxy\""));
232152

233-
Task("Package")
234-
.IsDependentOn("PackageNugetPackages");
235-
236-
Task("PackageNugetPackages")
237-
.IsDependentOn("Build")
238-
.Does<BuildConfig>((buildConfig) =>
239-
{
240-
EnsureDirectoryExists(artifactsPackagesDirectory);
241-
CleanDirectory(artifactsPackagesDirectory);
242-
243-
var projects = new[]
244-
{
245-
"MongoDB.Bson",
246-
"MongoDB.Driver",
247-
"MongoDB.Driver.Encryption"
248-
};
249-
250-
foreach (var project in projects)
251-
{
252-
var projectPath = $"{srcDirectory}\\{project}\\{project}.csproj";
253-
var settings = new DotNetPackSettings
254-
{
255-
Configuration = configuration,
256-
OutputDirectory = artifactsPackagesDirectory,
257-
NoBuild = true, // SetContinuousIntegrationBuild is enabled for nupkg on the Build step
258-
IncludeSymbols = true,
259-
MSBuildSettings = new DotNetMSBuildSettings()
260-
// configure deterministic build for better compatibility with debug symbols (used in Package/Build tasks). Affects: *.snupkg
261-
.SetContinuousIntegrationBuild(continuousIntegrationBuild: true)
262-
.WithProperty("PackageVersion", buildConfig.PackageVersion)
263-
};
264-
DotNetPack(projectPath, settings);
265-
}
266-
});
267-
268-
Task("PushToNuGet")
269-
.Does(() =>
270-
{
271-
var nugetApiKey = EnvironmentVariable("NUGETAPIKEY");
272-
if (nugetApiKey == null)
273-
{
274-
throw new Exception("NUGETAPIKEY environment variable missing");
275-
}
276-
277-
var packageFiles = new List<FilePath>();
278-
279-
var projects = new[]
280-
{
281-
"MongoDB.Bson",
282-
"MongoDB.Driver"
283-
};
284-
285-
foreach (var project in projects)
286-
{
287-
var packageFileName = $"{project}.{gitVersion.LegacySemVer}.nupkg";
288-
var packageFile = artifactsPackagesDirectory.CombineWithFilePath(packageFileName);
289-
packageFiles.Add(packageFile);
290-
}
291-
292-
NuGetPush(packageFiles, new NuGetPushSettings
293-
{
294-
ApiKey = nugetApiKey,
295-
Source = "https://api.nuget.org/v3/index.json"
296-
});
297-
});
298-
299-
Task("DumpGitVersion")
300-
.Does(() =>
301-
{
302-
Information(gitVersion.Dump());
303-
});
304-
305153
Task("SmokeTests")
306154
.DoesForEach(
307155
GetFiles("./**/SmokeTests/**/*.SmokeTests*.csproj"),

evergreen/build-packages.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ fi
1212
echo Creating nuget package...
1313

1414
dotnet clean ./CSharpDriver.sln
15-
dotnet pack ./CSharpDriver.sln -o ./artifacts/nuget -c Release -p:Version="$PACKAGE_VERSION" --include-symbols -p:SymbolPackageFormat=snupkg -p:ContinuousIntegrationBuild=true
15+
. ./evergreen/compile-sources.sh
16+
dotnet pack ./CSharpDriver.sln --no-build -o ./artifacts/nuget -c Release -p:Version="$PACKAGE_VERSION" --include-symbols -p:SymbolPackageFormat=snupkg -p:ContinuousIntegrationBuild=true

evergreen/compile-sources.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/env bash
2+
set -o errexit # Exit the script with error if any of the commands fail
3+
4+
if [ -z "$PACKAGE_VERSION" ]; then
5+
PACKAGE_VERSION=$(bash ./evergreen/get-version.sh)
6+
echo Calculated PACKAGE_VERSION value: "$PACKAGE_VERSION"
7+
fi
8+
9+
RESTORE_MAX_RETRIES=5
10+
RESTORE_RETRY_DELAY_SECONDS_MULTIPLIER=10
11+
12+
for (( ATTEMPT=1; ATTEMPT<=RESTORE_MAX_RETRIES; ATTEMPT++ ))
13+
do
14+
echo "Attempt $ATTEMPT of $RESTORE_MAX_RETRIES to run dotnet restore..."
15+
exit_status=0
16+
dotnet restore || exit_status=$?
17+
if [[ "$exit_status" -eq 0 ]]; then
18+
echo "dotnet restore succeeded."
19+
break
20+
fi
21+
22+
if [[ $ATTEMPT -eq $RESTORE_MAX_RETRIES ]]; then
23+
echo "Failed to restore packages after $RESTORE_MAX_RETRIES retries."
24+
exit 1
25+
fi
26+
27+
DELAY=$((ATTEMPT * RESTORE_RETRY_DELAY_SECONDS_MULTIPLIER))
28+
echo "dotnet restore attempt $ATTEMPT failed. Retrying in $DELAY seconds..."
29+
sleep $DELAY
30+
done
31+
32+
dotnet build -c Release --no-restore -p:Version="$PACKAGE_VERSION"

evergreen/evergreen.yml

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,14 @@ functions:
104104
- command: shell.exec
105105
type: system
106106
params:
107+
working_dir: mongo-csharp-driver
107108
include_expansions_in_env:
108109
- "OS"
109110
- "DOTNET_SDK_VERSION"
110111
- "FRAMEWORK"
111112
script: |
112113
${PREPARE_SHELL}
113-
bash ${PROJECT_DIRECTORY}/evergreen/install-dotnet.sh
114+
bash evergreen/install-dotnet.sh
114115
115116
prepare-resources:
116117
- command: shell.exec
@@ -196,40 +197,6 @@ functions:
196197
content_type: ${content_type|text/plain}
197198
display_name: "orchestration.log"
198199

199-
upload-working-dir:
200-
- command: archive.targz_pack
201-
params:
202-
target: "working-dir.tar.gz"
203-
source_dir: ${PROJECT_DIRECTORY}/
204-
include:
205-
- "./**"
206-
- command: s3.put
207-
params:
208-
aws_key: ${aws_key}
209-
aws_secret: ${aws_secret}
210-
local_file: working-dir.tar.gz
211-
remote_file: ${UPLOAD_BUCKET}/${build_variant}/${revision}/${version_id}/${build_id}/artifacts/${task_id}-${execution}-working-dir.tar.gz
212-
bucket: mciuploads
213-
permissions: public-read
214-
content_type: ${content_type|application/x-gzip}
215-
display_name: "working-dir.tar.gz"
216-
- command: archive.targz_pack
217-
params:
218-
target: "drivers-dir.tar.gz"
219-
source_dir: ${DRIVERS_TOOLS}
220-
include:
221-
- "./**"
222-
- command: s3.put
223-
params:
224-
aws_key: ${aws_key}
225-
aws_secret: ${aws_secret}
226-
local_file: drivers-dir.tar.gz
227-
remote_file: ${UPLOAD_BUCKET}/${build_variant}/${revision}/${version_id}/${build_id}/artifacts/${task_id}-${execution}-drivers-dir.tar.gz
228-
bucket: mciuploads
229-
permissions: public-read
230-
content_type: ${content_type|application/x-gzip}
231-
display_name: "drivers-dir.tar.gz"
232-
233200
upload-test-results:
234201
- command: attach.xunit_results
235202
params:
@@ -376,7 +343,7 @@ functions:
376343
- "FRAMEWORK"
377344
script: |
378345
${PREPARE_SHELL}
379-
bash evergreen/run-unit-tests.sh
346+
bash ./evergreen/run-unit-tests.sh
380347
381348
run-tests:
382349
- command: shell.exec
@@ -614,6 +581,7 @@ functions:
614581
echo "This platform does not support the ECS auth test, skipping..."
615582
exit 0
616583
fi
584+
. ./evergreen/compile-sources.sh
617585
echo "Project Directory: $PROJECT_DIRECTORY"
618586
# SRC_DIRECTORY is workaround since EG_TOOLS expects "src" folder as a root
619587
SRC_DIRECTORY=$(dirname $PROJECT_DIRECTORY)/src

evergreen/run-atlas-connectivity-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ set -o errexit # Exit the script with error if any of the commands fail
88

99
# Provision the correct connection string and set up SSL if needed
1010
for var in TMP TEMP NUGET_PACKAGES NUGET_HTTP_CACHE_PATH APPDATA; do setx $var z:\\data\\tmp; export $var=z:\\data\\tmp; done
11+
. ./evergreen/compile-sources.sh
1112
powershell.exe .\\build.ps1 --target TestAtlasConnectivity

evergreen/run-atlas-search-index-helpers-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ echo "Running Atlas Search Index Helpers driver tests"
1313

1414
export ATLAS_SEARCH_INDEX_HELPERS_TESTS_ENABLED=true
1515

16-
./build.sh --target=TestAtlasSearchIndexHelpers
16+
. ./evergreen/compile-sources.sh
17+
./build.sh --target=TestAtlasSearchIndexHelpers

evergreen/run-atlas-search-test.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ echo "Running Atlas Search driver tests"
1313

1414
export ATLAS_SEARCH_TESTS_ENABLED=true
1515

16-
powershell.exe .\\build.ps1 --target=TestAtlasSearch
16+
. ./evergreen/compile-sources.sh
17+
powershell.exe .\\build.ps1 --target=TestAtlasSearch

evergreen/run-csfle-azure-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ export CSFLE_AZURE_KMS_TESTS_ENABLED=true
2424
export FRAMEWORK=net6.0
2525
. ./evergreen/install-dotnet.sh
2626

27+
. ./evergreen/compile-sources.sh
2728
. ./build.sh --target=TestCsfleWithAzureKms

evergreen/run-csfle-gcp-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ export CSFLE_GCP_KMS_TESTS_ENABLED=true
1717
export FRAMEWORK=net6.0
1818
. ./evergreen/install-dotnet.sh
1919

20+
. ./evergreen/compile-sources.sh
2021
. ./build.sh --target=TestCsfleWithGcpKms

0 commit comments

Comments
 (0)