github.com/docker/cnab-to-oci@v0.3.0-beta4/Makefile (about) 1 .DEFAULT_GOAL := all 2 SHELL:=/bin/bash 3 4 PKG_NAME := github.com/docker/cnab-to-oci 5 6 EXEC_EXT := 7 ifeq ($(OS),Windows_NT) 8 EXEC_EXT := .exe 9 endif 10 11 ifeq ($(TAG),) 12 TAG := $(shell git describe --always --dirty 2> /dev/null) 13 endif 14 ifeq ($(COMMIT),) 15 COMMIT := $(shell git rev-parse --short HEAD 2> /dev/null) 16 endif 17 18 ifeq ($(BUILDTIME),) 19 BUILDTIME := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ" 2> /dev/null) 20 endif 21 ifeq ($(BUILDTIME),) 22 BUILDTIME := unknown 23 $(warning unable to set BUILDTIME. Set the value manually) 24 endif 25 26 LDFLAGS := "-s -w \ 27 -X $(PKG_NAME)/internal.GitCommit=$(COMMIT) \ 28 -X $(PKG_NAME)/internal.Version=$(TAG) \ 29 -X $(PKG_NAME)/internal.BuildTime=$(BUILDTIME)" 30 31 BUILD_ARGS := \ 32 --build-arg BUILDTIME \ 33 --build-arg COMMIT \ 34 --build-arg TAG \ 35 --build-arg=GOPROXY 36 37 GO_BUILD := CGO_ENABLED=0 go build -ldflags=$(LDFLAGS) 38 GO_TEST := CGO_ENABLED=0 go test -ldflags=$(LDFLAGS) -failfast 39 GO_TEST_RACE := go test -ldflags=$(LDFLAGS) -failfast -race 40 41 all: build test 42 43 all-ci: lint all 44 45 check_go_env: 46 @test $$(go list) = "$(PKG_NAME)" || \ 47 (echo "Invalid Go environment - The local directory structure must match: $(PKG_NAME)" && false) 48 49 get-tools: 50 go get golang.org/x/tools/cmd/goimports 51 go get github.com/golangci/golangci-lint/cmd/golangci-lint 52 53 # Default build 54 build: bin/cnab-to-oci 55 56 bin/%: cmd/% check_go_env 57 $(GO_BUILD) -o $@$(EXEC_EXT) ./$< 58 59 install: 60 pushd cmd/cnab-to-oci && go install && popd 61 62 clean: 63 rm -rf bin 64 65 test: test-unit test-e2e 66 67 test-unit: 68 $(GO_TEST_RACE) $(shell go list ./... | grep -vE '/e2e') 69 70 test-e2e: e2e-image 71 docker run --rm --network=host -v /var/run/docker.sock:/var/run/docker.sock cnab-to-oci-e2e 72 73 build-e2e-test: 74 $(GO_TEST) -c github.com/docker/cnab-to-oci/e2e 75 76 e2e-image: 77 docker build $(BUILD_ARGS) . -t cnab-to-oci-e2e 78 79 format: get-tools 80 go fmt ./... 81 @for source in `find . -type f -name '*.go' -not -path "./vendor/*"`; do \ 82 goimports -w $$source ; \ 83 done 84 85 lint: get-tools 86 golangci-lint run ./... 87 88 .PHONY: all get-tools build clean test test-unit test-e2e e2e-image lint