-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscheduled-integration-tests.yml
More file actions
154 lines (133 loc) · 5.22 KB
/
scheduled-integration-tests.yml
File metadata and controls
154 lines (133 loc) · 5.22 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
name: Scheduled Integration Tests
on:
schedule:
# Run every day at 2 AM UTC
- cron: '0 2 * * *'
workflow_dispatch: # Allow manual triggering
jobs:
scheduled-integration-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'pip'
- name: Install dependencies
run: |
pip install ".[dev]"
- name: Run all integration tests
if: secrets.NUTRIENT_API_KEY != ''
env:
NUTRIENT_API_KEY: ${{ secrets.NUTRIENT_API_KEY }}
run: |
echo "Running scheduled integration tests to detect API changes..."
python -m pytest tests/test_integration.py -v --tb=short
timeout-minutes: 20
continue-on-error: true
id: test-run
- name: Skip scheduled tests (no API key)
if: secrets.NUTRIENT_API_KEY == ''
run: |
echo "⏭️ Skipping scheduled integration tests - NUTRIENT_API_KEY not available"
echo "Configure NUTRIENT_API_KEY secret to enable scheduled API validation"
- name: Generate detailed test report
if: always()
run: |
python -m pytest tests/test_integration.py -v --tb=short --junit-xml=scheduled-test-results.xml || true
# Create summary
echo "## Integration Test Summary" > test-summary.md
echo "Date: $(date)" >> test-summary.md
echo "Status: ${{ steps.test-run.outcome }}" >> test-summary.md
# Extract test counts if possible
if [ -f scheduled-test-results.xml ]; then
echo "### Test Results" >> test-summary.md
python -c "
import xml.etree.ElementTree as ET
import os
if os.path.exists('scheduled-test-results.xml'):
tree = ET.parse('scheduled-test-results.xml')
root = tree.getroot()
tests = root.get('tests', '0')
failures = root.get('failures', '0')
errors = root.get('errors', '0')
skipped = root.get('skipped', '0')
passed = str(int(tests) - int(failures) - int(errors) - int(skipped))
print(f'- Total Tests: {tests}')
print(f'- Passed: {passed}')
print(f'- Failed: {failures}')
print(f'- Errors: {errors}')
print(f'- Skipped: {skipped}')
" >> test-summary.md
fi
- name: Create issue if tests fail
if: failure() && steps.test-run.outcome == 'failure'
uses: actions/github-script@v7
with:
script: |
const date = new Date().toISOString().split('T')[0];
const title = `🚨 Integration Tests Failed - ${date}`;
// Check if issue already exists
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['integration-failure', 'automated'],
state: 'open'
});
const existingIssue = issues.data.find(issue => issue.title.includes(date));
if (!existingIssue) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: `## Scheduled Integration tests failed
The scheduled integration test run has detected failures. This could indicate:
- API changes that need to be addressed
- Service degradation
- Test flakiness
### Action Required
1. Check the [workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) for details
2. Investigate any API changes
3. Update tests if needed
4. Close this issue once resolved
### Test Summary
See the workflow artifacts for detailed test results.`,
labels: ['integration-failure', 'automated', 'high-priority']
});
}
- name: Upload test artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: scheduled-integration-results-${{ github.run_number }}
path: |
scheduled-test-results.xml
test-summary.md
retention-days: 30
- name: Notify on success after previous failure
if: success() && steps.test-run.outcome == 'success'
uses: actions/github-script@v7
with:
script: |
// Close any open integration failure issues
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['integration-failure', 'automated'],
state: 'open'
});
for (const issue of issues.data) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed'
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body: '✅ **Resolved**: Integration tests are now passing.'
});
}