Skip to content

Commit 7d2c377

Browse files
authored
CSHARP-5399: Implement API compatibility validation EG script (#1533)
1 parent fe296ae commit 7d2c377

File tree

5 files changed

+95
-5
lines changed

5 files changed

+95
-5
lines changed

evergreen/evergreen.yml

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ functions:
100100
params:
101101
script: |
102102
${PREPARE_SHELL}
103-
OS=${OS} bash ${PROJECT_DIRECTORY}/evergreen/install-dotnet.sh
103+
OS=${OS} DOTNET_SDK_VERSION=${DOTNET_SDK_VERSION} bash ${PROJECT_DIRECTORY}/evergreen/install-dotnet.sh
104104
105105
prepare-resources:
106106
- command: shell.exec
@@ -1828,6 +1828,21 @@ tasks:
18281828
- func: build-packages
18291829
- func: upload-packages
18301830

1831+
- name: validate-apicompat
1832+
commands:
1833+
- func: install-dotnet
1834+
vars:
1835+
DOTNET_SDK_VERSION: 6.0
1836+
- func: download-packages
1837+
- command: shell.exec
1838+
type: test
1839+
params:
1840+
working_dir: mongo-csharp-driver
1841+
shell: "bash"
1842+
script: |
1843+
${PREPARE_SHELL}
1844+
bash evergreen/validate-apicompat.sh
1845+
18311846
- name: push-packages-nuget
18321847
commands:
18331848
- func: install-dotnet
@@ -2371,6 +2386,30 @@ task_groups:
23712386
tasks:
23722387
- test-serverless
23732388

2389+
- name: validate-apicompat-task-group
2390+
setup_group_can_fail_task: true
2391+
setup_group_timeout_secs: 1800 # 30 minutes
2392+
setup_group:
2393+
- func: fetch-source
2394+
- func: prepare-resources
2395+
- func: fix-absolute-paths
2396+
- func: make-files-executable
2397+
- func: install-dotnet
2398+
teardown_group:
2399+
- command: s3.put
2400+
params:
2401+
aws_key: ${aws_key}
2402+
aws_secret: ${aws_secret}
2403+
local_files_include_filter:
2404+
- mongo-csharp-driver/artifacts/apicompat/*.${PACKAGE_VERSION}.txt
2405+
remote_file: ${UPLOAD_BUCKET}/${revision}/
2406+
preserve_path: false
2407+
bucket: mciuploads
2408+
permissions: public-read
2409+
content_type: text/plain
2410+
tasks:
2411+
- validate-apicompat
2412+
23742413
buildvariants:
23752414
- matrix_name: stable-api-tests
23762415
matrix_spec: { version: ["5.0", "6.0", "7.0", "8.0", "rapid", "latest"], topology: "standalone", auth: "auth", ssl: "nossl", os: "windows-64" }
@@ -2725,6 +2764,16 @@ buildvariants:
27252764
- name: build-packages
27262765
priority: 10
27272766

2767+
- matrix_name: validate-apicompat
2768+
matrix_spec:
2769+
os: "ubuntu-2004"
2770+
display_name: "Validate API compatibility"
2771+
tasks:
2772+
- name: validate-apicompat-task-group
2773+
depends_on:
2774+
- name: build-packages
2775+
variant: ".build-packages"
2776+
27282777
- matrix_name: validate-apidocs
27292778
matrix_spec:
27302779
os: "ubuntu-2004"

evergreen/install-dotnet.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
set -o errexit # Exit the script with error if any of the commands fail
33

44
DOTNET_SDK_PATH="${DOTNET_SDK_PATH:-./.dotnet}"
5+
DOTNET_SDK_VERSION="${DOTNET_SDK_VERSION:-8.0}"
56

67
if [[ $OS =~ [Ww]indows.* ]]; then
78
echo "Downloading Windows .NET SDK installer into $DOTNET_SDK_PATH folder..."
89
curl -Lfo ./dotnet-install.ps1 https://dot.net/v1/dotnet-install.ps1
910
echo "Installing .NET 8.0 SDK..."
10-
powershell.exe ./dotnet-install.ps1 -Channel 8.0 -InstallDir "$DOTNET_SDK_PATH" -NoPath
11+
powershell.exe ./dotnet-install.ps1 -Channel "$DOTNET_SDK_VERSION" -InstallDir "$DOTNET_SDK_PATH" -NoPath
1112
else
1213
echo "Downloading .NET SDK installer into $DOTNET_SDK_PATH folder..."
1314
curl -Lfo ./dotnet-install.sh https://dot.net/v1/dotnet-install.sh
1415
echo "Installing .NET 8.0 SDK..."
15-
bash ./dotnet-install.sh --channel 8.0 --install-dir "$DOTNET_SDK_PATH" --no-path
16-
fi
16+
bash ./dotnet-install.sh --channel "$DOTNET_SDK_VERSION" --install-dir "$DOTNET_SDK_PATH" --no-path
17+
fi

evergreen/packages.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
PACKAGES=("MongoDB.Bson" "MongoDB.Driver" "MongoDB.Driver.Authentication.AWS" "MongoDB.Driver.Encryption")

evergreen/push-packages.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ if [ "$PACKAGES_SOURCE" = "https://api.nuget.org/v3/index.json" ] && [[ ! "$PACK
5555
exit 1
5656
fi
5757

58-
PACKAGES=("MongoDB.Bson" "MongoDB.Driver" "MongoDB.Driver.Authentication.AWS" "MongoDB.Driver.Encryption")
58+
source ./evergreen/packages.sh
5959

6060
for package in ${PACKAGES[*]}; do
6161
dotnet nuget verify ./artifacts/nuget/"$package"."$PACKAGE_VERSION".nupkg --certificate-fingerprint "$NUGET_SIGN_CERTIFICATE_FINGERPRINT"

evergreen/validate-apicompat.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
set -o errexit # Exit the script with error if any of the commands fail
3+
4+
# Environment variables used as input:
5+
# PACKAGE_VERSION
6+
7+
if [ -z "$PACKAGE_VERSION" ]; then
8+
PACKAGE_VERSION=$(bash ./evergreen/get-version.sh)
9+
echo Calculated PACKAGE_VERSION value: "$PACKAGE_VERSION"
10+
fi
11+
12+
BASELINE_VERSION="${PACKAGE_VERSION%%.*}.0.0"
13+
if [ "$PACKAGE_VERSION" == "$BASELINE_VERSION" ]; then
14+
echo "Skipping package validation for major release."
15+
exit 0
16+
fi
17+
18+
echo "Installing package validation tool."
19+
dotnet new tool-manifest --force
20+
dotnet tool install Microsoft.DotNet.ApiCompat.Tool --version 8.0.* --local
21+
22+
EXIT_CODE=0
23+
mkdir -p ./artifacts/apicompat/
24+
source ./evergreen/packages.sh
25+
for package in ${PACKAGES[*]}; do
26+
echo "Validating ${package}:${PACKAGE_VERSION} for compatibility with ${BASELINE_VERSION}"
27+
28+
curl -L -o "./artifacts/nuget/${package}.${BASELINE_VERSION}.nupkg" "https://www.nuget.org/api/v2/package/${package}/${BASELINE_VERSION}"
29+
# run apicompat tool and redirect stderr to file as apicompat reports problems as error output.
30+
dotnet tool run apicompat package "./artifacts/nuget/${package}.${PACKAGE_VERSION}.nupkg" --baseline-package "./artifacts/nuget/${package}.${BASELINE_VERSION}.nupkg" --enable-rule-cannot-change-parameter-name 2> "./artifacts/apicompat/${package}.${PACKAGE_VERSION}.txt"
31+
if [ -s "./artifacts/apicompat/${package}.${PACKAGE_VERSION}.txt" ] ; then
32+
EXIT_CODE=1
33+
else
34+
# delete file if empty (no compatibility issues detected)
35+
rm "./artifacts/apicompat/${package}.${PACKAGE_VERSION}.txt"
36+
fi
37+
done
38+
39+
exit $EXIT_CODE

0 commit comments

Comments
 (0)