-
Notifications
You must be signed in to change notification settings - Fork 1
131 lines (109 loc) · 4.06 KB
/
checks.yaml
File metadata and controls
131 lines (109 loc) · 4.06 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
name: "Checks"
on:
pull_request:
branches: [ main, next, development ]
types: [ opened, synchronize, reopened ]
jobs:
lint-dart:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Flutter
uses: flutter-actions/setup-flutter@v4
with:
channel: stable
version: 3.38.8
cache: true
cache-sdk: true
cache-key: ${{ runner.os }}-flutter-${{ hashFiles('pubspec.yaml') }}
- name: Install dependencies
run: flutter pub get
- name: Run analyze
run: flutter analyze
- name: Run tests
run: flutter test --machine --coverage > test-results.json
- name: Publish test results
uses: dorny/test-reporter@v1
if: always()
with:
name: Unit Tests
path: test-results.json
reporter: flutter-json
- name: Upload coverage
uses: actions/upload-artifact@v4
if: always()
with:
name: flutter-coverage
path: coverage/lcov.info
retention-days: 1
coverage-comment:
runs-on: ubuntu-latest
needs: lint-dart
if: always() && github.event_name == 'pull_request'
steps:
- name: Download coverage
uses: actions/download-artifact@v4
with:
name: flutter-coverage
path: coverage
continue-on-error: true
- name: Parse coverage
id: coverage
run: |
if [ -f coverage/lcov.info ]; then
# Use lcov to get summary (more reliable than grep)
COVERAGE_SUMMARY=$(lcov --summary coverage/lcov.info 2>&1)
# Extract line coverage percentage
COVERAGE_PCT=$(echo "$COVERAGE_SUMMARY" | grep -oP 'lines\.*: \K[\d.]+(?=%)')
COVERAGE_PCT=${COVERAGE_PCT:-0.0}
# Extract hit/total counts
LINES_HIT=$(grep -o 'DA:' coverage/lcov.info | wc -l)
LINES_TOTAL=$(grep -o 'LF:' coverage/lcov.info | wc -l)
echo "coverage_pct=$COVERAGE_PCT" >> $GITHUB_OUTPUT
echo "lines_hit=$LINES_HIT" >> $GITHUB_OUTPUT
echo "lines_total=$LINES_TOTAL" >> $GITHUB_OUTPUT
else
echo "coverage_pct=0.0" >> $GITHUB_OUTPUT
echo "lines_hit=0" >> $GITHUB_OUTPUT
echo "lines_total=0" >> $GITHUB_OUTPUT
fi
- name: Post coverage comment
uses: actions/github-script@v7
with:
script: |
const coveragePct = '${{ steps.coverage.outputs.coverage_pct }}';
const linesHit = '${{ steps.coverage.outputs.lines_hit }}';
const linesTotal = '${{ steps.coverage.outputs.lines_total }}';
const linesMissing = parseInt(linesTotal) - parseInt(linesHit);
const body = `## 📊 Coverage Report
| Metric | Value |
|--------|-------|
| **Coverage** | **${coveragePct}%** |
| Lines covered | ${linesHit} / ${linesTotal} |
| Lines missing | ${linesMissing} |
<sub>🤖 Coverage report from [checks workflow](${context.payload.repository.html_url}/actions/runs/${context.runId})</sub>`;
// Find existing comment
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
const existing = comments.find(c =>
c.user.type === 'Bot' && c.body.includes('## 📊 Coverage Report')
);
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body,
});
}