Skip to content

Commit 814817c

Browse files
authored
Introduce generated codes into codebase (#74)
1 parent aaf8a55 commit 814817c

File tree

11 files changed

+2462
-165
lines changed

11 files changed

+2462
-165
lines changed

.github/workflows/go.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ jobs:
3737
uses: actions/checkout@v2
3838
with:
3939
submodules: true
40+
41+
- name: Check code generation
42+
run: make check-codegen
43+
44+
- uses: actions/upload-artifact@v2
45+
if: failure()
46+
with:
47+
name: check-diff
48+
path: /tmp/swctl/check.diff
4049

4150
- name: Check License
4251
run: make license

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
.idea
22
bin
33
coverage.txt
4-
graphql/schema/schema.go
54
.DS_Store
6-
*-packr.go
7-
packrd

Makefile

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ GO_GET = $(GO) get
3131
GO_TEST = $(GO) test
3232
GO_LINT = $(GO_PATH)/bin/golangci-lint
3333
GO_LICENSER = $(GO_PATH)/bin/go-licenser
34-
GO_PACKR = $(GO_PATH)/bin/packr2
34+
ARCH := $(shell uname)
35+
OSNAME := $(if $(findstring Darwin,$(ARCH)),darwin,linux)
36+
GOBINDATA_VERSION := v3.21.0
37+
GO_BINDATA = $(GO_PATH)/bin/go-bindata
3538
GO_BUILD_FLAGS = -v
3639
GO_BUILD_LDFLAGS = -X main.version=$(VERSION)
3740
GQL_GEN = $(GO_PATH)/bin/gqlgen
@@ -45,19 +48,33 @@ SHELL = /bin/bash
4548
all: clean license deps codegen lint test build
4649

4750
tools:
48-
$(GO_PACKR) -v || $(GO_GET) -u github.com/gobuffalo/packr/v2/...
51+
mkdir -p $(GO_PATH)/bin
52+
$(GO_BINDATA) -v || curl --location --output $(GO_BINDATA) https://github.com/kevinburke/go-bindata/releases/download/$(GOBINDATA_VERSION)/go-bindata-$(OSNAME)-amd64 \
53+
&& chmod +x $(GO_BINDATA)
4954
$(GO_LINT) version || curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(GO_PATH)/bin v1.21.0
5055
$(GO_LICENSER) -version || GO111MODULE=off $(GO_GET) -u github.com/elastic/go-licenser
5156
$(GQL_GEN) version || $(GO_GET) -u github.com/99designs/gqlgen
5257

5358
deps: tools
5459
$(GO_GET) -v -t -d ./...
5560

56-
codegen: clean tools
61+
.PHONY: assets
62+
assets: tools
63+
cd assets \
64+
&& $(GO_BINDATA) --nocompress --nometadata --pkg assets --ignore '.*\.go' \
65+
-o "assets.gen.go" ./... \
66+
&& ../hack/build-header.sh assets.gen.go \
67+
&& cd ..
68+
69+
gqlgen: tools
5770
echo 'scalar Long' > query-protocol/schema.graphqls
5871
$(GQL_GEN) generate
5972
-rm -rf generated.go
60-
cd assets && GO111MODULE=on $(GO_PACKR) -v && cd ..
73+
-hack/build-header.sh graphql/schema/schema.go
74+
-rm query-protocol/schema.graphqls
75+
76+
codegen: clean assets gqlgen
77+
@go mod tidy &> /dev/null
6178

6279
.PHONY: $(PLATFORMS)
6380
$(PLATFORMS):
@@ -96,12 +113,10 @@ clean: tools
96113
-rm -rf bin
97114
-rm -rf coverage.txt
98115
-rm -rf query-protocol/schema.graphqls
99-
-rm -rf graphql/schema/schema.go
100116
-rm -rf *.tgz
101117
-rm -rf *.tgz
102118
-rm -rf *.asc
103119
-rm -rf *.sha512
104-
cd assets && $(GO_PACKR) clean
105120

106121
release-src: clean
107122
-tar -zcvf $(RELEASE_SRC).tgz \
@@ -111,10 +126,7 @@ release-src: clean
111126
--exclude .DS_Store \
112127
--exclude .github \
113128
--exclude $(RELEASE_SRC).tgz \
114-
--exclude graphql/schema/schema.go \
115129
--exclude query-protocol/schema.graphqls \
116-
--exclude assets/packrd \
117-
--exclude assets/*-packr.go \
118130
.
119131

120132
release-bin: build
@@ -131,3 +143,15 @@ release: verify release-src release-bin
131143
shasum -a 512 $(RELEASE_SRC).tgz > $(RELEASE_SRC).tgz.sha512
132144
gpg --batch --yes --armor --detach-sig $(RELEASE_BIN).tgz
133145
shasum -a 512 $(RELEASE_BIN).tgz > $(RELEASE_BIN).tgz.sha512
146+
147+
## Check that the status is consistent with CI.
148+
check-codegen: codegen
149+
$(MAKE) clean
150+
mkdir -p /tmp/swctl
151+
@go mod tidy &> /dev/null
152+
git diff >/tmp/swctl/check.diff 2>&1
153+
@if [ ! -z "`git status -s`" ]; then \
154+
echo "Following files are not consistent with CI:"; \
155+
git status -s; \
156+
exit 1; \
157+
fi

0 commit comments

Comments
 (0)