Skip to content

Commit

Permalink
makefile: buf setup backport v0.34 (#8863)
Browse files Browse the repository at this point in the history
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
  • Loading branch information
tnasu and jmalicevic committed Jul 13, 2023
1 parent 69da06e commit 781018a
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 87 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/check-generated.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Verify that generated code is up-to-date.
#
# Note that we run these checks regardless whether the input files have
# changed, because generated code can change in response to toolchain updates
# even if no files in the repository are modified.
name: Check generated code
on:
pull_request:
branches:
- main

permissions:
contents: read

jobs:
check-mocks:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.18'

- uses: actions/checkout@v3

- name: "Check generated mocks"
run: |
set -euo pipefail
readonly MOCKERY=v2.30.17 # N.B. no leading "v"
curl -sL "https://github.com/vektra/mockery/releases/download/v${MOCKERY}/mockery_${MOCKERY}_Linux_x86_64.tar.gz" | tar -C /usr/local/bin -xzf -
make mockery 2>/dev/null
if ! git diff --stat --exit-code ; then
echo ">> ERROR:"
echo ">>"
echo ">> Generated mocks require update (either Mockery or source files may have changed)."
echo ">> Ensure your tools are up-to-date, re-run 'make mockery' and update this PR."
echo ">>"
exit 1
fi
check-proto:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v3
with:
go-version: '1.18'

- uses: actions/checkout@v3
with:
fetch-depth: 1 # we need a .git directory to run git diff

- name: "Check protobuf generated code"
run: |
set -euo pipefail
# Install buf and gogo tools, so that differences that arise from
# toolchain differences are also caught.
readonly tools="$(mktemp -d)"
export PATH="${PATH}:${tools}/bin"
export GOBIN="${tools}/bin"
go install github.com/bufbuild/buf/cmd/buf
go install github.com/gogo/protobuf/protoc-gen-gogofaster@latest
make proto-gen
if ! git diff --stat --exit-code ; then
echo ">> ERROR:"
echo ">>"
echo ">> Protobuf generated code requires update (either tools or .proto files may have changed)."
echo ">> Ensure your tools are up-to-date, re-run 'make proto-gen' and update this PR."
echo ">>"
exit 1
fi
58 changes: 0 additions & 58 deletions .github/workflows/proto-docker.yml

This file was deleted.

19 changes: 19 additions & 0 deletions .github/workflows/proto-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Protobuf Lint
on:
pull_request:
paths:
- 'proto/**'
push:
paths:
- 'proto/**'

jobs:
lint:
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- uses: actions/checkout@v3
- uses: bufbuild/buf-setup-action@v1.5.0
- uses: bufbuild/buf-lint-action@v1
with:
input: 'proto'
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ VERSION := $(shell git describe --always)
LD_FLAGS = -X github.com/Finschia/ostracon/version.OCCoreSemVer=$(VERSION)
BUILD_FLAGS = -mod=readonly -ldflags "$(LD_FLAGS)"
HTTPS_GIT := https://github.com/Finschia/ostracon.git
DOCKER_BUF := docker run -v $(shell pwd):/workspace --workdir /workspace bufbuild/buf
CGO_ENABLED ?= 0
TARGET_OS ?= $(shell go env GOOS)
TARGET_ARCH ?= $(shell go env GOARCH)
Expand Down Expand Up @@ -83,7 +82,13 @@ ifeq (,$(shell which protoc-gen-gogofaster))
endif
.PHONY: check-proto-deps

proto-gen:
check-proto-format-deps:
ifeq (,$(shell which clang-format))
$(error "clang-format is required for Protobuf formatting. See instructions for your platform on how to install it.")
endif
.PHONY: check-proto-format-deps

proto-gen: check-proto-deps
@echo "Generating Protobuf files"
@go run github.com/bufbuild/buf/cmd/buf generate
@mv ./proto/ostracon/abci/types.pb.go ./abci/types/
Expand All @@ -98,9 +103,9 @@ proto-lint: check-proto-deps
@go run github.com/bufbuild/buf/cmd/buf lint
.PHONY: proto-lint

proto-format:
proto-format: check-proto-format-deps
@echo "Formatting Protobuf files"
docker run --rm -v $(shell pwd):/workspace --workdir /workspace tendermintdev/docker-build-proto find ./ -not -path "./third_party/*" -name *.proto -exec clang-format -i {} \;
@find . -name '*.proto' -path "./proto/*" -exec clang-format -i {} \;
.PHONY: proto-format

proto-check-breaking: check-proto-deps
Expand All @@ -112,7 +117,7 @@ proto-check-breaking: check-proto-deps
.PHONY: proto-check-breaking

proto-check-breaking-ci:
@$(DOCKER_BUF) breaking --against $(HTTPS_GIT)#branch=main
@go run github.com/bufbuild/buf/cmd/buf breaking --against ".git"#branch=main
.PHONY: proto-check-breaking-ci

###############################################################################
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ require (
github.com/Finschia/r2ishiguro_vrf v0.1.2
github.com/bufbuild/buf v1.23.1
github.com/golangci/golangci-lint v1.53.3
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/oasisprotocol/curve25519-voi v0.0.0-20230110094441-db37f07504ce
github.com/prometheus/common v0.42.0 // indirect
github.com/rs/zerolog v1.29.1
github.com/syndtr/goleveldb v1.0.1-0.20200815110645-5c35d600f0ca
github.com/vektra/mockery/v2 v2.30.17
Expand Down Expand Up @@ -169,7 +171,6 @@ require (
github.com/kisielk/gotool v1.0.0 // indirect
github.com/kkHAIKE/contextcheck v1.1.4 // indirect
github.com/klauspost/compress v1.16.6 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/kulti/thelper v0.6.3 // indirect
github.com/kunwardeep/paralleltest v1.0.7 // indirect
github.com/kyoh86/exportloopref v0.1.11 // indirect
Expand Down Expand Up @@ -209,7 +210,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/polyfloyd/go-errorlint v1.4.2 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/quasilyte/go-ruleguard v0.3.19 // indirect
github.com/quasilyte/gogrep v0.5.0 // indirect
Expand Down
19 changes: 19 additions & 0 deletions scripts/proto-gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
#
# Update the generated code for protocol buffers in the Tendermint repository.
# This must be run from inside a Tendermint working directory.
#
set -euo pipefail

# Work from the root of the repository.
cd "$(git rev-parse --show-toplevel)"

# Run inside Docker to install the correct versions of the required tools
# without polluting the local system.
docker run --rm -i -v "$PWD":/w --workdir=/w golang:1.18-alpine sh <<"EOF"
apk add git make
go install github.com/bufbuild/buf/cmd/buf
go install github.com/gogo/protobuf/protoc-gen-gogofaster@latest
make proto-gen
EOF
22 changes: 0 additions & 22 deletions scripts/protocgen.sh

This file was deleted.

0 comments on commit 781018a

Please sign in to comment.