forked from OpenHands/OpenHands-CLI
-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (158 loc) · 5.81 KB
/
Copy pathtests.yml
File metadata and controls
185 lines (158 loc) · 5.81 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
---
# Workflow that runs Python unit tests and snapshot tests with pytest
name: Tests
on:
push:
branches: [main]
pull_request:
branches: ['**']
permissions:
contents: read
pull-requests: write
concurrency:
group: ${{ github.workflow }}-${{ (github.head_ref && github.ref) || github.run_id }}
cancel-in-progress: true
jobs:
test-unit:
name: Run unit tests (pytest)
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: latest
- name: Install dependencies
run: |
uv sync --group dev
- name: Run unit tests with coverage (excluding snapshots)
run: |
# Clean up any existing coverage file
rm -f .coverage
uv run pytest -v \
--ignore=tests/snapshots \
--cov=openhands_cli \
--cov-report=term-missing \
--cov-fail-under=0 \
--cov-config=pyproject.toml
# Verify coverage data file exists
if [ -f .coverage ]; then
echo "Coverage data file created successfully"
ls -la .coverage
else
echo "ERROR: Coverage data file not created"
exit 1
fi
- name: Prepare coverage file for upload
if: always()
run: |
echo "Current directory: $(pwd)"
echo "Files in current directory:"
ls -la
echo "Looking for .coverage file:"
find . -name ".coverage" -type f -exec ls -la {} \;
# Copy coverage file to ensure it's accessible
if [ -f .coverage ]; then
cp .coverage coverage-data.db
echo "Copied .coverage to coverage-data.db"
ls -la coverage-data.db
else
echo "ERROR: .coverage file not found for upload"
exit 1
fi
- name: Upload coverage data
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-data
path: coverage-data.db
if-no-files-found: error
test-snapshots:
name: Run snapshot tests
runs-on: ubuntu-24.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: latest
- name: Install dependencies
run: |
uv sync --group dev
- name: Run snapshot tests
run: |
uv run pytest tests/snapshots -v
- name: Upload snapshot report on failure
if: failure()
uses: actions/upload-artifact@v4
with:
name: snapshot-report
path: snapshot_report.html
if-no-files-found: ignore
coverage-report:
name: Generate coverage report
runs-on: ubuntu-24.04
needs: [test-unit]
if: always() && github.event_name == 'pull_request'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
version: latest
- name: Install dependencies (for coverage CLI)
run: |
uv sync --group dev
- name: Download coverage data
uses: actions/download-artifact@v4
with:
name: coverage-data
continue-on-error: true
- name: Generate coverage report
run: |
# Check for downloaded coverage file and rename it
if [ -f coverage-data.db ]; then
echo "Downloaded coverage file found, renaming to .coverage..."
mv coverage-data.db .coverage
ls -la .coverage
elif [ -f .coverage ]; then
echo "Coverage file already exists..."
else
echo "No coverage file found; skipping report generation."
exit 0
fi
echo "Generating coverage report..."
uv run coverage xml -i -o coverage.xml
uv run coverage report -m
- name: Post coverage comment to PR
if: always()
continue-on-error: true
uses: MishaKav/pytest-coverage-comment@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
pytest-xml-coverage-path: coverage.xml
title: Coverage Report
create-new-comment: false
hide-report: false
report-only-changed-files: true
remove-links-to-files: true
remove-links-to-lines: true