forked from opensbom-generator/spdx-sbom-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
87 lines (70 loc) · 2.96 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
# SPDX-License-Identifier: Apache-2.0
# It's necessary to set this because some environments don't link sh -> bash.
SHELL := /usr/bin/env bash
BUILD_TIME=$(shell sh -c 'date +%FT%T%z')
VERSION := $(shell sh -c 'git describe --always --tags')
BRANCH := $(shell sh -c 'git rev-parse --abbrev-ref HEAD')
COMMIT := $(shell sh -c 'git rev-parse --short HEAD')
GO_FILES=$(shell find . -type f -name '*.go' -not -path './vendor/*')
PKG_LIST := $(shell go list ./... | grep -v mock)
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.branch=$(BRANCH) -X main.buildDate=$(BUILD_TIME)"
ROOT_DIR:=$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))
LINT_TOOL=$(shell go env GOPATH)/bin/golangci-lint
LINT_VERSION=v1.37.0
.PHONY: help
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
.PHONY: setup
setup: $(LINT_TOOL)
.PHONY: mod
mod:
@go mod download
@go mod tidy
.PHONY: generator
generate: mod
@echo "Running cli on version: $(VERSION)"
@GO111MODULE=on GLFLAGs=-mod-vendor go run cmd/generator/generator.go $(ARGS)
.PHONY: build
build: mod
@echo "Building spdx-sbom-generator for Linux Intel/AMD 64-bit version: $(VERSION)"
env GOOS=linux GOARCH=amd64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator cmd/generator/generator.go
@chmod +x bin/spdx-sbom-generator
.PHONY: build-mac
build-mac: mod
@echo "Building spdx-sbom-generator for Mac Intel/AMD 64-bit version: $(VERSION)"
@env GOOS=darwin GOARCH=amd64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator cmd/generator/generator.go
@chmod +x bin/spdx-sbom-generator
.PHONY: build-mac-arm64
build-mac-arm64: mod
@echo "Building spdx-sbom-generator for Mac ARM 64-bit version: $(VERSION)"
@env GOOS=darwin GOARCH=arm64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator cmd/generator/generator.go
@chmod +x bin/spdx-sbom-generator
.PHONY: build-win
build-win: mod
@echo "Building spdx-sbom-generator for Windows Intel/AMD 64-bit version: $(VERSION)"
env GOOS=windows GOARCH=amd64 go build $(LD_FLAGS) -o bin/spdx-sbom-generator.exe cmd/generator/generator.go
@chmod +x bin/spdx-sbom-generator.exe
$(LINT_TOOL):
@echo "Installing golangci linter version $(LINT_VERSION)..."
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(shell go env GOPATH)/bin $(LINT_VERSION)
.PHONY: go-lint
go-lint:
echo "Running lint..." && $(LINT_TOOL) --version && $(LINT_TOOL) run --allow-parallel-runners --config=.golangci.yaml ./... && echo "Lint check passed."
.PHONY: check-headers
check-headers:
@echo "Running license header check..."
$(ROOT_DIR)/check-headers.sh
fmt:
@gofmt -w -l -s $(GO_FILES)
@goimports -w -l $(GO_FILES)
.PHONY: lint
lint: go-lint check-headers
.PHONY: test
test: prepare-test
@echo "IMPLEMENT TEST"
@go test -v $(PKG_LIST)
.PHONY: prepare-test
prepare-test:
@cd pkg/modules/npm/test && npm install
@cd pkg/modules/yarn/test && yarn install
@cd pkg/modules/swift/test && swift build