Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.

Commit e6dfcd1

Browse files
author
Sameer Naik
committed
adds make build infra
1 parent 5f0625d commit e6dfcd1

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

Makefile

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
PACKAGE = aws-custom-runtime
2+
PACKAGE_DESC = Triggermesh AWS Lambda Custom Runtime
3+
4+
TARGETS ?= linux/amd64
5+
6+
BASE_DIR ?= $(CURDIR)
7+
8+
OUTPUT_DIR ?= $(BASE_DIR)/_output
9+
10+
BIN_OUTPUT_DIR ?= $(OUTPUT_DIR)
11+
TEST_OUTPUT_DIR ?= $(OUTPUT_DIR)
12+
COVER_OUTPUT_DIR ?= $(OUTPUT_DIR)
13+
DIST_DIR ?= $(OUTPUT_DIR)
14+
15+
GO ?= go
16+
GOFMT ?= gofmt
17+
GOLINT ?= golangci-lint run
18+
GOTOOL ?= go tool
19+
GOTEST ?= gotestsum --junitfile $(TEST_OUTPUT_DIR)/$(PACKAGE)-unit-tests.xml --format pkgname-and-test-fails --
20+
21+
GOPKGS = ./pkg/events/...
22+
LDFLAGS = -extldflags=-static -w -s
23+
24+
HAS_GOTESTSUM := $(shell command -v gotestsum;)
25+
HAS_GOLANGCI_LINT := $(shell command -v golangci-lint;)
26+
27+
.PHONY: help build install release test coverage lint fmt fmt-test clean
28+
29+
all: build
30+
31+
install-gotestsum:
32+
ifndef HAS_GOTESTSUM
33+
curl -SL https://github.com/gotestyourself/gotestsum/releases/download/v0.4.2/gotestsum_0.4.2_linux_amd64.tar.gz | tar -C $(shell go env GOPATH)/bin -zxf -
34+
endif
35+
36+
install-golangci-lint:
37+
ifndef HAS_GOLANGCI_LINT
38+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.26.0
39+
endif
40+
41+
help: ## Display this help
42+
@awk 'BEGIN {FS = ":.*?## "; printf "\n$(PACKAGE_DESC)\nUsage:\n make \033[36m<source>\033[0m\n"} /^[a-zA-Z0-9._-]+:.*?## / {printf " \033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
43+
44+
build: ## Build the binary
45+
$(GO) build -ldflags "$(LDFLAGS)" -o $(BIN_OUTPUT_DIR)/$(PACKAGE)
46+
47+
test: install-gotestsum ## Run unit tests
48+
@mkdir -p $(TEST_OUTPUT_DIR)
49+
$(GOTEST) -p=1 -race -cover -coverprofile=$(TEST_OUTPUT_DIR)/$(PACKAGE)-c.out $(GOPKGS)
50+
51+
cover: test ## Generate code coverage
52+
@mkdir -p $(COVER_OUTPUT_DIR)
53+
$(GOTOOL) cover -html=$(TEST_OUTPUT_DIR)/$(PACKAGE)-c.out -o $(COVER_OUTPUT_DIR)/$(PACKAGE)-coverage.html
54+
55+
lint: install-golangci-lint ## Lint source files
56+
$(GOLINT) $(GOPKGS)
57+
58+
fmt: ## Format source files
59+
$(GOFMT) -s -w $(shell $(GO) list -f '{{$$d := .Dir}}{{range .GoFiles}}{{$$d}}/{{.}} {{end}} {{$$d := .Dir}}{{range .TestGoFiles}}{{$$d}}/{{.}} {{end}}' $(GOPKGS))
60+
61+
fmt-test: ## Check source formatting
62+
@test -z $(shell $(GOFMT) -l $(shell $(GO) list -f '{{$$d := .Dir}}{{range .GoFiles}}{{$$d}}/{{.}} {{end}} {{$$d := .Dir}}{{range .TestGoFiles}}{{$$d}}/{{.}} {{end}}' $(GOPKGS)))
63+
64+
release: ## Build release binaries
65+
@set -e ; \
66+
for platform in $(TARGETS); do \
67+
GOOS=$${platform%/*} ; \
68+
GOARCH=$${platform#*/} ; \
69+
RELEASE_BINARY=$(PACKAGE)-$${GOOS}-$${GOARCH} ; \
70+
[ $${GOOS} = "windows" ] && RELEASE_BINARY=$${RELEASE_BINARY}.exe ; \
71+
echo "GOOS=$${GOOS} GOARCH=$${GOARCH} $(GO) build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/$${RELEASE_BINARY}" . ; \
72+
GOOS=$${GOOS} GOARCH=$${GOARCH} $(GO) build -ldflags "$(LDFLAGS)" -o $(DIST_DIR)/$${RELEASE_BINARY} . ; \
73+
done
74+
75+
clean: ## Clean build artifacts
76+
@for platform in $(TARGETS); do \
77+
GOOS=$${platform%/*} ; \
78+
GOARCH=$${platform#*/} ; \
79+
RELEASE_BINARY=$(PACKAGE)-$${GOOS}-$${GOARCH} ; \
80+
[ $${GOOS} = "windows" ] && RELEASE_BINARY=$${RELEASE_BINARY}.exe ; \
81+
$(RM) -v $(DIST_DIR)/$${RELEASE_BINARY}; \
82+
done
83+
@$(RM) -v $(BIN_OUTPUT_DIR)/$(PACKAGE)
84+
@$(RM) -v $(TEST_OUTPUT_DIR)/$(PACKAGE)-c.out $(TEST_OUTPUT_DIR)/$(PACKAGE)-unit-tests.xml
85+
@$(RM) -v $(COVER_OUTPUT_DIR)/$(PACKAGE)-coverage.html

0 commit comments

Comments
 (0)