-
Notifications
You must be signed in to change notification settings - Fork 3
260 lines (217 loc) · 8.4 KB
/
test.yml
File metadata and controls
260 lines (217 loc) · 8.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
name: Test & Coverage
on:
pull_request: # Triggers on ALL pull requests to satisfy branch protection
workflow_dispatch:
permissions:
contents: read
checks: write
pull-requests: write
jobs:
# This job always runs to satisfy branch protection requirements
status-check:
name: Status Check
runs-on: ubuntu-latest
outputs:
should-test: ${{ steps.check-paths.outputs.should-test }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Need full history to check changed files
- name: Check if tests should run
id: check-paths
run: |
# For release-please PRs, skip tests
if [[ "${{ github.head_ref }}" == release-please--branches--* ]]; then
echo "should-test=false" >> $GITHUB_OUTPUT
echo "Skipping tests for release-please PR"
exit 0
fi
# Get list of changed files
echo "Checking changed files between origin/${{ github.base_ref }} and HEAD"
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD || echo "")
# Check if any test-relevant files changed
TEST_PATTERNS="scripts/ tests/ pyproject.toml \\.github/workflows/test\\.yml"
SHOULD_TEST=false
for pattern in $TEST_PATTERNS; do
if echo "$CHANGED_FILES" | grep -q "^$pattern"; then
SHOULD_TEST=true
echo "Found changes in $pattern - tests will run"
break
fi
done
echo "should-test=$SHOULD_TEST" >> $GITHUB_OUTPUT
if [ "$SHOULD_TEST" = "false" ]; then
echo "No test-relevant files changed. Tests will be skipped."
echo "Changed files:"
echo "$CHANGED_FILES"
fi
- name: Status summary
run: |
echo "## Test Status Check" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [[ "${{ steps.check-paths.outputs.should-test }}" == "true" ]]; then
echo "✅ Test-relevant files changed - full test suite will run" >> $GITHUB_STEP_SUMMARY
else
echo "ℹ️ No test-relevant files changed - tests skipped" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "This satisfies branch protection requirements without running unnecessary tests." >> $GITHUB_STEP_SUMMARY
fi
test:
name: Test Python on ${{ matrix.os }}
needs: status-check
if: needs.status-check.outputs.should-test == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
enable-cache: true
cache-dependency-glob: "pyproject.toml"
- name: Install dependencies
run: uv sync --all-extras --dev
- name: Run pytest with coverage
run: uv run pytest -v --cov=scripts --cov-report=term-missing --cov-report=xml --cov-report=html --junit-xml=test-results.xml tests/
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}
path: test-results.xml
- name: Upload coverage reports
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: |
coverage.xml
htmlcov/
- name: Surface test results
if: always()
uses: pmeier/pytest-results-action@main
with:
path: test-results.xml
summary: true
display-options: fEX
fail-on-empty: true
- name: Coverage comment
if: github.event_name == 'pull_request' && matrix.os == 'ubuntu-latest'
uses: py-cov-action/python-coverage-comment-action@v3
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
MINIMUM_GREEN: 80
MINIMUM_ORANGE: 60
test-validation:
name: Test Environment Validation
needs: status-check
if: needs.status-check.outputs.should-test == 'true'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install dependencies
run: uv sync
- name: Validate all environment configs
run: |
uv run python scripts/validate_environment_config.py environments/library/
- name: Test entity counting
run: |
uv run python scripts/count_entities.py
test-install-scripts:
name: Test Install Scripts
needs: status-check
if: needs.status-check.outputs.should-test == 'true'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: pyproject.toml
- name: Install uv
uses: astral-sh/setup-uv@v4
- name: Install dependencies
run: uv sync
- name: Test setup_environment.py imports
run: |
uv run python -c "import sys; sys.path.insert(0, 'scripts'); import setup_environment"
- name: Test install_claude.py imports
run: |
uv run python -c "import sys; sys.path.insert(0, 'scripts'); import install_claude"
- name: Test setup with dry run (Unix)
if: runner.os != 'Windows'
run: |
uv run python scripts/setup_environment.py python --skip-install || true
- name: Test setup with dry run (Windows)
if: runner.os == 'Windows'
run: |
uv run python scripts/setup_environment.py python --skip-install
continue-on-error: true
# Summary for when tests are skipped
summary-skip:
name: Test Summary (Skipped)
runs-on: ubuntu-latest
needs: [status-check]
if: needs.status-check.outputs.should-test != 'true'
steps:
- name: Summary
run: |
echo "## Test Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "ℹ️ Tests were skipped for this PR" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Reason" >> $GITHUB_STEP_SUMMARY
if [[ "${{ github.head_ref }}" == release-please--branches--* ]]; then
echo "This is a release-please PR - tests are not required" >> $GITHUB_STEP_SUMMARY
else
echo "No test-relevant files were modified in this PR" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Test-relevant paths:" >> $GITHUB_STEP_SUMMARY
echo "- \`scripts/**\`" >> $GITHUB_STEP_SUMMARY
echo "- \`tests/**\`" >> $GITHUB_STEP_SUMMARY
echo "- \`pyproject.toml\`" >> $GITHUB_STEP_SUMMARY
echo "- \`.github/workflows/test.yml\`" >> $GITHUB_STEP_SUMMARY
fi
# Summary for when tests run
summary-run:
name: Test Summary
runs-on: ubuntu-latest
needs: [status-check, test, test-validation, test-install-scripts]
if: needs.status-check.outputs.should-test == 'true'
steps:
- name: Summary
run: |
echo "## Test Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "✅ All tests completed successfully!" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Test Matrix" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Ubuntu + Python 3.12" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Windows + Python 3.12" >> $GITHUB_STEP_SUMMARY
echo "- ✅ macOS + Python 3.12" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Validation Tests" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Environment configurations validated" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Entity counting tested" >> $GITHUB_STEP_SUMMARY
echo "- ✅ Install scripts tested" >> $GITHUB_STEP_SUMMARY