Skip to content

Instantly share code, notes, and snippets.

@maddiesch
Last active July 17, 2023 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maddiesch/7f5b8bb943acea75f2d0bc348d84c48e to your computer and use it in GitHub Desktop.
Save maddiesch/7f5b8bb943acea75f2d0bc348d84c48e to your computer and use it in GitHub Desktop.
Golang Makefile for SAM project
GOLANG := go
GOLANG_TEST_FLAGS ?= -v
GOLANG_TEST_RUN ?= .
GOLANG_TEST_PATH ?= ./...
GO_LAMBDA_ENV ?= GOOS=linux GOARCH=arm64
GO_LAMBDA_BUILD_FLAGS ?= -ldflags="-s -w" -tags "lambda.norpc"
GO_LAMBDA_BUILD ?= ${GO_LAMBDA_ENV} ${GOLANG} build ${GO_LAMBDA_BUILD_FLAGS}
GO_FILES := $(shell find . -type f -name '*.go' ! -name '*_test.go')
GO_TEST_FILES := $(shell find . -type f -name '*_test.go')
.PHONY: test
test:
${GOLANG} test ${GOLANG_TEST_FLAGS} -run ${GOLANG_TEST_RUN} ${GOLANG_TEST_PATH}
.PHONY: clean
clean:
rm -rf ./bin
${GOLANG} clean -testcache
bin/%/bootstrap: ${GO_FILES} ./go.mod ./go.sum
${GO_LAMBDA_BUILD} -o $@ ./cmd/$(patsubst bin/%/bootstrap,%,$@)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment