-
Notifications
You must be signed in to change notification settings - Fork 247
157 lines (138 loc) · 5.42 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
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: Build and Test
on:
push:
branches:
- 'main'
pull_request:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["stable"]
command: ["build", "vet", "lint", "test", "testrace"]
steps:
- name: Check out repository
uses: actions/checkout@v3
# The setup-go action's default caching behavior does not work well with
# matrix tests. By default, setup-go caches the contents of `go env
# GOCACHE` and `go env GOMODCACHE` under a key derived from the OS, the
# go version, and a hash of the contents of go.sum [1].
#
# When we run a matrix test, every job uses the same cache key. As a
# result, the jobs race, and the first to finish determines the contents
# of the cache. Because caches are write-once, all other jobs fail to
# update the cache. In subsequent runs, all jobs use the contents of the
# cache, even if the cache was generated by a different job.
#
# For example, if the "lint" job finishes first, then all future jobs
# like "build" and "test" will use the cache produced by the "lint" job.
# However, this cache is likely missing a lot of cached package and build
# outputs, causing to the "build" and "test" jobs to redundantly download
# and build dependencies again and again.
#
# To avoid this problem, we manually cache the contents of `go env
# GOCACHE` and `go env GOMODCACHE` using a key derived from the OS, the
# go version, the contents of go.sum, and the matrix command. See [2] for
# more documentation on custom cache keys and paths.
#
# [1]: https://github.com/actions/setup-go/blob/93397bea11091df50f3d7e59dc26a7711a8bcfbe/docs/adrs/0000-caching-dependencies.md
# [2]: https://github.com/actions/cache#creating-a-cache-key
- name: Set up Go
id: setup-go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.version }}
cache: false
- name: Get go cache locations
id: get-go-caches
run: |
echo "gocache=$(go env GOCACHE)" >> $GITHUB_OUTPUT
echo "gomodcache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT
- name: Cache go
uses: actions/cache@v3
with:
path: |
${{ steps.get-go-caches.outputs.gocache }}
${{ steps.get-go-caches.outputs.gomodcache }}
key: ${{ runner.os }}-go${{ steps.setup-go.outputs.go-version }}-${{ hashFiles('go.sum') }}-${{ matrix.command }}
- name: Cache linter
uses: actions/cache@v3
with:
path: ~/go/bin/staticcheck
key: staticcheck-v0.5.0
if: ${{ matrix.command == 'lint' }}
- name: Install linter
run: go install honnef.co/go/tools/cmd/staticcheck@v0.5.0
if: ${{ matrix.command == 'lint' }}
- name: Build the weaver binary
run: cd cmd/weaver; go build .
if: ${{ matrix.command == 'test' || matrix.command == 'testrace' }}
- name: ${{ matrix.command }}
run: ./dev/build_and_test ${{ matrix.command }}
generate:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["stable"]
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.version }}
cache: true
- name: Cache protoc-gen-go
uses: actions/cache@v3
with:
path: ~/go/bin/protoc-gen-go
key: protoc-gen-go-v1.26
- name: Cache addlicense
uses: actions/cache@v3
with:
path: ~/go/bin/addlicense
key: addlicense-v1.1.1
- name: Install protoc
run: sudo apt install -y protobuf-compiler
- name: Install protoc-gen-go
run: go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.26
- name: Install addlicense
run: go install github.com/google/addlicense@v1.1.1
- name: Generate code
run: ./dev/build_and_test generate
- name: Check spurious changes
run: |
# TODO(mwhittaker): Check .pb.go files.
# Exclude the weaver binary, which is built by the generate tool.
rm ./cmd/weaver/weaver
# Exclude .pb.go files, as the protoc version may differ.
if [[ $(git ls-files --modified --others | grep -v '.*\.pb\.go') ]]; then
for f in $(git ls-files --modified); do
if ! [[ $f == *.pb.go ]]; then
echo "❌ File $f modified."
git diff "$f"
fi
done
for f in $(git ls-files --others); do
echo "❌ File $f untracked."
done
echo "Run './dev/build_and_test generate' and commit the changes."
exit 1
fi
echo "Success ✅"