-
Notifications
You must be signed in to change notification settings - Fork 27
352 lines (303 loc) · 12.3 KB
/
compatibility-matrix-test.yml
File metadata and controls
352 lines (303 loc) · 12.3 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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
name: Compatibility Matrix Test
on:
# Run every morning at 9 AM UTC on the main branch
schedule:
- cron: '0 9 * * *'
# Allow manual trigger from any branch
workflow_dispatch:
inputs:
combination:
description: 'Test specific combination (leave empty for all)'
required: false
type: string
clean_build:
description: 'Clean build between tests'
required: false
type: boolean
default: false
jobs:
# Read the compatibility matrix and set up the test matrix
setup:
name: Setup Test Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up matrix from JSON
id: set-matrix
run: |
# Read the compatibility matrix JSON and filter out disabled combinations
MATRIX=$(cat .github/workflows/compatibility-matrix.json | jq -c '[.combinations[] | select(.enabled // true == true)]')
echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
# Print the matrix for debugging
echo "Enabled test combinations:"
echo "$MATRIX" | jq -r '.[] | " - \(.name): AGP \(.agp), Gradle \(.gradle), Java \(.java), Kotlin \(.kotlin)"'
# Print disabled combinations for reference
DISABLED=$(cat .github/workflows/compatibility-matrix.json | jq -c '[.combinations[] | select(.enabled == false)]')
DISABLED_COUNT=$(echo "$DISABLED" | jq 'length')
if [ "$DISABLED_COUNT" -gt 0 ]; then
echo ""
echo "Disabled combinations (future versions):"
echo "$DISABLED" | jq -r '.[] | " - \(.name): \(.note // "Future version")"'
fi
# Build the agent once and cache it for all test jobs
build-agent:
name: Build and Publish Agent
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK 11
uses: actions/setup-java@v4
with:
java-version: 11
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
with:
cache-read-only: false
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Publish Agent to Local Maven
run: |
./gradlew publishToMavenLocal -x test -x functionalTests -x integrationTests
env:
JAVA_HOME: ${{ env.JAVA_HOME }}
- name: Upload Maven Local Repository
uses: actions/upload-artifact@v4
with:
name: maven-local-repository
path: ~/.m2/repository/com/newrelic/agent/android/
retention-days: 1
# Run tests for each combination in the matrix
test:
name: Test ${{ matrix.combination.name }}
runs-on: ubuntu-latest
needs: [setup, build-agent]
timeout-minutes: 30
strategy:
fail-fast: false # Continue testing other combinations even if one fails
max-parallel: 1 # Run tests sequentially to avoid conflicts with shared files
matrix:
combination: ${{ fromJson(needs.setup.outputs.matrix) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up JDK ${{ matrix.combination.java }}
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.combination.java }}
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/gradle-build-action@v3
with:
gradle-version: ${{ matrix.combination.gradle }}
cache-read-only: false
- name: Cache Android SDK
uses: actions/cache@v4
with:
path: |
~/.android/sdk
~/.android/avd
key: android-sdk-${{ runner.os }}-${{ hashFiles('**/build.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
android-sdk-${{ runner.os }}-
- name: Download Pre-built Agent from Maven
uses: actions/download-artifact@v4
with:
name: maven-local-repository
path: ~/.m2/repository/com/newrelic/agent/android/
- name: Grant execute permission for gradlew and test script
run: |
chmod +x gradlew
chmod +x scripts/test-compatibility-matrix.sh
- name: Build Test App with ${{ matrix.combination.name }}
id: build
run: |
echo "::group::Building with configuration"
echo "AGP Version: ${{ matrix.combination.agp }}"
echo "Gradle Version: ${{ matrix.combination.gradle }}"
echo "Java Version: ${{ matrix.combination.java }}"
echo "Kotlin Version: ${{ matrix.combination.kotlin }}"
echo "::endgroup::"
# Use the test script to properly handle version switching
./scripts/test-compatibility-matrix.sh --combination "${{ matrix.combination.name }}" --verbose
env:
JAVA_HOME: ${{ env.JAVA_HOME }}
- name: Check APK was generated
if: success()
working-directory: samples/agent-test-app
run: |
APK_PATH="build/outputs/apk/release/agent-test-app-release-unsigned.apk"
if [ -f "$APK_PATH" ]; then
APK_SIZE=$(du -h "$APK_PATH" | cut -f1)
echo "✓ APK generated successfully: $APK_SIZE"
echo "apk_generated=true" >> $GITHUB_OUTPUT
echo "apk_size=$APK_SIZE" >> $GITHUB_OUTPUT
else
echo "✗ APK not found at $APK_PATH"
echo "apk_generated=false" >> $GITHUB_OUTPUT
exit 1
fi
- name: Upload APK as artifact
if: success()
uses: actions/upload-artifact@v4
with:
name: apk-${{ matrix.combination.name }}-agp${{ matrix.combination.agp }}
path: samples/agent-test-app/build/outputs/apk/release/*.apk
retention-days: 7
if-no-files-found: error
- name: Upload build logs on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: build-logs-${{ matrix.combination.name }}
path: |
samples/agent-test-app/build/reports/
samples/agent-test-app/build/outputs/logs/
retention-days: 7
if-no-files-found: ignore
# Generate a summary report
report:
name: Generate Test Report
runs-on: ubuntu-latest
needs: [setup, test]
if: always() # Run even if some tests failed
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Generate Summary
run: |
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
# 📊 Compatibility Matrix Test Results
## Test Configuration
- **Triggered by**: ${{ github.event_name }}
- **Run ID**: ${{ github.run_id }}
- **Date**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
## Test Matrix
| Configuration | AGP | Gradle | Java | Kotlin | Status |
|---------------|-----|--------|------|--------|--------|
EOF
# Parse matrix and add results
MATRIX='${{ needs.setup.outputs.matrix }}'
echo "$MATRIX" | jq -r '.[] |
"| \(.name) | \(.agp) | \(.gradle) | \(.java) | \(.kotlin) | ⏳ Running |"
' >> $GITHUB_STEP_SUMMARY
cat >> $GITHUB_STEP_SUMMARY << 'EOF'
## 📝 Notes
- ✅ Green: Build succeeded and APK generated
- ❌ Red: Build failed
- ⏭️ Skipped: Dependency failure
EOF
# Comment on PR with results (only runs if workflow is triggered by a pull_request event)
# Note: This job is disabled by default since the workflow runs on schedule/manual trigger
# Re-enable by adding 'pull_request:' trigger if needed
comment:
name: Post PR Comment
runs-on: ubuntu-latest
needs: [setup, test, build-agent]
if: github.event_name == 'pull_request' && always()
permissions:
pull-requests: write
steps:
- name: Generate Comment Body
uses: actions/github-script@v7
id: generate-comment
with:
script: |
const matrix = ${{ needs.setup.outputs.matrix }};
// Fetch all workflow jobs to get individual test results
const { data: jobs } = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: context.runId,
});
// Map test job results by combination name
const testResults = {};
jobs.jobs.forEach(job => {
// Match jobs like "Test AGP 7.4 - Stable"
const match = job.name.match(/^Test (.+)$/);
if (match) {
const combinationName = match[1];
testResults[combinationName] = {
conclusion: job.conclusion,
status: job.status,
html_url: job.html_url
};
}
});
// Generate markdown table
let comment = `## 🤖 Compatibility Matrix Test Results\n\n`;
comment += `The agent was tested against multiple AGP/Gradle/Java/Kotlin combinations:\n\n`;
comment += `| Configuration | AGP | Gradle | Java | Kotlin | Result |\n`;
comment += `|---------------|-----|--------|------|--------|--------|\n`;
matrix.forEach(combo => {
const result = testResults[combo.name];
let statusIcon = '⏳';
let statusText = 'Running';
if (result) {
if (result.conclusion === 'success') {
statusIcon = '✅';
statusText = 'Passed';
} else if (result.conclusion === 'failure') {
statusIcon = '❌';
statusText = 'Failed';
} else if (result.conclusion === 'cancelled') {
statusIcon = '🚫';
statusText = 'Cancelled';
} else if (result.conclusion === 'skipped') {
statusIcon = '⏭️';
statusText = 'Skipped';
}
}
comment += `| ${combo.name} | ${combo.agp} | ${combo.gradle} | ${combo.java} | ${combo.kotlin} | ${statusIcon} ${statusText} |\n`;
});
// Add summary
const totalTests = matrix.length;
const passedTests = Object.values(testResults).filter(r => r.conclusion === 'success').length;
const failedTests = Object.values(testResults).filter(r => r.conclusion === 'failure').length;
comment += `\n### Summary\n`;
comment += `- **Total**: ${totalTests} combinations\n`;
comment += `- **Passed**: ✅ ${passedTests}\n`;
comment += `- **Failed**: ❌ ${failedTests}\n`;
if (failedTests > 0) {
comment += `\n⚠️ **Some tests failed.** Please check the workflow logs for details.\n`;
} else if (passedTests === totalTests) {
comment += `\n🎉 **All tests passed!**\n`;
}
comment += `\n**View full results**: [Workflow Run](${context.payload.repository.html_url}/actions/runs/${context.runId})\n`;
return comment;
- name: Comment on PR
uses: actions/github-script@v7
with:
script: |
const comment = ${{ steps.generate-comment.outputs.result }};
// Find existing comment to update
const { data: comments } = await github.rest.issues.listComments({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
});
const botComment = comments.find(c =>
c.user.type === 'Bot' &&
c.body.includes('🤖 Compatibility Matrix Test Results')
);
if (botComment) {
// Update existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: botComment.id,
body: comment
});
} else {
// Create new comment
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
}