-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
125 lines (98 loc) · 2.97 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
SHELL := /usr/bin/env bash
# tools:
GO ?= go
CMD_DOCKER ?= docker
CMD_GIT ?= git
CMD_EMBEDMD ?= embedmd
CMD_GORELEASER ?= goreleaser
CMD_GOLANGCI_LINT ?= golangci-lint
# environment:
ARCH ?= $(shell go env GOARCH)
# version:
ifeq ($(GITHUB_BRANCH_NAME),)
BRANCH := $(shell git rev-parse --abbrev-ref HEAD)-
else
BRANCH := $(GITHUB_BRANCH_NAME)-
endif
ifeq ($(GITHUB_SHA),)
COMMIT := $(shell git describe --no-match --dirty --always --abbrev=8)
else
COMMIT := $(shell echo $(GITHUB_SHA) | cut -c1-8)
endif
VERSION ?= $(if $(RELEASE_TAG),$(RELEASE_TAG),$(shell $(CMD_GIT) describe --tags 2>/dev/null || echo '$(BRANCH)$(COMMIT)'))
# inputs and outputs:
OUT_DIR ?= dist
GO_SRC := $(shell find . -type f -name '*.go')
OUT_BIN := $(OUT_DIR)/parca-debuginfo
OUT_DOCKER ?= ghcr.io/parca-dev/parca-debuginfo
OUT_DOCKER_DEV ?= parca-dev/parca-debuginfo
.PHONY: all
all: build
$(OUT_DIR):
mkdir -p $@
.PHONY: build
build: $(OUT_BIN)
GO_ENV := CGO_ENABLED=0 GOOS=linux GOARCH=$(ARCH)
GO_BUILD_FLAGS := -tags osusergo,netgo -mod=readonly -trimpath -v
$(OUT_BIN): $(filter-out *_test.go,$(GO_SRC)) go/deps | $(OUT_DIR)
find dist -exec touch -t 202101010000.00 {} +
$(GO) build -trimpath -v -o $(OUT_BIN) ./cmd/parca-debuginfo
.PHONY: go/deps
go/deps:
$(GO) mod tidy
# static analysis:
lint: check-license go/lint vet
.PHONY: check-license
check-license:
./scripts/check-license.sh
.PHONY: go/lint
go/lint:
$(CMD_GOLANGCI_LINT) run
.PHONY: test
test: $(GO_SRC)
$(GO_ENV) $(CGO_ENV) $(GO) test -v $(shell $(GO) list ./...)
.PHONY: format
format:
$(GO) fmt $(shell $(GO) list ./...)
.PHONY: vet
vet: $(GO_SRC)
$(GO_ENV) $(CGO_ENV) $(GO) vet -v $(shell $(GO) list ./...)
# clean:
.PHONY: mostlyclean
mostlyclean:
-rm -rf $(OUT_BIN)
.PHONY: clean
clean: mostlyclean
-rm -rf $(OUT_DIR)
# container:
.PHONY: container
container: $(OUT_DIR)
podman build \
--platform linux/amd64,linux/arm64 \
--timestamp 0 \
--manifest $(OUT_DOCKER):$(VERSION) .
.PHONY: container-dev
container-dev:
docker build -t $(OUT_DOCKER_DEV):$(VERSION) --build-arg=GOLANG_BASE=golang:1.18.3-bullseye --build-arg=DEBIAN_BASE=debian:bullseye-slim .
.PHONY: sign-container
sign-container:
crane digest $(OUT_DOCKER):$(VERSION)
cosign sign --force -a GIT_HASH=$(COMMIT) -a GIT_VERSION=$(VERSION) $(OUT_DOCKER)@$(shell crane digest $(OUT_DOCKER):$(VERSION))
.PHONY: push-container
push-container:
podman manifest push --all $(OUT_DOCKER):$(VERSION) docker://$(OUT_DOCKER):$(VERSION)
.PHONY: push-local-container
push-local-container:
podman push $(OUT_DOCKER):$(VERSION) docker-daemon:docker.io/$(OUT_DOCKER):$(VERSION)
# other artifacts:
$(OUT_DIR)/help.txt: $(OUT_BIN)
$(OUT_BIN) --help > $@
README.md: $(OUT_DIR)/help.txt
$(CMD_EMBEDMD) -w README.md
# test cross-compile release pipeline:
.PHONY: release-dry-run
release-dry-run:
$(CMD_GORELEASER) release --rm-dist --auto-snapshot --skip-validate --skip-publish --debug
.PHONY: release-build
release-build:
$(CMD_GORELEASER) build --rm-dist --skip-validate --snapshot --debug