|
1 | 1 | #! /usr/bin/make |
2 | 2 | # |
3 | | -# Makefile for Goa examples |
4 | | -# |
5 | | -# Targets: |
6 | | -# - "depend" retrieves the Go packages needed to run the linter and tests |
7 | | -# - "gen" invokes the "goa" tool to generate the examples source code |
8 | | -# - "build" compiles the example microservices and client CLIs |
9 | | -# - "clean" deletes the output of "build" |
10 | | -# - "lint" runs the linter and checks the code format using goimports |
11 | | -# - "test" runs the tests |
12 | | -# |
13 | | -# Meta targets: |
14 | | -# - "all" is the default target, it runs all the targets in the order above. |
15 | | -# |
16 | | -GO_FILES=$(shell find . -type f -name '*.go') |
17 | | -MODULE=$(shell go list -m) |
18 | | -APP=cellar |
19 | | - |
20 | | -# Only list test and build dependencies |
21 | | -# Standard dependencies are installed via go get |
22 | | -DEPEND=\ |
23 | | - github.com/hashicorp/go-getter \ |
24 | | - github.com/cheggaaa/pb \ |
25 | | - github.com/golang/protobuf/protoc-gen-go \ |
26 | | - github.com/golang/protobuf/proto \ |
27 | | - goa.design/goa/... \ |
28 | | - golang.org/x/lint/golint \ |
29 | | - golang.org/x/tools/cmd/goimports \ |
30 | | - honnef.co/go/tools/cmd/staticcheck |
31 | | - |
32 | | -.phony: all depend lint test build clean |
33 | | - |
34 | | -all: gen lint test |
35 | | - @echo DONE! |
| 3 | +# Makefile for Goa v3 cellar example |
36 | 4 |
|
37 | | -# Install protoc |
38 | | -GOOS=$(shell go env GOOS) |
39 | | -PROTOC_VERSION=3.6.1 |
40 | | -ifeq ($(GOOS),linux) |
41 | | -PROTOC=protoc-$(PROTOC_VERSION)-linux-x86_64 |
42 | | -PROTOC_EXEC=$(PROTOC)/bin/protoc |
43 | | -GOBIN=$(GOPATH)/bin |
44 | | -else |
45 | | - ifeq ($(GOOS),darwin) |
46 | | -PROTOC=protoc-$(PROTOC_VERSION)-osx-x86_64 |
47 | | -PROTOC_EXEC=$(PROTOC)/bin/protoc |
48 | | -GOBIN=$(GOPATH)/bin |
49 | | - else |
50 | | - ifeq ($(GOOS),windows) |
51 | | -PROTOC=protoc-$(PROTOC_VERSION)-win32 |
52 | | -PROTOC_EXEC="$(PROTOC)\bin\protoc.exe" |
53 | | -GOBIN="$(GOPATH)\bin" |
54 | | - endif |
55 | | - endif |
56 | | -endif |
57 | | -depend: |
58 | | - @echo INSTALLING DEPENDENCIES... |
59 | | - @go get -v $(DEPEND) |
60 | | - @go install github.com/hashicorp/go-getter/cmd/go-getter && \ |
61 | | - go-getter https://github.com/google/protobuf/releases/download/v$(PROTOC_VERSION)/$(PROTOC).zip $(PROTOC) && \ |
62 | | - cp $(PROTOC_EXEC) $(GOBIN) && \ |
63 | | - rm -r $(PROTOC) |
64 | | - @go install github.com/golang/protobuf/protoc-gen-go |
65 | | - @go get -t -v ./... |
66 | | - |
67 | | -lint: |
68 | | - @echo LINTING CODE... |
69 | | - @if [ "`goimports -l $(GO_FILES) | grep -v .pb.go | tee /dev/stderr`" ]; then \ |
70 | | - echo "^ - Repo contains improperly formatted go files" && echo && exit 1; \ |
71 | | - fi |
72 | | - @if [ "`staticcheck ./... | grep -v ".pb.go" | tee /dev/stderr`" ]; then \ |
73 | | - echo "^ - staticcheck errors!" && echo && exit 1; \ |
74 | | - fi |
75 | | - |
76 | | -.PHONY: gen |
77 | | -gen: |
78 | | - @# NOTE: not all command line tools are generated |
79 | | - @echo GENERATING CODE... |
80 | | - @goa gen "$(MODULE)/design" && \ |
81 | | - goa example "$(MODULE)/design" |
82 | | - |
83 | | -build: |
84 | | - @go build "./cmd/$(APP)" && go build "./cmd/$(APP)-cli" |
85 | | - |
86 | | -clean: |
87 | | - @rm -rf "./cmd/$(APP)" "./cmd/$(APP)-cli" |
88 | | - |
89 | | -test: |
90 | | - @echo TESTING... |
91 | | - @go test ./... > /dev/null |
| 5 | +APP=cellar |
92 | 6 |
|
93 | | -check-freshness: |
94 | | - @if [ "`git diff | wc -l`" -gt "0" ]; then \ |
95 | | - echo "[ERROR] generated code not in-sync with design:"; \ |
96 | | - echo; \ |
97 | | - git status -s; \ |
98 | | - git --no-pager diff; \ |
99 | | - echo; \ |
100 | | - exit 1; \ |
101 | | - fi |
| 7 | +include ../common.mk |
0 commit comments