8000 add more tests in makefile and detect go version by dmachard · Pull Request #502 · dmachard/DNS-collector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add more tests in makefile and detect go version #502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 25 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
0