Skip to content

Commit

Permalink
Bring Makefile improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiught committed Jan 4, 2024
1 parent 44df671 commit 6bb1d18
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ jobs:
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
version: latest
args: -v -c .golangci.yaml

audit:
name: Security Audits
Expand Down
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
run:
timeout: 3m
modules-download-mode: readonly
allow-parallel-runners: true

linters:
enable-all: true
Expand Down
60 changes: 45 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
BINARY_NAME=fga
BUILD_FOLDER=dist
#-----------------------------------------------------------------------------------------------------------------------
# Variables (https://www.gnu.org/software/make/manual/html_node/Using-Variables.html#Using-Variables)
#-----------------------------------------------------------------------------------------------------------------------
BINARY_NAME = fga
BUILD_DIR ?= $(CURDIR)/dist
GO_BIN ?= $(shell go env GOPATH)/bin

all: build
#-----------------------------------------------------------------------------------------------------------------------
# Rules (https://www.gnu.org/software/make/manual/html_node/Rule-Introduction.html#Rule-Introduction)
#-----------------------------------------------------------------------------------------------------------------------
$(GO_BIN)/golangci-lint:
@echo "==> Installing golangci-lint within "${GO_BIN}""
@go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest

build:
go build -o ${BUILD_FOLDER}/${BINARY_NAME} main.go
$(GO_BIN)/govulncheck:
@echo "==> Installing govulncheck within "${GO_BIN}""
@go install -v golang.org/x/vuln/cmd/govulncheck@latest

$(GO_BIN)/gofumpt:
@echo "==> Installing gofumpt within "${GO_BIN}""
@go install -v mvdan.cc/gofumpt@latest

$(GO_BIN)/gci:
@echo "==> Installing gci within "${GO_BIN}""
@go install -v github.com/daixiang0/gci@latest

$(BUILD_DIR)/$(BINARY_NAME):
@echo "==> Building binary within ${BUILD_DIR}/${BINARY_NAME}"
go build -v -o ${BUILD_DIR}/${BINARY_NAME} main.go

.PHONY: build run clean test lint audit format

build: $(BUILD_DIR)/$(BINARY_NAME)

run: build
./${BUILD_FOLDER}/${BINARY_NAME}
run: $(BUILD_DIR)/$(BINARY_NAME)
${BUILD_DIR}/${BINARY_NAME} $(ARGS)

clean:
@echo "==> Cleaning project files"
go clean
rm -f ${BUILD_FOLDER}
rm -f ${BUILD_DIR}

test:
go test -race \
Expand All @@ -24,12 +51,15 @@ test:
@cat coverageunit.tmp.out | grep -v "mocks" > coverageunit.out
@rm coverageunit.tmp.out

lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest && golangci-lint run
lint: $(GO_BIN)/golangci-lint
@echo "==> Linting Go source files"
@golangci-lint run -v --fix -c .golangci.yaml ./...

audit:
go install golang.org/x/vuln/cmd/govulncheck@latest && govulncheck ./...;
audit: $(GO_BIN)/govulncheck
@echo "==> Checking Go source files for vulnerabilities"
govulncheck ./...

format:
go install mvdan.cc/gofumpt@latest && gofumpt -w .
go install github.com/daixiang0/gci@latest && gci write -s standard -s default .
format: $(GO_BIN)/gofumpt $(GO_BIN)/gci
@echo "==> Formatting project files"
gofumpt -w .
gci write -s standard -s default .

0 comments on commit 6bb1d18

Please sign in to comment.