-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (121 loc) · 3.79 KB
/
Copy pathci.yml
File metadata and controls
130 lines (121 loc) · 3.79 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
contents: read
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
env:
GO_VERSION: "1.25"
jobs:
fmt:
name: gofmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: false
- name: gofmt -l
run: |
dirty=$(gofmt -l .)
if [ -n "$dirty" ]; then
echo "::error::gofmt produced changes — run 'make fmt' locally:"
echo "$dirty"
exit 1
fi
vet:
name: go vet
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: go vet (per module)
run: |
set -euo pipefail
while IFS= read -r m; do
dir=$(dirname "$m")
echo "::group::go vet $dir"
(cd "$dir" && go vet ./...)
echo "::endgroup::"
done < <(find . -name go.mod -not -path './*/vendor/*' | sort)
build:
name: go build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: go build (per module)
run: |
set -euo pipefail
while IFS= read -r m; do
dir=$(dirname "$m")
echo "::group::go build $dir"
(cd "$dir" && go build ./...)
echo "::endgroup::"
done < <(find . -name go.mod -not -path './*/vendor/*' | sort)
test:
name: go test -race
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: go test -race (per module, with coverage)
run: |
set -euo pipefail
mkdir -p coverage
while IFS= read -r m; do
dir=$(dirname "$m")
mod=$(basename "$dir")
echo "::group::go test -race $dir"
(cd "$dir" && go test -race -count=1 -coverprofile="$GITHUB_WORKSPACE/coverage/$mod.out" -covermode=atomic ./... || exit 1)
echo "::endgroup::"
done < <(find . -name go.mod -not -path './*/vendor/*' | sort)
- name: Aggregate coverage
run: |
echo "mode: atomic" > coverage/total.out
for f in coverage/*.out; do
[ "$f" = "coverage/total.out" ] && continue
tail -n +2 "$f" >> coverage/total.out 2>/dev/null || true
done
go tool cover -func=coverage/total.out | tail -1
- name: Upload coverage artifact
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage/
lint:
name: golangci-lint
runs-on: ubuntu-latest
needs: [fmt]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: golangci-lint (per module)
# We run the linter per-module because golangci-lint does not yet
# natively support Go workspaces — see https://github.com/golangci/golangci-lint/issues/2654.
# The module-by-module loop matches the build/test sweep above.
run: |
set -euo pipefail
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.7
while IFS= read -r m; do
dir=$(dirname "$m")
echo "::group::golangci-lint $dir"
(cd "$dir" && "$HOME/go/bin/golangci-lint" run --timeout=5m ./...) || exit 1
echo "::endgroup::"
done < <(find . -name go.mod -not -path './*/vendor/*' | sort)