-
Notifications
You must be signed in to change notification settings - Fork 107
193 lines (165 loc) · 6.91 KB
/
go.yml
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
name: Go
on:
push:
branches: [ master ]
pull_request:
schedule:
- cron: "0 0 * * *"
jobs:
build:
name: Build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: ['1.18', '1.19', '1.20', '1.x']
steps:
- name: Install protobuf
uses: arduino/setup-protoc@v1
with:
version: '3.x'
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go }}
id: go
- name: Install protoc-gen-go, goimports, Staticcheck
run: |
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install golang.org/x/tools/cmd/goimports@latest
- name: Check out code
uses: actions/checkout@v3
with:
path: go/src/github.com/openconfig/ygot
- name: Get dependencies
run: |
go get -v -t -d ./...
working-directory: go/src/github.com/openconfig/ygot
- name: Generate dependencies
run: make generate
working-directory: go/src/github.com/openconfig/ygot
- name: Build packages
run: go build -v ./...
working-directory: go/src/github.com/openconfig/ygot
- name: Run Tests
run: go test -v ./...
working-directory: go/src/github.com/openconfig/ygot
- name: Run race tests
run: go test -race -v ./...
working-directory: go/src/github.com/openconfig/ygot
- name: Check that Go integration test files compile
working-directory: go/src/github.com/openconfig/ygot
run: |
function test-go-build() {
cwd=$(pwd)
tmpdir=$(mktemp -d -p $cwd)
for f in "$@"; do
name=$(basename $f)
cp "$f" "$tmpdir"/"${name}.go"
done
cd $tmpdir
goimports -w *.go
go build
cd $cwd
rm -r $tmpdir
}
skipped=(
# fake ygot and ytype paths specified in generation options.
"openconfig-options-explicit.formatted-txt.go"
)
for f in gogen/testdata/schema/*.formatted-txt; do
if [[ ${skipped[@]} =~ $(basename $f) ]]; then
continue
fi
test-go-build $f
done
skipped=(
)
for f in gogen/testdata/structs/*.formatted-txt; do
if [[ ${skipped[@]} =~ $(basename $f) ]]; then
continue
fi
test-go-build $f
done
skipped=(
# GoStructs in a separate package, harder to set-up.
"openconfig-augmented.path-txt"
"openconfig-withlist-separate-package.path-txt"
)
for f in ypathgen/testdata/structs/*.path-txt; do
if [[ ${skipped[@]} =~ $(basename $f) ]]; then
continue
fi
filename=$(basename $f)
f_prefix="${filename%%.*}"
go_file="gogen/testdata/structs/${f_prefix}.formatted-txt"
test-go-build $f $go_file
done
- name: Make sure exampleoc doesn't error or panic
run: |
go install golang.org/x/tools/cmd/stringer@latest
go generate ./...
working-directory: go/src/github.com/openconfig/ygot
static_analysis:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.x'
id: go
- name: Install required static analysis tools
run: |
go install github.com/mattn/goveralls@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
- name: Check out ygot code
uses: actions/checkout@v3
- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Run coverage
run: |
pkgs="$(go list ./... | grep -v 'github.com/openconfig/ygot/exampleoc' | grep -v 'github.com/openconfig/ygot/uexampleoc' | grep -v 'github.com/openconfig/ygot/proto/' | grep -v 'github.com/openconfig/ygot/demo/' | grep -v 'github.com/openconfig/ygot/integration_tests' | grep -v 'github.com/openconfig/ygot/generator' | grep -v 'github.com/openconfig/ygot/gnmidiff/cmd' | tr '\n' ' ')"
for p in $pkgs; do
dir=$(echo $p | sed -e 's/^github\.com\/openconfig\/ygot\///')
go test -covermode count -coverprofile profile.coverprofile -outputdir $dir $p
done
# Overwrite results for gogen/protogen since they also cover ygen's
# and testutil's code.
go test -covermode count -coverprofile profile.coverprofile -outputdir gogen -coverpkg github.com/openconfig/ygot/gogen,github.com/openconfig/ygot/ygen,github.com/openconfig/ygot/testutil github.com/openconfig/ygot/gogen
go test -covermode count -coverprofile profile.coverprofile -outputdir protogen -coverpkg github.com/openconfig/ygot/protogen,github.com/openconfig/ygot/ygen,github.com/openconfig/ygot/testutil github.com/openconfig/ygot/protogen
# Also cover testutil,yreflect from util, ytypes and ygot packages
go test -covermode count -coverprofile profile.coverprofile -outputdir util -coverpkg github.com/openconfig/ygot/util,github.com/openconfig/ygot/testutil,github.com/openconfig/ygot/internal/yreflect github.com/openconfig/ygot/util
go test -covermode count -coverprofile profile.coverprofile -outputdir ygot -coverpkg github.com/openconfig/ygot/ygot,github.com/openconfig/ygot/testutil,github.com/openconfig/ygot/internal/yreflect github.com/openconfig/ygot/ygot
go test -covermode count -coverprofile profile.coverprofile -outputdir ytypes -coverpkg github.com/openconfig/ygot/ytypes,github.com/openconfig/ygot/testutil,github.com/openconfig/ygot/internal/yreflect github.com/openconfig/ygot/ytypes
echo 'mode: count' > concatenated.coverprofile
for p in $pkgs; do
dir=$(echo $p | sed -e 's/^github\.com\/openconfig\/ygot\///')
tail -n +2 $dir/profile.coverprofile >> concatenated.coverprofile
done
- name: Submit coverage
uses: shogo82148/actions-goveralls@v1
with:
path-to-profile: concatenated.coverprofile
- name: Go vet
run: |
for i in util ygen ytypes ygot/pathtranslate ypathgen; do
go vet ./$i
done
for j in ygot testcmp testutil; do
go vet -composites=false ./$j
done
- name: Gofmt
run: |
for i in `find . -type d | egrep -v "exampleoc|demo|proto|uexampleoc"`; do
diff -u <(echo -n) <(gofmt -d -s ./$i)
done
- name: Staticcheck
run: |
checkstr=""
for i in util ygot ygen ytypes ygot/pathtranslate testutil testcmp ypathgen; do
checkstr="$checkstr github.com/openconfig/ygot/$i/..."
done
staticcheck $checkstr