mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
25291de8cb
* support retries * tests + registration options * fix ordering .. * HK + update packages * fix paths * Update dotnet/tests/CosmosDB.IntegrationTests/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB.Tests/CosmosTestFixture.cs * re create project and fix some pk usage * fix all tests * try workflow? * wip 1 * fix definition * try with cosmos_use_emulator env? * try ignore SSL errors? * other cert verifications * hardcode to 8081? * proper valuation of ENV * logging * ensure db exsists for CI * bump * cleanup * fix usage * nit comment * try only release for stability? * try skip some flaky tests * merge fixes + rollback container * reimplement with iasyncdisposable pattern * remove example doc struct
158 lines
6.3 KiB
YAML
158 lines
6.3 KiB
YAML
#
|
|
# This workflow runs Cosmos DB integration tests using the Cosmos DB emulator.
|
|
#
|
|
|
|
name: dotnet-cosmosdb-integration-tests
|
|
|
|
on:
|
|
workflow_dispatch:
|
|
pull_request:
|
|
branches: ["main", "feature*"]
|
|
paths:
|
|
- dotnet/tests/CosmosDB.IntegrationTests/**
|
|
- dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/**
|
|
- '.github/workflows/dotnet-cosmosdb-integration-tests.yml'
|
|
merge_group:
|
|
branches: ["main"]
|
|
push:
|
|
branches: ["main", "feature*"]
|
|
paths:
|
|
- dotnet/tests/CosmosDB.IntegrationTests/**
|
|
- dotnet/src/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB/**
|
|
- '.github/workflows/dotnet-cosmosdb-integration-tests.yml'
|
|
schedule:
|
|
- cron: "0 2 * * *" # Run at 2 AM UTC daily
|
|
|
|
env:
|
|
COSMOSDB_TESTS_USE_EMULATOR_CICD: "true"
|
|
|
|
jobs:
|
|
build-and-test:
|
|
runs-on: ${{ matrix.os }}
|
|
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- { targetFramework: "net9.0", os: "ubuntu-latest", configuration: Release }
|
|
# - { targetFramework: "net9.0", os: "ubuntu-latest", configuration: Debug }
|
|
|
|
services:
|
|
cosmosdb:
|
|
image: mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest
|
|
ports:
|
|
- 8081:8081
|
|
env:
|
|
AZURE_COSMOS_EMULATOR_ENABLE_DATA_PERSISTENCE: "false"
|
|
AZURE_COSMOS_EMULATOR_PARTITION_COUNT: "20" # the more the better for stable tests
|
|
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
with:
|
|
persist-credentials: false
|
|
sparse-checkout: |
|
|
.
|
|
.github
|
|
dotnet
|
|
- name: Setup dotnet
|
|
uses: actions/setup-dotnet@v4.3.1
|
|
with:
|
|
global-json-file: ${{ github.workspace }}/dotnet/global.json
|
|
- name: Build dotnet solutions
|
|
shell: bash
|
|
run: |
|
|
export SOLUTIONS=$(find ./dotnet/ -type f -name "*.slnx" | tr '\n' ' ')
|
|
for solution in $SOLUTIONS; do
|
|
dotnet build $solution -c ${{ matrix.configuration }} --warnaserror
|
|
done
|
|
- name: Package install check
|
|
shell: bash
|
|
# All frameworks are only built for the release configuration, so we only run this step for the release configuration
|
|
# and dotnet new doesn't support net472
|
|
if: matrix.configuration == 'Release' && matrix.targetFramework != 'net472'
|
|
run: |
|
|
TEMP_DIR=$(mktemp -d)
|
|
|
|
export SOLUTIONS=$(find ./dotnet/ -type f -name "*.slnx" | tr '\n' ' ')
|
|
for solution in $SOLUTIONS; do
|
|
dotnet pack $solution /property:TargetFrameworks=${{ matrix.targetFramework }} -c ${{ matrix.configuration }} --no-build --no-restore --output "$TEMP_DIR/artifacts"
|
|
done
|
|
|
|
pushd "$TEMP_DIR"
|
|
|
|
# Create a new console app to test the package installation
|
|
dotnet new console -f ${{ matrix.targetFramework }} --name packcheck --output consoleapp
|
|
|
|
# Create minimal nuget.config and use only dotnet nuget commands
|
|
echo '<?xml version="1.0" encoding="utf-8"?><configuration><packageSources><clear /></packageSources></configuration>' > consoleapp/nuget.config
|
|
|
|
# Add sources with local first using dotnet nuget commands
|
|
dotnet nuget add source ../artifacts --name local --configfile consoleapp/nuget.config
|
|
dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org --configfile consoleapp/nuget.config
|
|
|
|
# Change to project directory to ensure local nuget.config is used
|
|
pushd consoleapp
|
|
dotnet add packcheck.csproj package Microsoft.Extensions.AI.Agents --prerelease
|
|
dotnet build -f ${{ matrix.targetFramework }} -c ${{ matrix.configuration }} packcheck.csproj
|
|
|
|
# Clean up
|
|
popd
|
|
popd
|
|
rm -rf "$TEMP_DIR"
|
|
|
|
- name: Wait for Cosmos DB Emulator to be ready
|
|
run: |
|
|
set -e
|
|
for i in $(seq 1 120); do
|
|
if curl -sk https://localhost:8081/_explorer/emulator.pem -o /dev/null; then
|
|
echo "Emulator is up."
|
|
break
|
|
fi
|
|
echo "Waiting for emulator... ($i/120)"
|
|
sleep 2
|
|
done
|
|
|
|
- name: Install emulator TLS certificate into system trust store
|
|
run: |
|
|
set -e
|
|
sudo apt-get update
|
|
sudo apt-get install -y ca-certificates curl openssl
|
|
# Fetch the PEM directly from the emulator's explorer endpoint
|
|
curl -sk https://localhost:8081/_explorer/emulator.pem -o cosmos-emulator.crt
|
|
# Install with the correct .crt extension so update-ca-certificates picks it up
|
|
sudo cp cosmos-emulator.crt /usr/local/share/ca-certificates/cosmos-emulator.crt
|
|
sudo update-ca-certificates
|
|
|
|
- name: Verify TLS now trusts the emulator
|
|
run: |
|
|
# Use -servername to avoid SNI warning and check verification
|
|
echo | openssl s_client -connect localhost:8081 -servername localhost 2>/dev/null | grep -E "Verify return code|subject=|issuer="
|
|
# Expect: "Verify return code: 0 (ok)"
|
|
|
|
- name: Run Cosmos DB Integration Tests
|
|
shell: bash
|
|
run: |
|
|
# Run the specific CosmosDB integration tests
|
|
dotnet test ./dotnet/tests/CosmosDB.IntegrationTests/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB.Tests/Microsoft.Extensions.AI.Agents.Runtime.Storage.CosmosDB.Tests.csproj \
|
|
-f ${{ matrix.targetFramework }} \
|
|
-c ${{ matrix.configuration }} \
|
|
--no-build \
|
|
-v Normal \
|
|
--logger trx \
|
|
--collect:"XPlat Code Coverage" \
|
|
--results-directory:"TestResults/Coverage/" \
|
|
-- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.ExcludeByAttribute=GeneratedCodeAttribute,CompilerGeneratedAttribute,ExcludeFromCodeCoverageAttribute
|
|
|
|
# Generate test reports and check coverage
|
|
- name: Generate test reports
|
|
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.11
|
|
with:
|
|
reports: "./TestResults/Coverage/**/coverage.cobertura.xml"
|
|
targetdir: "./TestResults/Reports"
|
|
reporttypes: "HtmlInline;JsonSummary"
|
|
|
|
- name: Upload coverage report artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: CosmosDB-CoverageReport-${{ matrix.os }}-${{ matrix.targetFramework }}-${{ matrix.configuration }}
|
|
path: ./TestResults/Reports |