Skip to content

Commit fae5880

Browse files
authored
Add "checkgenerate" make target to CI (#385)
1 parent 1fda47e commit fae5880

15 files changed

+1203
-1057
lines changed

.circleci/config.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ shared_configs:
44
- run:
55
name: Run tests
66
command: |
7-
make ci
7+
make test
88
99
# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference
1010
version: 2.1
@@ -25,6 +25,17 @@ jobs:
2525
working_directory: ~/repo
2626
docker:
2727
- image: cimg/go:1.19
28+
steps:
29+
- checkout
30+
- run:
31+
name: Run tests and linters
32+
command: |
33+
make ci
34+
35+
build-1-20:
36+
working_directory: ~/repo
37+
docker:
38+
- image: cimg/go:1.20
2839
steps: *simple_job_steps
2940

3041
workflows:
@@ -33,3 +44,4 @@ workflows:
3344
- build-1-17
3445
- build-1-18
3546
- build-1-19
47+
- build-1-20

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dist/
22
.idea/
33
VERSION
4+
.tmp/

Makefile

+23-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
dev_build_version=$(shell git describe --tags --always --dirty)
22

3+
export PATH := $(shell pwd)/.tmp/protoc/bin:$(PATH)
4+
5+
export PROTOC_VERSION := 22.0
6+
37
# TODO: run golint and errcheck, but only to catch *new* violations and
48
# decide whether to change code or not (e.g. we need to be able to whitelist
59
# violations already in the code). They can be useful to catch errors, but
610
# they are just too noisy to be a requirement for a CI -- we don't even *want*
711
# to fix some of the things they consider to be violations.
812
.PHONY: ci
9-
ci: deps checkgofmt vet staticcheck ineffassign predeclared test
13+
ci: deps checkgofmt checkgenerate vet staticcheck ineffassign predeclared test
1014

1115
.PHONY: deps
1216
deps:
@@ -31,6 +35,19 @@ docker:
3135
docker build -t fullstorydev/grpcurl:$(dev_build_version) .
3236
@rm VERSION
3337

38+
.PHONY: generate
39+
generate: .tmp/protoc/bin/protoc
40+
@go install google.golang.org/protobuf/cmd/protoc-gen-go@a709e31e5d12
41+
@go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.1.0
42+
go generate ./...
43+
44+
.PHONY: checkgenerate
45+
checkgenerate: generate
46+
git status --porcelain
47+
@if [ -n "$$(git status --porcelain)" ]; then \
48+
exit 1; \
49+
fi
50+
3451
.PHONY: checkgofmt
3552
checkgofmt:
3653
gofmt -s -l .
@@ -44,7 +61,7 @@ vet:
4461

4562
.PHONY: staticcheck
4663
staticcheck:
47-
@go install honnef.co/go/tools/cmd/staticcheck@v0.3.3
64+
@go install honnef.co/go/tools/cmd/staticcheck@v0.4.3
4865
staticcheck ./...
4966

5067
.PHONY: ineffassign
@@ -72,3 +89,7 @@ errcheck:
7289
.PHONY: test
7390
test:
7491
go test -race ./...
92+
93+
.tmp/protoc/bin/protoc: ./Makefile ./download_protoc.sh
94+
./download_protoc.sh
95+

download_protoc.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
cd $(dirname $0)
6+
7+
if [[ -z "$PROTOC_VERSION" ]]; then
8+
echo "Set PROTOC_VERSION env var to indicate the version to download" >&2
9+
exit 1
10+
fi
11+
PROTOC_OS="$(uname -s)"
12+
PROTOC_ARCH="$(uname -m)"
13+
case "${PROTOC_OS}" in
14+
Darwin) PROTOC_OS="osx" ;;
15+
Linux) PROTOC_OS="linux" ;;
16+
*)
17+
echo "Invalid value for uname -s: ${PROTOC_OS}" >&2
18+
exit 1
19+
esac
20+
21+
# This is for macs with M1 chips. Precompiled binaries for osx/amd64 are not available for download, so for that case
22+
# we download the x86_64 version instead. This will work as long as rosetta2 is installed.
23+
if [ "$PROTOC_OS" = "osx" ] && [ "$PROTOC_ARCH" = "arm64" ]; then
24+
PROTOC_ARCH="x86_64"
25+
fi
26+
27+
PROTOC="${PWD}/.tmp/protoc/bin/protoc"
28+
29+
if [[ "$(${PROTOC} --version 2>/dev/null)" != "libprotoc 3.${PROTOC_VERSION}" ]]; then
30+
rm -rf ./.tmp/protoc
31+
mkdir -p .tmp/protoc
32+
curl -L "https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_OS}-${PROTOC_ARCH}.zip" > .tmp/protoc/protoc.zip
33+
pushd ./.tmp/protoc && unzip protoc.zip && popd
34+
fi
35+

internal/testing/cmd/bankdemo/bank.go

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
// bankServer implements the Bank gRPC service.
1414
type bankServer struct {
15+
UnimplementedBankServer
1516
allAccounts *accounts
1617
}
1718

0 commit comments

Comments
 (0)