From bd1d4e5efbc0928f45c01d09efc54ac578a27621 Mon Sep 17 00:00:00 2001 From: Yuvraj Date: Mon, 6 Dec 2021 12:03:00 +0530 Subject: [PATCH] Added script for checking diff of generated code (#229) * Added script for checking diff of generated code Signed-off-by: Yuvraj --- flytectl/.github/config.yml | 2 +- flytectl/.github/workflows/build.yaml | 10 +++++++++ flytectl/Makefile | 3 --- .../flyte/golang_support_tools/go.mod | 4 ++-- .../flyte/golang_support_tools/go.sum | 5 +++-- .../flyte/golang_test_targets/Makefile | 4 ++++ .../flyte/golang_test_targets/go-gen.sh | 22 +++++++++++++++++++ .../boilerplate/flyte/welcome_bot/config.yml | 2 +- 8 files changed, 43 insertions(+), 9 deletions(-) create mode 100755 flytectl/boilerplate/flyte/golang_test_targets/go-gen.sh diff --git a/flytectl/.github/config.yml b/flytectl/.github/config.yml index 7afe6111f5..73da252e52 100644 --- a/flytectl/.github/config.yml +++ b/flytectl/.github/config.yml @@ -1,5 +1,5 @@ # Comment to be posted on PRs from first-time contributors in your repository -newPRWelcomeComment: > +newPRWelcomeComment: | Thank you for opening this pull request! 🙌 These tips will help get your PR across the finish line: diff --git a/flytectl/.github/workflows/build.yaml b/flytectl/.github/workflows/build.yaml index 03b19ecd88..148963bd0c 100644 --- a/flytectl/.github/workflows/build.yaml +++ b/flytectl/.github/workflows/build.yaml @@ -43,3 +43,13 @@ jobs: env: GO111MODULE: "on" run: make install && make lint + + generate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions/setup-go@v2 + with: + go-version: '1.16' + - name: Go generate and diff + run: DELTA_CHECK=true make generate \ No newline at end of file diff --git a/flytectl/Makefile b/flytectl/Makefile index 601e502569..d515ffa462 100644 --- a/flytectl/Makefile +++ b/flytectl/Makefile @@ -13,9 +13,6 @@ define PIP_COMPILE pip-compile $(1) --upgrade --verbose endef -generate: - go test github.com/flyteorg/flytectl/cmd --update - compile: go build -o bin/flytectl -ldflags=$(LD_FLAGS) main.go diff --git a/flytectl/boilerplate/flyte/golang_support_tools/go.mod b/flytectl/boilerplate/flyte/golang_support_tools/go.mod index 53f645159a..13941936c5 100644 --- a/flytectl/boilerplate/flyte/golang_support_tools/go.mod +++ b/flytectl/boilerplate/flyte/golang_support_tools/go.mod @@ -4,10 +4,10 @@ go 1.16 require ( github.com/alvaroloes/enumer v1.1.2 - github.com/flyteorg/flytestdlib v0.3.22 + github.com/flyteorg/flytestdlib v0.4.7 github.com/golangci/golangci-lint v1.38.0 - github.com/pseudomuto/protoc-gen-doc v1.4.1 // indirect github.com/vektra/mockery v0.0.0-20181123154057-e78b021dcbb5 + github.com/pseudomuto/protoc-gen-doc v0.1.1 // indirect ) replace github.com/vektra/mockery => github.com/enghabu/mockery v0.0.0-20191009061720-9d0c8670c2f0 diff --git a/flytectl/boilerplate/flyte/golang_support_tools/go.sum b/flytectl/boilerplate/flyte/golang_support_tools/go.sum index 261048f745..a62010d29f 100644 --- a/flytectl/boilerplate/flyte/golang_support_tools/go.sum +++ b/flytectl/boilerplate/flyte/golang_support_tools/go.sum @@ -210,8 +210,8 @@ github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg= github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= -github.com/flyteorg/flytestdlib v0.3.22 h1:nJEPaCdxzXBaeg2p4fdo3I3Ua09NedFRaUwuLafLEdw= -github.com/flyteorg/flytestdlib v0.3.22/go.mod h1:1XG0DwYTUm34Yrffm1Qy9Tdr/pWQypEqTq5dUxw3/cM= +github.com/flyteorg/flytestdlib v0.4.7 h1:SMPPXI3j/MjP7D2fqaR+lPQkTrqYS7xZbwsgJI2F8SU= +github.com/flyteorg/flytestdlib v0.4.7/go.mod h1:fv1ar34LJLMTaf0tbfetisLykUlARi7rP+NQTUn6QQs= github.com/flyteorg/protoc-gen-doc v1.4.2 h1:Otw0F+RHaPQ8XlpzhLLgjsCMcrAIcMO01Zh+ALe3rrE= github.com/flyteorg/protoc-gen-doc v1.4.2/go.mod h1:exDTOVwqpp30eV/EDPFLZy3Pwr2sn6hBC1WIYH/UbIg= github.com/form3tech-oss/jwt-go v3.2.2+incompatible h1:TcekIExNqud5crz4xD2pavyTgWiPvpYe4Xau31I0PRk= @@ -1263,6 +1263,7 @@ honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 honnef.co/go/tools v0.1.2 h1:SMdYLJl312RXuxXziCCHhRsp/tvct9cGKey0yv95tZM= honnef.co/go/tools v0.1.2/go.mod h1:NgwopIslSNH47DimFoV78dnkksY2EFtX0ajyb3K/las= k8s.io/api v0.0.0-20210217171935-8e2decd92398/go.mod h1:60tmSUpHxGPFerNHbo/ayI2lKxvtrhbxFyXuEIWJd78= +k8s.io/api v0.20.2/go.mod h1:d7n6Ehyzx+S+cE3VhTGfVNNqtGc/oL9DCdYYahlurV8= k8s.io/apimachinery v0.0.0-20210217011835-527a61b4dffe/go.mod h1:Z7ps/g0rjlTeMstYrMOUttJfT2Gg34DEaG/f2PYLCWY= k8s.io/apimachinery v0.20.2 h1:hFx6Sbt1oG0n6DZ+g4bFt5f6BoMkOjKWsQFu077M3Vg= k8s.io/apimachinery v0.20.2/go.mod h1:WlLqWAHZGg07AeltaI0MV5uk1Omp8xaN0JGLY6gkRpU= diff --git a/flytectl/boilerplate/flyte/golang_test_targets/Makefile b/flytectl/boilerplate/flyte/golang_test_targets/Makefile index 21d8b5b776..280e1e55e4 100644 --- a/flytectl/boilerplate/flyte/golang_test_targets/Makefile +++ b/flytectl/boilerplate/flyte/golang_test_targets/Makefile @@ -8,6 +8,10 @@ download_tooling: #download dependencies (including test deps) for the package @boilerplate/flyte/golang_test_targets/download_tooling.sh +.PHONY: generate +generate: download_tooling #generate go code + @boilerplate/flyte/golang_test_targets/go-gen.sh + .PHONY: lint lint: download_tooling #lints the package for common code smells GL_DEBUG=linters_output,env golangci-lint run --deadline=5m --exclude deprecated -v diff --git a/flytectl/boilerplate/flyte/golang_test_targets/go-gen.sh b/flytectl/boilerplate/flyte/golang_test_targets/go-gen.sh new file mode 100755 index 0000000000..54bd6af61b --- /dev/null +++ b/flytectl/boilerplate/flyte/golang_test_targets/go-gen.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -ex + +echo "Running go generate" +go generate ./... + +# This section is used by GitHub workflow to ensure that the generation step was run +if [ -n "$DELTA_CHECK" ]; then + DIRTY=$(git status --porcelain) + if [ -n "$DIRTY" ]; then + echo "FAILED: Go code updated without commiting generated code." + echo "Ensure make generate has run and all changes are committed." + DIFF=$(git diff) + echo "diff detected: $DIFF" + DIFF=$(git diff --name-only) + echo "files different: $DIFF" + exit 1 + else + echo "SUCCESS: Generated code is up to date." + fi +fi diff --git a/flytectl/boilerplate/flyte/welcome_bot/config.yml b/flytectl/boilerplate/flyte/welcome_bot/config.yml index 7afe6111f5..73da252e52 100644 --- a/flytectl/boilerplate/flyte/welcome_bot/config.yml +++ b/flytectl/boilerplate/flyte/welcome_bot/config.yml @@ -1,5 +1,5 @@ # Comment to be posted on PRs from first-time contributors in your repository -newPRWelcomeComment: > +newPRWelcomeComment: | Thank you for opening this pull request! 🙌 These tips will help get your PR across the finish line: