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