From bdea0ea42c997fe1ae3f4228b465efaaf6ca2853 Mon Sep 17 00:00:00 2001 From: Yuvraj Date: Fri, 3 Dec 2021 23:58:41 +0530 Subject: [PATCH] Added script for checking diff of generated code (#303) * Added ci check for go generate Signed-off-by: Yuvraj Signed-off-by: Katrina Rogan Co-authored-by: Katrina Rogan --- .github/workflows/pull_request.yml | 10 ++++ Makefile | 2 - .../flyte/golang_test_targets/Makefile | 4 ++ .../flyte/golang_test_targets/go-gen.sh | 22 ++++++++ .../interfaces/application_configuration.go | 2 +- .../inlineeventdatapolicy_enumer.go | 50 +++++++++++++++++++ 6 files changed, 87 insertions(+), 3 deletions(-) create mode 100755 boilerplate/flyte/golang_test_targets/go-gen.sh create mode 100644 pkg/runtime/interfaces/inlineeventdatapolicy_enumer.go diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 43ff39864b..e924f74e8b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -133,3 +133,13 @@ jobs: GO111MODULE: "on" with: args: 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/Makefile b/Makefile index 5ce74dbf72..6419a3bbf1 100644 --- a/Makefile +++ b/Makefile @@ -69,5 +69,3 @@ seed_projects: all: compile -generate: download_tooling - @go generate ./... diff --git a/boilerplate/flyte/golang_test_targets/Makefile b/boilerplate/flyte/golang_test_targets/Makefile index 21d8b5b776..280e1e55e4 100644 --- a/boilerplate/flyte/golang_test_targets/Makefile +++ b/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/boilerplate/flyte/golang_test_targets/go-gen.sh b/boilerplate/flyte/golang_test_targets/go-gen.sh new file mode 100755 index 0000000000..f2a63dda01 --- /dev/null +++ b/boilerplate/flyte/golang_test_targets/go-gen.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash + +set -ex + +echo "Generating pflags" +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/pkg/runtime/interfaces/application_configuration.go b/pkg/runtime/interfaces/application_configuration.go index 16ec45b503..d2b4dcc491 100644 --- a/pkg/runtime/interfaces/application_configuration.go +++ b/pkg/runtime/interfaces/application_configuration.go @@ -312,7 +312,7 @@ type SignedURL struct { } //go:generate enumer -type=InlineEventDataPolicy -trimprefix=InlineEventDataPolicy -type InlineEventDataPolicy = int +type InlineEventDataPolicy int const ( // InlineEventDataPolicyOffload specifies that inline execution event data (e.g. outputs) should be offloaded to the diff --git a/pkg/runtime/interfaces/inlineeventdatapolicy_enumer.go b/pkg/runtime/interfaces/inlineeventdatapolicy_enumer.go new file mode 100644 index 0000000000..63ff94e89f --- /dev/null +++ b/pkg/runtime/interfaces/inlineeventdatapolicy_enumer.go @@ -0,0 +1,50 @@ +// Code generated by "enumer -type=InlineEventDataPolicy -trimprefix=InlineEventDataPolicy"; DO NOT EDIT. + +// +package interfaces + +import ( + "fmt" +) + +const _InlineEventDataPolicyName = "OffloadStoreInline" + +var _InlineEventDataPolicyIndex = [...]uint8{0, 7, 18} + +func (i InlineEventDataPolicy) String() string { + if i < 0 || i >= InlineEventDataPolicy(len(_InlineEventDataPolicyIndex)-1) { + return fmt.Sprintf("InlineEventDataPolicy(%d)", i) + } + return _InlineEventDataPolicyName[_InlineEventDataPolicyIndex[i]:_InlineEventDataPolicyIndex[i+1]] +} + +var _InlineEventDataPolicyValues = []InlineEventDataPolicy{0, 1} + +var _InlineEventDataPolicyNameToValueMap = map[string]InlineEventDataPolicy{ + _InlineEventDataPolicyName[0:7]: 0, + _InlineEventDataPolicyName[7:18]: 1, +} + +// InlineEventDataPolicyString retrieves an enum value from the enum constants string name. +// Throws an error if the param is not part of the enum. +func InlineEventDataPolicyString(s string) (InlineEventDataPolicy, error) { + if val, ok := _InlineEventDataPolicyNameToValueMap[s]; ok { + return val, nil + } + return 0, fmt.Errorf("%s does not belong to InlineEventDataPolicy values", s) +} + +// InlineEventDataPolicyValues returns all values of the enum +func InlineEventDataPolicyValues() []InlineEventDataPolicy { + return _InlineEventDataPolicyValues +} + +// IsAInlineEventDataPolicy returns "true" if the value is listed in the enum definition. "false" otherwise +func (i InlineEventDataPolicy) IsAInlineEventDataPolicy() bool { + for _, v := range _InlineEventDataPolicyValues { + if i == v { + return true + } + } + return false +}