2018-03-12 22:57:10 +00:00
|
|
|
GIT_TAG?= $(shell git describe --always --tags)
|
2018-07-19 17:42:25 +01:00
|
|
|
BIN = gosec
|
2018-03-12 22:57:10 +00:00
|
|
|
FMT_CMD = $(gofmt -s -l -w $(find . -type f -name '*.go' -not -path './vendor/*') | tee /dev/stderr)
|
2018-08-19 01:28:17 +01:00
|
|
|
IMAGE_REPO = securego
|
2022-10-31 10:58:34 +00:00
|
|
|
DATE_FMT=+%Y-%m-%d
|
|
|
|
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 "$(DATE_FMT)")
|
|
|
|
endif
|
2021-07-30 15:58:13 +01:00
|
|
|
BUILDFLAGS := "-w -s -X 'main.Version=$(GIT_TAG)' -X 'main.GitTag=$(GIT_TAG)' -X 'main.BuildDate=$(BUILD_DATE)'"
|
2018-08-15 08:53:33 +01:00
|
|
|
CGO_ENABLED = 0
|
2019-05-02 08:19:18 +01:00
|
|
|
GO := GO111MODULE=on go
|
2020-01-06 08:47:28 +00:00
|
|
|
GOPATH ?= $(shell $(GO) env GOPATH)
|
|
|
|
GOBIN ?= $(GOPATH)/bin
|
|
|
|
GOSEC ?= $(GOBIN)/gosec
|
|
|
|
GINKGO ?= $(GOBIN)/ginkgo
|
2022-09-12 13:53:04 +01:00
|
|
|
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
|
|
|
|
GOVULN_MIN_VERSION = 17
|
2024-08-19 08:17:50 +01:00
|
|
|
GO_VERSION = 1.23
|
2018-03-12 22:57:10 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
$(MAKE) build
|
|
|
|
|
2020-03-26 21:43:52 +00:00
|
|
|
install-test-deps:
|
2022-01-03 17:11:35 +00:00
|
|
|
go install github.com/onsi/ginkgo/v2/ginkgo@latest
|
2023-08-18 16:05:17 +01:00
|
|
|
go install golang.org/x/crypto/...@latest
|
|
|
|
go install github.com/lib/pq/...@latest
|
2020-03-26 21:43:52 +00:00
|
|
|
|
2022-09-12 13:34:07 +01:00
|
|
|
install-govulncheck:
|
2022-09-12 13:56:34 +01:00
|
|
|
@if [ $(GO_MINOR_VERSION) -gt $(GOVULN_MIN_VERSION) ]; then \
|
|
|
|
go install golang.org/x/vuln/cmd/govulncheck@latest; \
|
|
|
|
fi
|
2022-09-12 13:34:07 +01:00
|
|
|
|
2023-10-18 14:03:58 +01:00
|
|
|
test: install-test-deps build-race fmt vet sec govulncheck
|
2022-01-03 17:11:35 +00:00
|
|
|
$(GINKGO) -v --fail-fast
|
2018-07-27 13:41:45 +01:00
|
|
|
|
2019-05-02 08:19:18 +01:00
|
|
|
fmt:
|
|
|
|
@echo "FORMATTING"
|
|
|
|
@FORMATTED=`$(GO) fmt ./...`
|
2022-01-03 19:26:14 +00:00
|
|
|
@([ ! -z "$(FORMATTED)" ] && printf "Fixed unformatted files:\n$(FORMATTED)") || true
|
2019-05-02 08:19:18 +01:00
|
|
|
|
2023-02-06 13:15:05 +00:00
|
|
|
vet:
|
2019-05-02 08:19:18 +01:00
|
|
|
@echo "VETTING"
|
2020-01-06 08:47:28 +00:00
|
|
|
$(GO) vet ./...
|
2019-05-02 08:19:18 +01:00
|
|
|
|
2022-03-21 15:53:22 +00:00
|
|
|
golangci:
|
|
|
|
@echo "LINTING: golangci-lint"
|
|
|
|
golangci-lint run
|
|
|
|
|
2020-01-06 08:47:28 +00:00
|
|
|
sec:
|
2019-05-02 08:19:18 +01:00
|
|
|
@echo "SECURITY SCANNING"
|
|
|
|
./$(BIN) ./...
|
|
|
|
|
2022-09-12 13:34:07 +01:00
|
|
|
govulncheck: install-govulncheck
|
|
|
|
@echo "CHECKING VULNERABILITIES"
|
2022-09-12 13:53:04 +01:00
|
|
|
@if [ $(GO_MINOR_VERSION) -gt $(GOVULN_MIN_VERSION) ]; then \
|
|
|
|
govulncheck ./...; \
|
|
|
|
fi
|
2022-09-12 13:34:07 +01:00
|
|
|
|
2020-03-26 21:43:52 +00:00
|
|
|
test-coverage: install-test-deps
|
2021-05-07 16:01:09 +01:00
|
|
|
go test -race -v -count=1 -coverprofile=coverage.out ./...
|
2018-12-11 16:08:31 +00:00
|
|
|
|
2018-03-12 22:57:10 +00:00
|
|
|
build:
|
2018-07-19 17:42:25 +01:00
|
|
|
go build -o $(BIN) ./cmd/gosec/
|
2018-07-27 13:41:45 +01:00
|
|
|
|
2023-10-18 14:00:50 +01:00
|
|
|
build-race:
|
|
|
|
go build -race -o $(BIN) ./cmd/gosec/
|
|
|
|
|
2018-03-12 22:57:10 +00:00
|
|
|
clean:
|
2024-06-24 18:16:32 +01:00
|
|
|
rm -rf build vendor dist coverage.out
|
2019-04-25 08:31:00 +01:00
|
|
|
rm -f release image $(BIN)
|
2018-07-27 13:41:45 +01:00
|
|
|
|
2020-01-06 08:47:28 +00:00
|
|
|
release:
|
2018-07-27 13:41:45 +01:00
|
|
|
@echo "Releasing the gosec binary..."
|
|
|
|
goreleaser release
|
2020-01-06 08:47:28 +00:00
|
|
|
|
2018-08-15 08:53:33 +01:00
|
|
|
build-linux:
|
2023-10-25 09:13:32 +01:00
|
|
|
CGO_ENABLED=$(CGO_ENABLED) GOOS=linux go build -ldflags=$(BUILDFLAGS) -o $(BIN) ./cmd/gosec/
|
2018-03-12 22:57:10 +00:00
|
|
|
|
2018-09-26 06:09:20 +01:00
|
|
|
image:
|
2018-03-12 22:57:10 +00:00
|
|
|
@echo "Building the Docker image..."
|
2020-04-09 12:01:40 +01:00
|
|
|
docker build -t $(IMAGE_REPO)/$(BIN):$(GIT_TAG) --build-arg GO_VERSION=$(GO_VERSION) .
|
2018-07-27 13:41:45 +01:00
|
|
|
docker tag $(IMAGE_REPO)/$(BIN):$(GIT_TAG) $(IMAGE_REPO)/$(BIN):latest
|
2018-03-12 22:57:10 +00:00
|
|
|
touch image
|
|
|
|
|
|
|
|
image-push: image
|
|
|
|
@echo "Pushing the Docker image..."
|
2018-08-19 01:28:17 +01:00
|
|
|
docker push $(IMAGE_REPO)/$(BIN):$(GIT_TAG)
|
2018-03-12 22:57:10 +00:00
|
|
|
docker push $(IMAGE_REPO)/$(BIN):latest
|
|
|
|
|
2023-02-15 19:44:13 +00:00
|
|
|
tlsconfig:
|
|
|
|
go generate ./...
|
2023-08-18 16:05:17 +01:00
|
|
|
|
2024-08-26 17:54:11 +01:00
|
|
|
perf-diff:
|
|
|
|
./perf-diff.sh
|
|
|
|
|
|
|
|
.PHONY: test build clean release image image-push tlsconfig perf-diff
|