forked from Azure/azure-cosmos-dotnet-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencryption-custom-compatibility.yml
More file actions
329 lines (283 loc) · 13.9 KB
/
Copy pathencryption-custom-compatibility.yml
File metadata and controls
329 lines (283 loc) · 13.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
name: Encryption.Custom Compatibility Tests
on:
pull_request:
branches:
- master
- main
paths:
- 'Microsoft.Azure.Cosmos.Encryption.Custom/**'
- '.github/workflows/encryption-custom-compatibility.yml'
push:
branches:
- master
- main
paths:
- 'Microsoft.Azure.Cosmos.Encryption.Custom/**'
schedule:
# Run daily at 2:00 AM UTC for comprehensive version matrix
- cron: '0 2 * * *'
workflow_dispatch:
inputs:
test_versions:
description: 'Comma-separated list of versions to test (e.g., "1.0.0-preview07"). Leave empty to test against all build sources.'
required: false
default: '1.0.0-preview07'
type: string
build_sources:
description: 'JSON array of build sources: [{"repo":"owner/repo","ref":"branch","name":"label"}]. Leave empty for current repo/branch.'
required: false
default: ''
type: string
env:
DOTNET_VERSION: '8.0.x'
jobs:
# Prepare build matrix
prepare-matrix:
name: Prepare Build Matrix
runs-on: ubuntu-latest
outputs:
build_sources: ${{ steps.setup-matrix.outputs.build_sources }}
steps:
- name: Setup build matrix
id: setup-matrix
run: |
# Use custom build sources if provided, otherwise use defaults based on trigger
if [ -n "${{ github.event.inputs.build_sources }}" ]; then
BUILD_SOURCES='${{ github.event.inputs.build_sources }}'
echo "Using custom build sources from workflow input"
elif [ "${{ github.event_name }}" == "schedule" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
# For scheduled/manual runs: test against multiple PRs for comprehensive validation
BUILD_SOURCES='[
{"repository":"${{ github.repository }}","ref":"${{ github.ref }}","source_name":"current"},
{"repository":"Azure/azure-cosmos-dotnet-v3","ref":"refs/pull/5385/head","source_name":"pr-5385"},
{"repository":"Azure/azure-cosmos-dotnet-v3","ref":"refs/pull/5399/head","source_name":"pr-5399"},
{"repository":"Azure/azure-cosmos-dotnet-v3","ref":"refs/pull/5403/head","source_name":"pr-5403"},
{"repository":"Azure/azure-cosmos-dotnet-v3","ref":"refs/pull/5417/head","source_name":"pr-5417"},
{"repository":"Azure/azure-cosmos-dotnet-v3","ref":"refs/pull/5428/head","source_name":"pr-5428"}
]'
echo "Using expanded build matrix with PRs for scheduled/manual run"
else
# For PR/CI builds: only test current branch for fast feedback
BUILD_SOURCES='[{"repository":"${{ github.repository }}","ref":"${{ github.ref }}","source_name":"current"}]'
echo "Using default build source: current repository and branch"
fi
echo "build_sources=$BUILD_SOURCES" >> $GITHUB_OUTPUT
echo "Build sources matrix:"
echo "$BUILD_SOURCES" | jq '.'
# Build packages from different sources (matrix)
build-packages:
name: Build ${{ matrix.build_source.source_name }}
needs: prepare-matrix
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.prepare-matrix.outputs.build_sources) }}
outputs:
# Output pattern: package_version_<source_name>
package_version: ${{ steps.build-pkg.outputs.version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
repository: ${{ matrix.repository }}
ref: ${{ matrix.ref }}
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Build and pack
id: build-pkg
run: |
# Create artifacts/local-packages folder (required by Directory.Build.props RestoreSources)
mkdir -p artifacts/local-packages
# Generate unique version with source identifier
SOURCE_SLUG=$(echo "${{ matrix.build_source.source_name }}" | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]-')
if [ "${{ github.event_name }}" == "pull_request" ]; then
VERSION_SUFFIX="pr${{ github.event.pull_request.number }}-${SOURCE_SLUG}-${{ github.run_number }}"
else
VERSION_SUFFIX="${SOURCE_SLUG}-${{ github.run_number }}"
fi
# Get base version from Directory.Build.props
BASE_VERSION=$(grep -oPm1 "(?<=<CustomEncryptionVersion>)[^<]+" Directory.Build.props)
PACKAGE_VERSION="${BASE_VERSION}-${VERSION_SUFFIX}"
echo "========================================="
echo "Building from: ${{ matrix.repository }}@${{ matrix.ref }}"
echo "Source name: ${{ matrix.build_source.source_name }}"
echo "Package version: $PACKAGE_VERSION"
echo "========================================="
echo "version=$PACKAGE_VERSION" >> $GITHUB_OUTPUT
# Build and pack
dotnet pack Microsoft.Azure.Cosmos.Encryption.Custom/src/Microsoft.Azure.Cosmos.Encryption.Custom.csproj \
--configuration Release \
-p:Version=$PACKAGE_VERSION \
-p:PackageVersion=$PACKAGE_VERSION \
--output ./packages
PACKAGE_FILE="./packages/Microsoft.Azure.Cosmos.Encryption.Custom.${PACKAGE_VERSION}.nupkg"
echo "path=$PACKAGE_FILE" >> $GITHUB_OUTPUT
echo "========================================="
echo "Built Package: $PACKAGE_FILE"
ls -lh ./packages/
echo "========================================="
- name: Upload package artifact
uses: actions/upload-artifact@v4
with:
name: package-${{ matrix.build_source.source_name }}
path: ./packages/*.nupkg
retention-days: 7
# Run compatibility tests with version matrix
# Tests built packages against specified published versions
compatibility-tests:
name: Test ${{ matrix.build_source.source_name }} ⟷ ${{ matrix.test_version }}
needs: [prepare-matrix, build-packages]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# Each build source will be tested against each test version
build_source: ${{ fromJson(needs.prepare-matrix.outputs.build_sources) }}
test_version:
- '1.0.0-preview07'
# Add more versions here as needed
# - '1.0.0-preview06'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-compat-${{ hashFiles('**/Directory.Packages.props', '**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-compat-
${{ runner.os }}-nuget-
- name: Download built package
uses: actions/download-artifact@v4
with:
name: package-${{ matrix.build_source.source_name }}
path: ./local-packages
- name: Setup test environment
run: |
# Create artifacts/local-packages folder (required by Directory.Build.props RestoreSources)
mkdir -p artifacts/local-packages
# Copy built package to artifacts/local-packages
cp ./local-packages/*.nupkg artifacts/local-packages/
echo "Copied built package to artifacts/local-packages"
ls -lh artifacts/local-packages/
# Get the actual package version from the filename
BUILT_PACKAGE=$(ls ./local-packages/Microsoft.Azure.Cosmos.Encryption.Custom.*.nupkg | head -1)
BUILT_VERSION=$(basename "$BUILT_PACKAGE" | sed 's/Microsoft.Azure.Cosmos.Encryption.Custom.\(.*\).nupkg/\1/')
echo "BUILT_VERSION=$BUILT_VERSION" >> $GITHUB_ENV
echo "Built package version: $BUILT_VERSION"
- name: Update test configuration
run: |
BUILT_VERSION="${{ env.BUILT_VERSION }}"
TEST_VERSION="${{ matrix.test_version }}"
# Create version array for this specific test pair
VERSIONS_JSON="[\"$BUILT_VERSION\",\"$TEST_VERSION\"]"
echo "========================================="
echo "Test Pair Configuration"
echo "========================================="
echo "Built Source: ${{ matrix.build_source.source_name }}"
echo "Built Version: $BUILT_VERSION"
echo "Test Version: $TEST_VERSION"
echo "Test versions: $VERSIONS_JSON"
echo "========================================="
# Update testconfig.json with this specific version pair
cd Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests
# Update the versions array in testconfig.json
jq ".versionMatrix.versions = $VERSIONS_JSON" testconfig.json > testconfig.json.tmp
mv testconfig.json.tmp testconfig.json
echo "Updated testconfig.json:"
cat testconfig.json
- name: Restore dependencies
run: |
dotnet restore Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests.csproj
- name: Build compatibility tests
run: |
dotnet build Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests.csproj \
--configuration Release \
--no-restore
- name: Run compatibility tests
id: run-tests
continue-on-error: true
run: |
dotnet test Microsoft.Azure.Cosmos.Encryption.Custom/tests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests/Microsoft.Azure.Cosmos.Encryption.Custom.CompatibilityTests.csproj \
--configuration Release \
--no-build \
--no-restore \
--logger "trx;LogFileName=compatibility-${{ matrix.build_source.source_name }}-vs-${{ matrix.test_version }}.trx" \
--logger "console;verbosity=normal" \
--results-directory ./TestResults
- name: Upload test results (TRX)
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.build_source.source_name }}-vs-${{ matrix.test_version }}
path: ./TestResults/*.trx
retention-days: 30
- name: Publish test results
if: always()
uses: dorny/test-reporter@v1
with:
name: Compatibility Test Results
path: './TestResults/*.trx'
reporter: dotnet-trx
fail-on-error: true
fail-on-empty: true
- name: Generate test summary
if: always()
run: |
echo "## 🧪 Compatibility Test Results: ${{ matrix.build_source.source_name }} vs ${{ matrix.test_version }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Built Source:** \`${{ matrix.build_source.source_name }}\`" >> $GITHUB_STEP_SUMMARY
echo "**Test Version:** \`${{ matrix.test_version }}\`" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
TRX_FILE="./TestResults/compatibility-${{ matrix.build_source.source_name }}-vs-${{ matrix.test_version }}.trx"
if [ -f "$TRX_FILE" ]; then
# Parse TRX file for summary (basic parsing)
TOTAL=$(grep -oP '(?<=total=")[^"]+' "$TRX_FILE" | head -1)
PASSED=$(grep -oP '(?<=passed=")[^"]+' "$TRX_FILE" | head -1)
FAILED=$(grep -oP '(?<=failed=")[^"]+' "$TRX_FILE" | head -1)
echo "| Metric | Count |" >> $GITHUB_STEP_SUMMARY
echo "|--------|-------|" >> $GITHUB_STEP_SUMMARY
echo "| Total Tests | $TOTAL |" >> $GITHUB_STEP_SUMMARY
echo "| ✅ Passed | $PASSED |" >> $GITHUB_STEP_SUMMARY
echo "| ❌ Failed | $FAILED |" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "$FAILED" == "0" ]; then
echo "### ✅ All compatibility tests passed!" >> $GITHUB_STEP_SUMMARY
else
echo "### ❌ Some compatibility tests failed" >> $GITHUB_STEP_SUMMARY
echo "Check the detailed test report above for failure details." >> $GITHUB_STEP_SUMMARY
fi
else
echo "⚠️ Test results file not found: $TRX_FILE" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "---" >> $GITHUB_STEP_SUMMARY
echo "📦 **Test Pair:** \`${{ matrix.build_source.source_name }}\` ⟷ \`${{ matrix.test_version }}\`" >> $GITHUB_STEP_SUMMARY
- name: Fail workflow if tests failed
if: steps.run-tests.outcome == 'failure'
run: |
echo "❌ Compatibility tests failed"
exit 1
- name: Display test summary
if: always()
run: |
echo "========================================="
echo "Compatibility Test Summary"
echo "========================================="
echo "Built Source: ${{ matrix.build_source.source_name }}"
echo "Test Version: ${{ matrix.test_version }}"
echo "========================================="
if [ "${{ steps.run-tests.outcome }}" == "success" ]; then
echo "✅ Compatibility test passed for this version pair"
else
echo "❌ Compatibility test failures detected for this version pair"
fi
echo "========================================="