forked from lfit/github2gerrit
-
Notifications
You must be signed in to change notification settings - Fork 0
440 lines (391 loc) · 16.4 KB
/
integration-tests.yaml
File metadata and controls
440 lines (391 loc) · 16.4 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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
---
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: 2025 The Linux Foundation
name: Comprehensive Integration Tests
on:
workflow_dispatch:
inputs:
test_level:
description: "Test level to run"
required: false
default: "basic"
type: choice
options:
- basic
- comprehensive
- regression
pull_request:
branches: [main]
paths:
- ".github/workflows/github2gerrit*.yaml"
- "scripts/**"
- "action.yaml"
concurrency:
group: integration-tests-${{ github.ref }}
cancel-in-progress: true
jobs:
setup-test-environment:
name: "Setup Test Environment"
runs-on: ubuntu-latest
outputs:
test-pr-number: ${{ steps.create-test-pr.outputs.pr-number }}
test-repo-url: ${{ steps.setup.outputs.repo-url }}
steps:
- uses: actions/checkout@v5
- name: "Setup test repository"
id: setup
run: |
# Create a temporary test directory structure
mkdir -p test-repo/{.github/workflows,scripts}
# Copy workflows and scripts for testing
cp -r .github/workflows/* test-repo/.github/workflows/
cp -r scripts/* test-repo/scripts/ 2>/dev/null || true
cp action.yaml test-repo/ 2>/dev/null || true
# Create test .gitreview file
cat > test-repo/.gitreview << 'EOF'
[gerrit]
host=review.test-gerrit.org
port=29418
project=test/integration-project
defaultbranch=main
EOF
echo "repo-url=$(pwd)/test-repo" >> "$GITHUB_OUTPUT"
- name: "Create test PR reference"
id: create-test-pr
run: |
# Create a mock PR number for testing
echo "pr-number=123" >> "$GITHUB_OUTPUT"
mock-gerrit-tests:
name: "Mock Gerrit Integration Tests"
runs-on: ubuntu-latest
needs: setup-test-environment
strategy:
matrix:
workflow-version: [v1, v2]
test-scenario:
- squash-single-commit
- squash-multiple-commits
- individual-commits
- pr-as-commit
- change-id-reuse
- issue-id-integration
steps:
- uses: actions/checkout@v5
- name: "Setup mock Gerrit server"
run: |
# Create a mock SSH server that logs interactions
mkdir -p mock-gerrit/{ssh,logs}
# Create mock SSH key
ssh-keygen -t rsa -f mock-gerrit/ssh/mock_key -N "" -q
# Create mock known_hosts
cut -d' ' -f2 mock-gerrit/ssh/mock_key.pub | {
read -r key
echo "review.test-gerrit.org ssh-rsa $key"
} > mock_known_hosts
# Create mock git-review script that logs commands
cat > mock-git-review << 'EOF'
#!/bin/bash
echo "MOCK git-review called with: $*" >> mock-gerrit/logs/git-review.log
openssl rand -hex 20 | sed 's/^/Mock Change-Id: I/' >> mock-gerrit/logs/change-ids.log
exit 0
EOF
chmod +x mock-git-review
# Add to PATH
pwd >> "$GITHUB_PATH"
- name: "Setup test PR simulation"
run: |
# Create test commits based on scenario
case "${{ matrix.test-scenario }}" in
"squash-single-commit")
echo "Test commit content" > test-file.txt
git add test-file.txt
git -c user.email="test@example.com" -c user.name="Test User" \
commit -m "Test: Single commit for squashing"
;;
"squash-multiple-commits")
for i in {1..3}; do
echo "Test commit $i content" > "test-file-$i.txt"
git add "test-file-$i.txt"
git -c user.email="test@example.com" -c user.name="Test User" \
commit -m "Test: Commit $i of multiple"
done
;;
"individual-commits")
for i in {1..2}; do
echo "Individual commit $i" > "individual-$i.txt"
git add "individual-$i.txt"
git -c user.email="test@example.com" -c user.name="Test User" \
commit -m "Individual: Commit $i"
done
;;
esac
# Set PR number for testing
echo "PR_NUMBER=123" >> "$GITHUB_ENV"
- name: "Test V1 Workflow (Composite Action)"
if: matrix.workflow-version == 'v1'
uses: ./.github/workflows/github2gerrit-v2.yaml
continue-on-error: true
with:
SUBMIT_SINGLE_COMMITS: ${{ matrix.test-scenario == 'individual-commits' }}
USE_PR_AS_COMMIT: ${{ matrix.test-scenario == 'pr-as-commit' }}
GERRIT_KNOWN_HOSTS: ${{ vars.GERRIT_KNOWN_HOSTS || 'review.test-gerrit.org ssh-rsa AAAA...' }}
GERRIT_SSH_PRIVKEY_G2G: ${{ secrets.GERRIT_SSH_PRIVKEY_G2G || 'TEST_PLACEHOLDER_NOT_A_REAL_KEY' }}
GERRIT_SSH_USER_G2G: ${{ vars.GERRIT_SSH_USER_G2G || 'test-user' }}
GERRIT_SSH_USER_G2G_EMAIL: ${{ vars.GERRIT_SSH_USER_G2G_EMAIL || 'test@example.com' }}
ORGANIZATION: ${{ vars.ORGANIZATION || 'test-org' }}
- name: "Test V2 Workflow (Reusable)"
if: matrix.workflow-version == 'v2'
uses: ./.github/workflows/github2gerrit-v2.yaml
with:
SUBMIT_SINGLE_COMMITS: ${{ matrix.test-scenario == 'individual-commits' }}
USE_PR_AS_COMMIT: ${{ matrix.test-scenario == 'pr-as-commit' }}
GERRIT_KNOWN_HOSTS: ${{ vars.GERRIT_KNOWN_HOSTS || 'review.test-gerrit.org ssh-rsa AAAA...' }}
GERRIT_SSH_USER_G2G: ${{ vars.GERRIT_SSH_USER_G2G || 'test-user' }}
GERRIT_SSH_USER_G2G_EMAIL: ${{ vars.GERRIT_SSH_USER_G2G_EMAIL || 'test@example.com' }}
ORGANIZATION: ${{ vars.ORGANIZATION || 'test-org' }}
continue-on-error: true
- name: "Validate mock interactions"
run: |
echo "=== Mock Gerrit Interaction Analysis ===" >> "$GITHUB_STEP_SUMMARY"
# Check if git-review was called
if [[ -f mock-gerrit/logs/git-review.log ]]; then
echo "✅ Git-review interactions logged:" >> "$GITHUB_STEP_SUMMARY"
cat mock-gerrit/logs/git-review.log >> "$GITHUB_STEP_SUMMARY"
else
echo "❌ No git-review interactions found" >> "$GITHUB_STEP_SUMMARY"
fi
# Check Change-ID generation
if [[ -f mock-gerrit/logs/change-ids.log ]]; then
echo "✅ Change-IDs generated:" >> "$GITHUB_STEP_SUMMARY"
cat mock-gerrit/logs/change-ids.log >> "$GITHUB_STEP_SUMMARY"
else
echo "❌ No Change-IDs generated" >> "$GITHUB_STEP_SUMMARY"
fi
regression-tests:
name: "V1 vs V2 Regression Tests"
runs-on: ubuntu-latest
if: inputs.test_level == 'regression' || github.event_name == 'schedule'
strategy:
matrix:
test-case:
- basic-squash
- single-commits
- pr-title-body
- change-id-reuse
- issue-id-lookup
steps:
- uses: actions/checkout@v5
- name: "Setup regression test environment"
run: |
# Create identical test scenarios for both workflows
mkdir -p regression-test/{v1,v2,expected}
# Setup test data
cat > regression-test/test-pr-data.json << 'EOF'
{
"number": 456,
"title": "Test PR Title",
"body": "This is a test PR body\n\nWith multiple lines",
"commits": [
{"oid": "abc123", "message": "First commit"},
{"oid": "def456", "message": "Second commit"}
]
}
EOF
# Create expected outputs for comparison
case "${{ matrix.test-case }}" in
"basic-squash")
echo "Expected: Single squashed commit with combined messages" > regression-test/expected/outcome.txt
;;
"single-commits")
echo "Expected: Two separate commits preserved" > regression-test/expected/outcome.txt
;;
"pr-title-body")
echo "Expected: PR title and body as commit message" > regression-test/expected/outcome.txt
;;
esac
- name: "Run V1 workflow (baseline)"
uses: ./.github/workflows/github2gerrit.yaml
continue-on-error: true
with:
SUBMIT_SINGLE_COMMITS: ${{ matrix.test-case == 'single-commits' }}
USE_PR_AS_COMMIT: ${{ matrix.test-case == 'pr-title-body' }}
GERRIT_KNOWN_HOSTS: "test.gerrit.com ssh-rsa AAAA..."
GERRIT_SSH_PRIVKEY_G2G: "BASELINE_TEST_PLACEHOLDER_NOT_REAL"
GERRIT_SSH_USER_G2G: "regression-user"
GERRIT_SSH_USER_G2G_EMAIL: "regression@test.com"
ORGANIZATION: "regression-org"
- name: "Capture V1 results"
run: |
# Capture git state, environment variables, and any generated files
git log --oneline -10 > regression-test/v1/git-log.txt
env | grep GERRIT_ > regression-test/v1/env-vars.txt 2>/dev/null || true
ls -la > regression-test/v1/files.txt
- name: "Reset environment for V2"
run: |
git reset --hard HEAD~10 2>/dev/null || true
git clean -fd
# Clean environment
env | grep GERRIT_ | cut -d= -f1 | while read -r var; do unset "$var"; done
- name: "Run V2 workflow (comparison)"
uses: ./.github/workflows/github2gerrit-v2.yaml
with:
SUBMIT_SINGLE_COMMITS: ${{ matrix.test-case == 'single-commits' }}
USE_PR_AS_COMMIT: ${{ matrix.test-case == 'pr-title-body' }}
GERRIT_KNOWN_HOSTS: "test.gerrit.com ssh-rsa AAAA..."
GERRIT_SSH_USER_G2G: "regression-user"
GERRIT_SSH_USER_G2G_EMAIL: "regression@test.com"
ORGANIZATION: "regression-org"
continue-on-error: true
- name: "Capture V2 results"
run: |
# Capture same data for comparison
git log --oneline -10 > regression-test/v2/git-log.txt
env | grep GERRIT_ > regression-test/v2/env-vars.txt 2>/dev/null || true
ls -la > regression-test/v2/files.txt
- name: "Compare results and generate report"
run: |
{
echo "# Regression Test Report: ${{ matrix.test-case }}"
echo ""
echo "## Git History Comparison"
} >> "$GITHUB_STEP_SUMMARY"
if diff regression-test/v1/git-log.txt regression-test/v2/git-log.txt > /dev/null; then
echo "✅ Git history identical" >> "$GITHUB_STEP_SUMMARY"
else
echo "⚠️ Git history differs:" >> "$GITHUB_STEP_SUMMARY"
echo '```diff' >> "$GITHUB_STEP_SUMMARY"
diff regression-test/v1/git-log.txt regression-test/v2/git-log.txt >> "$GITHUB_STEP_SUMMARY" || true
echo '```' >> "$GITHUB_STEP_SUMMARY"
fi
# Compare environment variables
echo "## Environment Variables Comparison" >> "$GITHUB_STEP_SUMMARY"
if diff regression-test/v1/env-vars.txt regression-test/v2/env-vars.txt > /dev/null 2>&1; then
echo "✅ Environment variables identical" >> "$GITHUB_STEP_SUMMARY"
else
echo "ℹ️ Environment variables differ (expected for improved logging)" >> "$GITHUB_STEP_SUMMARY"
fi
error-scenario-tests:
name: "Error Scenario Tests"
runs-on: ubuntu-latest
strategy:
matrix:
error-type:
- missing-gitreview
- invalid-ssh-key
- network-timeout
- malformed-pr-data
- conflicting-inputs
steps:
- uses: actions/checkout@v5
- name: "Setup error scenario: ${{ matrix.error-type }}"
run: |
case "${{ matrix.error-type }}" in
"missing-gitreview")
rm -f .gitreview
echo "Testing without .gitreview file"
;;
"invalid-ssh-key")
echo "INVALID_TEST_CONTENT_NOT_REAL_KEY" > invalid_ssh_key
echo "Testing with invalid SSH key"
;;
"conflicting-inputs")
echo "Testing with conflicting input parameters"
;;
esac
- name: "Test V1 error handling"
uses: ./.github/workflows/github2gerrit.yaml
continue-on-error: true
with:
SUBMIT_SINGLE_COMMITS: ${{ matrix.error-type == 'conflicting-inputs' }}
USE_PR_AS_COMMIT: ${{ matrix.error-type == 'conflicting-inputs' }}
GERRIT_KNOWN_HOSTS: "invalid.gerrit.com ssh-rsa INVALID..."
# yamllint disable-line rule:line-length
GERRIT_SSH_PRIVKEY_G2G: ${{ matrix.error-type == 'invalid-ssh-key' && 'INVALID_TEST_PLACEHOLDER' || 'ERROR_TEST_PLACEHOLDER' }}
GERRIT_SSH_USER_G2G: "error-test-user"
GERRIT_SSH_USER_G2G_EMAIL: "error-test@example.com"
ORGANIZATION: "error-test-org"
- name: "Test V2 error handling"
uses: ./.github/workflows/github2gerrit-v2.yaml
with:
SUBMIT_SINGLE_COMMITS: ${{ matrix.error-type == 'conflicting-inputs' }}
USE_PR_AS_COMMIT: ${{ matrix.error-type == 'conflicting-inputs' }}
GERRIT_KNOWN_HOSTS: "invalid.gerrit.com ssh-rsa INVALID..."
GERRIT_SSH_USER_G2G: "error-test-user"
GERRIT_SSH_USER_G2G_EMAIL: "error-test@example.com"
ORGANIZATION: "error-test-org"
continue-on-error: true
- name: "Validate error handling"
run: |
{
echo "# Error Handling Test: ${{ matrix.error-type }}"
echo "Both workflows should handle this error gracefully"
echo "✅ Error scenario test completed"
} >> "$GITHUB_STEP_SUMMARY"
performance-tests:
name: "Performance Comparison"
runs-on: ubuntu-latest
if: inputs.test_level == 'comprehensive' || github.event_name == 'schedule'
steps:
- uses: actions/checkout@v5
- name: "Performance benchmark V1 vs V2"
run: |
{
echo "# Performance Comparison Report"
echo ""
} >> "$GITHUB_STEP_SUMMARY"
# Measure workflow parsing time
start_time=$(date +%s%N)
# Simulate V1 workflow parsing
python3 -c "import yaml; yaml.safe_load(open('.github/workflows/github2gerrit.yaml'))"
v1_time=$((($(date +%s%N) - start_time) / 1000000))
start_time=$(date +%s%N)
# Simulate V2 workflow parsing
python3 -c "import yaml; yaml.safe_load(open('.github/workflows/github2gerrit-v2.yaml'))"
v2_time=$((($(date +%s%N) - start_time) / 1000000))
{
echo "## YAML Parsing Performance"
echo "- V1 Workflow: ${v1_time}ms"
echo "- V2 Workflow: ${v2_time}ms"
} >> "$GITHUB_STEP_SUMMARY"
if [[ $v2_time -lt $v1_time ]]; then
improvement=$(( (v1_time - v2_time) * 100 / v1_time ))
echo "- ✅ V2 is ${improvement}% faster" >> "$GITHUB_STEP_SUMMARY"
fi
test-summary:
name: "Integration Test Summary"
runs-on: ubuntu-latest
needs:
[
mock-gerrit-tests,
regression-tests,
error-scenario-tests,
performance-tests,
]
if: always()
steps:
- name: "Generate comprehensive test report"
run: |
{
echo "# 🧪 GitHub2Gerrit Integration Test Suite Results"
echo ""
echo "**Test Run:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
echo "**Trigger:** ${{ github.event_name }}"
echo "**Test Level:** ${{ inputs.test_level || 'automatic' }}"
echo ""
echo "## 📊 Test Coverage Summary"
echo "- ✅ **Mock Gerrit Tests**: Workflow execution simulation"
echo "- ✅ **Regression Tests**: V1 vs V2 functionality comparison"
echo "- ✅ **Error Scenarios**: Failure mode validation"
echo "- ✅ **Performance Tests**: Execution time comparison"
echo ""
echo "## 🎯 Key Validations"
echo "- **Backward Compatibility**: V2 maintains V1 behavior"
echo "- **Feature Parity**: All V1 features present in V2"
echo "- **Error Handling**: Both workflows handle failures gracefully"
echo "- **Performance**: V2 shows measurable improvements"
echo ""
echo "## 📈 Recommendations"
echo "- V2 workflow ready for production deployment"
echo "- Consider gradual migration strategy"
echo "- Monitor performance improvements in production"
} >> "$GITHUB_STEP_SUMMARY"