forked from bep/debounce
-
Notifications
You must be signed in to change notification settings - Fork 0
249 lines (207 loc) · 6.13 KB
/
ci.yaml
File metadata and controls
249 lines (207 loc) · 6.13 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
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
defaults:
run:
working-directory: ${{ matrix.path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.24
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ubuntu-latest-go-1.24-${{ hashFiles(format('{0}/go.sum', matrix.path)) }}
restore-keys: |
ubuntu-latest-go-1.24-
- name: Download dependencies
run: go mod download
- name: Verify dependencies
run: go mod verify
- name: Run go vet
run: go vet ./...
- name: Run go fmt
shell: bash
run: |
unformatted=$(gofmt -s -l .)
if [ -n "$unformatted" ]; then
echo "The following files are not formatted:"
echo "$unformatted"
exit 1
fi
- name: Run tests
run: go test -v -race ./...
benchmark:
name: Benchmark
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
defaults:
run:
working-directory: ${{ matrix.path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ubuntu-latest-go-1.24-${{ hashFiles(format('{0}/go.sum', matrix.path)) }}
restore-keys: |
ubunsu-latest-go-1.24-
- name: Download dependencies
run: go mod download
- name: Run benchmarks
run: go test -bench=. -benchmem -run=^$ ./...
coverage:
name: Coverage Check
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ubuntu-latest-go-1.24-${{ hashFiles(format('{0}/go.sum', matrix.path)) }}
restore-keys: |
ubuntu-latest-go-1.24-
- name: Download dependencies
working-directory: ${{ matrix.path }}
run: go mod download
- name: Run tests with coverage
working-directory: ${{ matrix.path }}
run: go test -coverprofile=coverage.out ./...
- name: Calculate coverage
working-directory: ${{ matrix.path }}
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
echo "Coverage: $COVERAGE%"
echo "COVERAGE=$COVERAGE" >> $GITHUB_ENV
- name: Check coverage threshold
run: |
THRESHOLD=80
if (( $(echo "$COVERAGE < $THRESHOLD" | bc -l) )); then
echo "Coverage $COVERAGE% is below threshold $THRESHOLD%"
exit 1
else
echo "Coverage $COVERAGE% meets threshold $THRESHOLD%"
fi
- name: Generate coverage report
working-directory: ${{ matrix.path }}
run: go tool cover -html=coverage.out -o coverage.html
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report-${{ matrix.module }}
path: |
${{ matrix.path }}/coverage.out
${{ matrix.path }}/coverage.html
- name: Go Coverage Badge # Pass the `coverage.out` output to this action
if: matrix.module == 'v2'
uses: tj-actions/coverage-badge-go@v2
with:
value: $COVERAGE
- name: Verify Changed files
if: matrix.module == 'v2'
uses: tj-actions/verify-changed-files@v16
id: verify-changed-files
with:
files: README.md
- name: Commit and push changes
if: matrix.module == 'v2' && steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "chore: Updated coverage badge."
git push
- name: Add coverage to PR comment
working-directory: ${{ matrix.path }}
if: github.event_name == 'pull_request'
run: |
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print substr($3, 1, length($3)-1)}')
echo "## 📊 ${{matrix.module}} Coverage Report" > coverage_comment.md
echo "" >> coverage_comment.md
echo "**Total Coverage: $COVERAGE%**" >> coverage_comment.md
echo "" >> coverage_comment.md
echo "### Coverage Details" >> coverage_comment.md
echo '```' >> coverage_comment.md
go tool cover -func=coverage.out >> coverage_comment.md
echo '```' >> coverage_comment.md
# Create or update PR comment
gh pr comment ${{ github.event.number }} --body-file coverage_comment.md || \
gh pr comment ${{ github.event.number }} --body "$(cat coverage_comment.md)"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
lint:
name: Lint
runs-on: ubuntu-latest
strategy:
matrix:
include:
- module: v1
path: .
- module: v2
path: v2
defaults:
run:
working-directory: ${{ matrix.path }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.24'
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=5m