Skip to content

Commit

Permalink
Add "checkgenerate" make target to CI (#385)
Browse files Browse the repository at this point in the history
  • Loading branch information
jhump authored Apr 18, 2023
1 parent 1fda47e commit fae5880
Show file tree
Hide file tree
Showing 15 changed files with 1,203 additions and 1,057 deletions.
14 changes: 13 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ shared_configs:
- run:
name: Run tests
command: |
make ci
make test
# Use the latest 2.1 version of CircleCI pipeline process engine. See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1
Expand All @@ -25,6 +25,17 @@ jobs:
working_directory: ~/repo
docker:
- image: cimg/go:1.19
steps:
- checkout
- run:
name: Run tests and linters
command: |
make ci
build-1-20:
working_directory: ~/repo
docker:
- image: cimg/go:1.20
steps: *simple_job_steps

workflows:
Expand All @@ -33,3 +44,4 @@ workflows:
- build-1-17
- build-1-18
- build-1-19
- build-1-20
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist/
.idea/
VERSION
.tmp/
25 changes: 23 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
dev_build_version=$(shell git describe --tags --always --dirty)

export PATH := $(shell pwd)/.tmp/protoc/bin:$(PATH)

export PROTOC_VERSION := 22.0

# TODO: run golint and errcheck, but only to catch *new* violations and
# decide whether to change code or not (e.g. we need to be able to whitelist
# violations already in the code). They can be useful to catch errors, but
# they are just too noisy to be a requirement for a CI -- we don't even *want*
# to fix some of the things they consider to be violations.
.PHONY: ci
ci: deps checkgofmt vet staticcheck ineffassign predeclared test
ci: deps checkgofmt checkgenerate vet staticcheck ineffassign predeclared test

.PHONY: deps
deps:
Expand All @@ -31,6 +35,19 @@ docker:
docker build -t fullstorydev/grpcurl:$(dev_build_version) .
@rm VERSION

.PHONY: generate
generate: .tmp/protoc/bin/protoc
@go install google.golang.org/protobuf/cmd/protoc-gen-go@a709e31e5d12
@go install google.golang.org/grpc/cmd/[email protected]
go generate ./...

.PHONY: checkgenerate
checkgenerate: generate
git status --porcelain
@if [ -n "$$(git status --porcelain)" ]; then \
exit 1; \
fi

.PHONY: checkgofmt
checkgofmt:
gofmt -s -l .
Expand All @@ -44,7 +61,7 @@ vet:

.PHONY: staticcheck
staticcheck:
@go install honnef.co/go/tools/cmd/staticcheck@v0.3.3
@go install honnef.co/go/tools/cmd/staticcheck@v0.4.3
staticcheck ./...

.PHONY: ineffassign
Expand Down Expand Up @@ -72,3 +89,7 @@ errcheck:
.PHONY: test
test:
go test -race ./...

.tmp/protoc/bin/protoc: ./Makefile ./download_protoc.sh
./download_protoc.sh

35 changes: 35 additions & 0 deletions download_protoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

set -e

cd $(dirname $0)

if [[ -z "$PROTOC_VERSION" ]]; then
echo "Set PROTOC_VERSION env var to indicate the version to download" >&2
exit 1
fi
PROTOC_OS="$(uname -s)"
PROTOC_ARCH="$(uname -m)"
case "${PROTOC_OS}" in
Darwin) PROTOC_OS="osx" ;;
Linux) PROTOC_OS="linux" ;;
*)
echo "Invalid value for uname -s: ${PROTOC_OS}" >&2
exit 1
esac

# This is for macs with M1 chips. Precompiled binaries for osx/amd64 are not available for download, so for that case
# we download the x86_64 version instead. This will work as long as rosetta2 is installed.
if [ "$PROTOC_OS" = "osx" ] && [ "$PROTOC_ARCH" = "arm64" ]; then
PROTOC_ARCH="x86_64"
fi

PROTOC="${PWD}/.tmp/protoc/bin/protoc"

if [[ "$(${PROTOC} --version 2>/dev/null)" != "libprotoc 3.${PROTOC_VERSION}" ]]; then
rm -rf ./.tmp/protoc
mkdir -p .tmp/protoc
curl -L "https://github.com/google/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-${PROTOC_OS}-${PROTOC_ARCH}.zip" > .tmp/protoc/protoc.zip
pushd ./.tmp/protoc && unzip protoc.zip && popd
fi

1 change: 1 addition & 0 deletions internal/testing/cmd/bankdemo/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

// bankServer implements the Bank gRPC service.
type bankServer struct {
UnimplementedBankServer
allAccounts *accounts
}

Expand Down
Loading

0 comments on commit fae5880

Please sign in to comment.