forked from interlynk-io/sbomasm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
181 lines (148 loc) · 5.6 KB
/
Makefile
File metadata and controls
181 lines (148 loc) · 5.6 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Copyright 2023 Interlynk.io
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Inspired by https://github.com/pinterb/go-semver/blob/master/Makefile
.DEFAULT_GOAL := help
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
else
GOBIN=$(shell go env GOBIN)
endif
# Version information
GIT_VERSION ?= $(shell git describe --tags --always --dirty)
GIT_HASH ?= $(shell git rev-parse HEAD)
DATE_FMT = +%Y-%m-%dT%H:%M:%SZ
SOURCE_DATE_EPOCH ?= $(shell git log -1 --pretty=%ct)
ifdef SOURCE_DATE_EPOCH
BUILD_DATE ?= $(shell date -u -d "@$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u -r "$(SOURCE_DATE_EPOCH)" "$(DATE_FMT)" 2>/dev/null || date -u "$(DATE_FMT)")
else
BUILD_DATE ?= $(shell date -u "$(DATE_FMT)")
endif
GIT_TREESTATE = clean
DIFF = $(shell git diff --quiet >/dev/null 2>&1; if [ $$? -eq 1 ]; then echo "1"; fi)
ifeq ($(DIFF), 1)
GIT_TREESTATE = dirty
endif
# Build variables
PKG ?= sigs.k8s.io/release-utils/version
LDFLAGS = -buildid= -X $(PKG).gitVersion=$(GIT_VERSION) \
-X $(PKG).gitCommit=$(GIT_HASH) \
-X $(PKG).gitTreeState=$(GIT_TREESTATE) \
-X $(PKG).buildDate=$(BUILD_DATE)
BUILD_DIR = ./build
BINARY_NAME = sbomasm
TARGETOS ?= $(shell go env GOOS)
TARGETARCH ?= $(shell go env GOARCH)
##@ General
.PHONY: help
help: ## Display this help
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
##@ Development
.PHONY: deps
deps: ## Download dependencies
@echo "Downloading dependencies..."
@go mod download
@go mod tidy
.PHONY: generate
generate: ## Run go generate
@echo "Running go generate..."
@go generate ./...
.PHONY: fmt
fmt: ## Run go fmt
@echo "Formatting code..."
@go fmt ./...
.PHONY: vet
vet: ## Run go vet
@echo "Running go vet..."
@go vet ./...
.PHONY: lint
lint: ## Run golangci-lint (requires golangci-lint installed)
@echo "Running linter..."
@if command -v golangci-lint >/dev/null 2>&1; then \
golangci-lint run; \
else \
echo "golangci-lint not found. Install it from https://golangci-lint.run/"; \
fi
##@ Testing
.PHONY: test
test: generate ## Run tests
@echo "Running tests..."
@go test -v -cover -race -failfast -p 1 ./...
.PHONY: test-coverage
test-coverage: generate ## Run tests with coverage report
@echo "Running tests with coverage..."
@go test -v -coverprofile=coverage.out -covermode=atomic ./...
@go tool cover -html=coverage.out -o coverage.html
@echo "Coverage report generated: coverage.html"
.PHONY: test-short
test-short: ## Run short tests
@echo "Running short tests..."
@go test -short -v ./...
##@ Building
.PHONY: build
build: ## Build binary for current platform
@echo "Building $(BINARY_NAME) for $(TARGETOS)/$(TARGETARCH)..."
@mkdir -p $(BUILD_DIR)
@CGO_ENABLED=0 GOOS=$(TARGETOS) GOARCH=$(TARGETARCH) go build -mod=readonly -trimpath -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME) .
.PHONY: build-all
build-all: ## Build binaries for all platforms
@echo "Building for all platforms..."
@mkdir -p $(BUILD_DIR)
@GOOS=linux GOARCH=amd64 go build -mod=readonly -trimpath -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-amd64 .
@GOOS=linux GOARCH=arm64 go build -mod=readonly -trimpath -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-linux-arm64 .
@GOOS=darwin GOARCH=amd64 go build -mod=readonly -trimpath -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-amd64 .
@GOOS=darwin GOARCH=arm64 go build -mod=readonly -trimpath -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-darwin-arm64 .
@GOOS=windows GOARCH=amd64 go build -mod=readonly -trimpath -ldflags "$(LDFLAGS)" -o $(BUILD_DIR)/$(BINARY_NAME)-windows-amd64.exe .
@echo "Build complete. Binaries in $(BUILD_DIR)/"
.PHONY: install
install: build ## Install binary to GOBIN
@echo "Installing $(BINARY_NAME) to $(GOBIN)..."
@install -m 755 $(BUILD_DIR)/$(BINARY_NAME) $(GOBIN)/$(BINARY_NAME)
@echo "Installed to $(GOBIN)/$(BINARY_NAME)"
##@ Release
.PHONY: snapshot
snapshot: ## Create a snapshot release (without publishing)
@echo "Creating snapshot release..."
@goreleaser release --clean --snapshot --skip=publish
.PHONY: release
release: ## Create a release (requires proper git tag)
@echo "Creating release..."
@goreleaser release --clean
##@ Maintenance
.PHONY: clean
clean: ## Clean build artifacts
@echo "Cleaning..."
@rm -rf $(BUILD_DIR) dist/ coverage.out coverage.html
.PHONY: clean-all
clean-all: clean ## Clean all artifacts including caches
@echo "Cleaning all artifacts..."
@go clean -cache -testcache -modcache
.PHONY: update-deps
update-deps: ## Update all dependencies
@echo "Updating dependencies..."
@go get -u ./...
@go mod tidy
.PHONY: tidy
tidy: ## Run go mod tidy
@echo "Tidying go.mod..."
@go mod tidy
##@ CI/CD
.PHONY: ci
ci: deps generate vet test ## Run CI pipeline locally
@echo "CI pipeline complete"
.PHONY: pre-commit
pre-commit: fmt vet lint test-short ## Run pre-commit checks
@echo "Pre-commit checks passed"