From 94bee6924e982b173b99b4b0addf69e0962e6e78 Mon Sep 17 00:00:00 2001 From: Denis Fadeev Date: Sun, 18 Jun 2023 12:27:18 +0400 Subject: [PATCH] ci: workflow to check if generated Go/OpenAPI source matches proto (#704) * ci: workflow * fix: remove flags from diff * refactor: error message * chore: rename workflow * fix: use bash explicitly * fix: remove pipefail * generate-go.yml * fix: install buf * fix: install buf * fix: install plugins * fix: add protoc plugins to path * fix: remove pipefail * trigger action * fix: workflow name * fix: diff flags * generate go only * generate go * fix: typo * remove openapi * ci: make a change to proto only on purpose to check the workflow * reverted the change so that the workflow succeeds * refactor: error message * fix * openapi * make proto * docs: name --- .github/workflows/generate-go.yml | 30 ++++++++++++++++++++++++++++++ Makefile | 4 ++-- scripts/protoc-gen-go.sh | 2 -- scripts/protoc-gen-openapi.sh | 4 ++-- 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/generate-go.yml diff --git a/.github/workflows/generate-go.yml b/.github/workflows/generate-go.yml new file mode 100644 index 0000000000..936e4801f5 --- /dev/null +++ b/.github/workflows/generate-go.yml @@ -0,0 +1,30 @@ +name: Generated Go/OpenAPI to Match Protobuf +on: + pull_request: + branches: + - "*" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - uses: bufbuild/buf-setup-action@v1 + + - name: Add protoc plugins to PATH + run: | + echo "$HOME/go/bin" >> $GITHUB_PATH + + - name: Generate Go and OpenAPI + run: make proto + + - name: Check for changes + run: | + if git diff --exit-code --ignore-space-change --ignore-all-space --ignore-cr-at-eol; then + echo "Generated Go files are up-to-date." + else + echo "::error::Generated Go and/or OpenAPI files are not up-to-date. Please run 'make proto' locally and commit any changes." + exit 1 + fi diff --git a/Makefile b/Makefile index 28dd5b871e..4e4f08be2a 100644 --- a/Makefile +++ b/Makefile @@ -122,9 +122,9 @@ lint: lint-pre proto: @echo "--> Generating Go from protocol buffer files" - @sh ./scripts/protoc-gen-go.sh + @bash ./scripts/protoc-gen-go.sh @echo "--> Generating OpenAPI specs" - @sh ./scripts/protoc-gen-openapi.sh + @bash ./scripts/protoc-gen-openapi.sh .PHONY: proto specs: diff --git a/scripts/protoc-gen-go.sh b/scripts/protoc-gen-go.sh index 188e297549..4ecc9a1f61 100755 --- a/scripts/protoc-gen-go.sh +++ b/scripts/protoc-gen-go.sh @@ -1,7 +1,5 @@ #!/usr/bin/env bash -set -eo pipefail - # Install the required protoc execution tools. go install github.com/regen-network/cosmos-proto/protoc-gen-gocosmos go install google.golang.org/protobuf/cmd/protoc-gen-go@latest diff --git a/scripts/protoc-gen-openapi.sh b/scripts/protoc-gen-openapi.sh index 3f29337de1..4725453267 100755 --- a/scripts/protoc-gen-openapi.sh +++ b/scripts/protoc-gen-openapi.sh @@ -1,9 +1,9 @@ #!/usr/bin/env bash -set -eo pipefail - go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2@latest +go mod download + COSMOS_SDK="github.com/cosmos/cosmos-sdk" PROTO_TEMPLATE="proto/buf.openapi.yaml" OUTPUT_DIR="./docs/openapi"