Skip to content

Commit

Permalink
Added script for checking diff of generated code (flyteorg#303)
Browse files Browse the repository at this point in the history
* Added ci check for go generate

Signed-off-by: Yuvraj <[email protected]>

Signed-off-by: Katrina Rogan <[email protected]>

Co-authored-by: Katrina Rogan <[email protected]>
  • Loading branch information
yindia and katrogan authored Dec 3, 2021
1 parent 72be279 commit 8376093
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 3 deletions.
10 changes: 10 additions & 0 deletions flyteadmin/.github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 0 additions & 2 deletions flyteadmin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,3 @@ seed_projects:

all: compile

generate: download_tooling
@go generate ./...
4 changes: 4 additions & 0 deletions flyteadmin/boilerplate/flyte/golang_test_targets/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions flyteadmin/boilerplate/flyte/golang_test_targets/go-gen.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 50 additions & 0 deletions flyteadmin/pkg/runtime/interfaces/inlineeventdatapolicy_enumer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8376093

Please sign in to comment.