From 2186bcbb7e4234d8b18d42cdf86ce3254de7c05b Mon Sep 17 00:00:00 2001 From: dmachard <5562930+dmachard@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:13:14 +0100 Subject: [PATCH 1/2] add more test in makefile --- .github/workflows/build.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 44ddeeea..c4be1b04 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -32,9 +32,15 @@ jobs: with: go-version: ${{ matrix.go-version }} - - name: build binary from make file + - name: build binary from makefile run: make build + - name: dep from makefile + run: make dep + + - name: dep+build from makefile + run: make + go-ubuntu: runs-on: ubuntu-latest From bc5cf8e4323b734a698694738c4cd2c93b5c6c35 Mon Sep 17 00:00:00 2001 From: dmachard <5562930+dmachard@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:36:11 +0100 Subject: [PATCH 2/2] detect go version --- Makefile | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 0d5f2c3d..fc139328 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ BINARY_NAME := go-dnscollector -GO_VERSION := 1.21 +GO_VERSION := $(shell go env GOVERSION | sed -n 's/go\([0-9]\+\.[0-9]\+\).*/\1/p') + GO_LOGGER := 0.4.0 GO_POWERDNS_PROTOBUF := 0.2.0 GO_DNSTAP_PROTOBUF := 0.6.0 @@ -25,11 +26,20 @@ ifndef $(GOPATH) export GOPATH endif -.PHONY: all dep lint build clean +.PHONY: all check-go dep lint build clean goversion + +# This target depends on dep and build. +all: check-go dep build -all: dep build +check-go: + @command -v go > /dev/null 2>&1 || { echo >&2 "Go is not installed. Please install it before proceeding."; exit 1; } -dep: +# Displays the Go version. +goversion: check-go + @echo "Go version: $(GO_VERSION)" + +# Installs project dependencies. +dep: check-go @go get github.com/dmachard/go-logger@v$(GO_LOGGER) @go get github.com/dmachard/go-powerdns-protobuf@v$(GO_POWERDNS_PROTOBUF) @go get github.com/dmachard/go-dnstap-protobuf@v$(GO_DNSTAP_PROTOBUF) @@ -38,19 +48,24 @@ dep: @go mod edit -go=$(GO_VERSION) @go mod tidy -build: +# Builds the project using go build. +build: check-go CGO_ENABLED=0 go build -v -ldflags="$(LD_FLAGS)" -o ${BINARY_NAME} dnscollector.go multiplexer.go +# Builds and runs the project. run: build ./${BINARY_NAME} +# Builds and runs the project with the -v flag. version: build ./${BINARY_NAME} -v +# Runs linters. lint: $(GOPATH)/bin/golangci-lint run --config=.golangci.yml ./... - -tests: + +# Runs various tests for different packages. +tests: check-go @go test -race -cover -v @go test ./pkgconfig/ -race -cover -v @go test ./dnsutils/ -race -cover -v @@ -60,5 +75,7 @@ tests: @go test -timeout 90s ./loggers/ -race -cover -v @go test -timeout 30s ./processors/ -race -cover -v -clean: +# Cleans the project using go clean. +clean: check-go @go clean + @rm -f $(BINARY_NAME)