-
Notifications
You must be signed in to change notification settings - Fork 0
183 lines (150 loc) · 5.07 KB
/
coverage-optimization.yml
File metadata and controls
183 lines (150 loc) · 5.07 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
name: Coverage Optimization
on:
push:
branches:
- main
- develop
paths:
- 'src/**'
- 'tests/**'
- '.github/workflows/**'
pull_request:
branches:
- main
- develop
jobs:
coverage:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
coverage-type: ['statement', 'branch', 'function', 'line']
steps:
- uses: actions/checkout@v3
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
pip install coverage pytest-cov
- name: Run coverage
run: |
coverage run -m pytest --cov=src/backend --cov-report=xml --cov-report=term-missing
coverage xml
coverage html
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
optimization:
needs: coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download coverage
uses: actions/download-artifact@v3
with:
name: coverage-reports
path: coverage-reports
- name: Analyze coverage
run: |
python -c """
import json
import xml.etree.ElementTree as ET
from pathlib import Path
# カバレッジレポートの解析
coverage = {}
for file in Path('coverage-reports').glob('*.xml'):
tree = ET.parse(file)
root = tree.getroot()
for package in root.findall('.//package'):
name = package.get('name')
lines = package.find('lines').findall('line')
for line in lines:
number = int(line.get('number'))
hits = int(line.get('hits'))
if name not in coverage:
coverage[name] = {}
coverage[name][number] = {
'hits': hits,
'branch': line.get('branch') == 'true'
}
# カバレッジ最適化の分析
optimization = {
'missing_lines': [],
'branch_coverage': [],
'recommendations': []
}
for file, lines in coverage.items():
for line, data in lines.items():
if data['hits'] == 0:
optimization['missing_lines'].append({
'file': file,
'line': line
})
if data['branch']:
optimization['branch_coverage'].append({
'file': file,
'line': line,
'hits': data['hits']
})
# 最適化の推奨事項
if optimization['missing_lines']:
optimization['recommendations'].append(
f"Add tests for {len(optimization['missing_lines'])} missing lines"
)
if optimization['branch_coverage']:
optimization['recommendations'].append(
f"Improve branch coverage for {len(optimization['branch_coverage'])} branches"
)
# 結果の保存
with open('coverage-optimization.json', 'w') as f:
json.dump(optimization, f, indent=2)
"""
- name: Upload optimization results
uses: actions/upload-artifact@v3
with:
name: coverage-optimization
path: coverage-optimization.json
report:
needs: optimization
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download optimization results
uses: actions/download-artifact@v3
with:
name: coverage-optimization
path: coverage-optimization
- name: Generate report
run: |
python -c """
import json
from datetime import datetime
# カバレッジ最適化レポートの生成
with open('coverage-optimization/coverage-optimization.json') as f:
optimization = json.load(f)
with open('coverage-optimization-report.md', 'w') as f:
f.write('# Coverage Optimization Report\n\n')
f.write(f'Generated at: {datetime.now().isoformat()}\n\n')
f.write('## Missing Lines\n\n')
for line in optimization['missing_lines']:
f.write(f"- {line['file']}:{line['line']}\n")
f.write('\n## Branch Coverage\n\n')
for branch in optimization['branch_coverage']:
f.write(f"- {branch['file']}:{branch['line']} (hits: {branch['hits']})\n")
f.write('\n## Recommendations\n\n')
for rec in optimization['recommendations']:
f.write(f"- {rec}\n")
"""
- name: Upload report
uses: actions/upload-artifact@v3
with:
name: coverage-report
path: coverage-optimization-report.md