-
Notifications
You must be signed in to change notification settings - Fork 1
97 lines (83 loc) · 2.61 KB
/
ci.yml
File metadata and controls
97 lines (83 loc) · 2.61 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: write
jobs:
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
go-version: ['1.22', '1.23', '1.24', '1.25', '1.26']
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Build
run: go build ./...
- name: Test
run: go test -v -race -count=1 ./...
coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
- name: Test with coverage
run: |
go test -coverprofile=coverage.out -covermode=atomic ./...
COVERAGE=$(go tool cover -func=coverage.out | grep total | awk '{print $3}' | tr -d '%')
echo "COVERAGE=$COVERAGE" >> "$GITHUB_ENV"
echo "Coverage: $COVERAGE%"
- name: Generate coverage badge
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
COV=${{ env.COVERAGE }}
# Pick color based on coverage
if (( $(echo "$COV >= 90" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$COV >= 80" | bc -l) )); then
COLOR="green"
elif (( $(echo "$COV >= 70" | bc -l) )); then
COLOR="yellowgreen"
elif (( $(echo "$COV >= 60" | bc -l) )); then
COLOR="yellow"
else
COLOR="red"
fi
# Download badge SVG from shields.io
curl -s "https://img.shields.io/badge/coverage-${COV}%25-${COLOR}" -o coverage-badge.svg
- name: Push badge to badges branch
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create or update the badges branch
git checkout --orphan badges-tmp
git rm -rf .
mv coverage-badge.svg .
git add coverage-badge.svg
git commit -m "Update coverage badge: ${{ env.COVERAGE }}%"
git push origin HEAD:badges --force
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.26'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest