Skip to content

Commit

Permalink
Refactoring Makefile (Checkmarx#2238)
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeriopeixotocx authored Mar 15, 2021
1 parent 8408e7f commit 9c8af30
Show file tree
Hide file tree
Showing 10 changed files with 1,323 additions and 36 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ jobs:
with:
version: v1.37
skip-go-installation: true
go-generate:
name: go-generate
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.16.x
- name: Check out code
uses: actions/checkout@v2
with:
persist-credentials: false
fetch-depth: 0
- name: Generate mocks and marshall/unmarshall code
run: make generate
unit-tests:
name: unit-tests
strategy:
Expand Down
94 changes: 79 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,92 @@
########################
# GNU Makefile #
# Golang SDK required #
########################
.DEFAULT_GOAL := help
GOLINT := golangci-lint
IMAGE_TAG := $(shell git rev-parse HEAD)

.PHONY: dep
dep: # Download required dependencies
.PHONY: clean
clean: ## remove files created during build
$(call print-target)
rm -rf dist
rm -rf bin
rm -rf vendor
rm -f coverage.*

.PHONY: mod-tidy
mod-tidy: ## go mod tidy - download and cleanup modules
$(call print-target)
go mod tidy
go mod download
cd tools && go mod tidy

.PHONY: vendor
vendor: ## go mod vendor - download vendor modules
$(call print-target)
go mod vendor

.PHONY: install
install: ## go install tools
$(call print-target)
cd tools && go install $(shell cd tools && go list -f '{{ join .Imports " " }}' -tags=tools)

.PHONY: lint
lint: dep # Lint the files
lint: ## Lint the files
lint: mod-tidy
$(call print-target)
$(GOLINT) run -c .golangci.yml

.PHONY: gen
gen:
go get -u github.com/mailru/easyjson/...
easyjson pkg/model/model.go
.PHONY: build
build: ## go build
build: lint generate
$(call print-target)
go build -o bin/ -ldflags "-X github.com/Checkmarx/kics/internal/constants.Version=${IMAGE_TAG}" ./...
@mv bin/console bin/kics

.PHONY: go-clean
go-clean: ## Go clean build, test and modules caches
$(call print-target)
go clean -r -i -cache -testcache -modcache

.PHONY: generate
generate: mod-tidy ## go generate
$(call print-target)
go generate ./...

.PHONY: test
test: dep # Run unit tests
test-short: # Run sanity unit tests
test-short: generate
$(call print-target)
go test -short ./...

.PHONY: dockerise
dockerise:
docker build --build-arg GIT_USER=$(GITHUB_USER) --build-arg GIT_TOKEN=$(GITHUB_TOKEN) -t "kics:${IMAGE_TAG}" .
.PHONY: test
test: ## Run tests with race detector and code covarage
test: generate
$(call print-target)
go test -race -covermode=atomic -coverprofile=coverage.out ./...
go tool cover -html=coverage.out -o coverage.html

.PHONY: cover
cover: ## generate coverage report
cover: test
$(call print-target)
go tool cover -html=coverage.out -o coverage.html

.PHONY: docker
docker: ## build docker image
$(call print-target)
docker build -t "kics:${IMAGE_TAG}" .

.PHONY: release
release: ## goreleaser --rm-dist
release: install
$(call print-target)
goreleaser --rm-dist

.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: mock
mock:
mockgen -package mock -source pkg/engine/source/source.go > pkg/engine/mock/source.go
define print-target
@printf "Executing target: \033[36m$@\033[0m\n"
endef
10 changes: 2 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.2.2/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
github.com/googleapis/gnostic v0.4.1/go.mod h1:LRhVm6pbyptWbWbuZ38d1eyptfvIytN3ir6b65WBswg=
github.com/gookit/color v1.2.4 h1:xOYBan3Fwlrqj1M1UN2TlHOCRiek3bGzWf/vPnJ1roE=
github.com/gookit/color v1.2.4/go.mod h1:AhIE+pS6D4Ql0SQWbBeXPHw7gY0/sjHoA4s/n1KB7xg=
github.com/gookit/color v1.3.8 h1:w2WcSwaCa1ojRWO60Mm4GJUJomBNKR9G+x9DwaaCL1c=
github.com/gookit/color v1.3.8/go.mod h1:R3ogXq2B9rTbXoSHJ1HyUVAZ3poOJHpd9nQmyGZsfvQ=
Expand Down Expand Up @@ -563,8 +562,6 @@ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/hcl/v2 v2.9.0 h1:7kJiMiKBqGHASbDJuFAMlpRMJLyhuLg/IsU/3EzwniA=
github.com/hashicorp/hcl/v2 v2.9.0/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
github.com/hashicorp/hcl/v2 v2.9.1 h1:eOy4gREY0/ZQHNItlfuEZqtcQbXIxzojlP301hDpnac=
github.com/hashicorp/hcl/v2 v2.9.1/go.mod h1:FwWsfWEjyV/CMj8s/gqAuiviY72rJ1/oayI9WftqcKg=
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
Expand Down Expand Up @@ -772,8 +769,6 @@ github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7J
github.com/onsi/gomega v1.8.1/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/onsi/gomega v1.9.0/go.mod h1:Ho0h+IUsWyvy1OpqCwxlQ/21gkhVunqlU8fDGcoTdcA=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/open-policy-agent/opa v0.26.0 h1:FI0woFdGA73reU8OzSMzgHLFK+XeDMxKIlBpvvpRqDQ=
github.com/open-policy-agent/opa v0.26.0/go.mod h1:iGThTRECCfKQKICueOZkXUi0opN7BR3qiAnIrNHCmlI=
github.com/open-policy-agent/opa v0.27.0 h1:7aOP0bTdohk3lN8VWHRm+075lhkPiVoRJTWUygppRC4=
github.com/open-policy-agent/opa v0.27.0/go.mod h1:0LeBOluVCvxLgPT/RXPzd9q+4vRL6R1K2H0EAIDenQY=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
Expand Down Expand Up @@ -1001,7 +996,6 @@ github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/
github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/uudashr/gocognit v1.0.1/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
Expand All @@ -1017,8 +1011,6 @@ github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6Ac
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/vmware/govmomi v0.20.3/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59bHWk6aFU=
github.com/wasmerio/go-ext-wasm v0.3.1 h1:G95XP3fE2FszQSwIU+fHPBYzD0Csmd2ef33snQXNA5Q=
github.com/wasmerio/go-ext-wasm v0.3.1/go.mod h1:VGyarTzasuS7k5KhSIGpM3tciSZlkP31Mp9VJTHMMeI=
github.com/willf/bitset v1.1.11-0.20200630133818-d5bec3311243/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4=
github.com/willf/bitset v1.1.11/go.mod h1:83CECat5yLh5zVOf4P1ErAgKA5UDvKtgyUABdr3+MjI=
github.com/xanzy/go-gitlab v0.31.0/go.mod h1:sPLojNBn68fMUWSxIJtdVVIP8uSBYqesTfDUseX11Ug=
Expand Down Expand Up @@ -1127,6 +1119,7 @@ golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down Expand Up @@ -1352,6 +1345,7 @@ golang.org/x/tools v0.0.0-20200501065659-ab2804fb9c9d/go.mod h1:EkVYQZoAsY45+roY
golang.org/x/tools v0.0.0-20200502202811-ed308ab3e770/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200512131952-2bc93b1c0c88/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20201009032223-96877f285f7e h1:G1acLyqfyttmexrW7XPhzsaS8m6s+P9XsW9djwh10s4=
golang.org/x/tools v0.0.0-20201009032223-96877f285f7e/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 1 addition & 1 deletion pkg/engine/mock/source.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/engine/source/source.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate go run -mod=mod github.com/golang/mock/mockgen -package mock -source=./$GOFILE -destination=../mock/$GOFILE
package source

import "github.com/Checkmarx/kics/pkg/model"
Expand Down
3 changes: 3 additions & 0 deletions pkg/model/model.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
//go:generate go run -mod=mod github.com/mailru/easyjson/easyjson ./$GOFILE
package model

import (
"sort"
"strings"

_ "github.com/mailru/easyjson/gen" //nolint
)

// Constants to describe what kind of file refers
Expand Down
24 changes: 12 additions & 12 deletions pkg/model/model_easyjson.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions tools/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/Checkmarx/kics/tools

go 1.16

require (
github.com/golangci/golangci-lint v1.37.1
github.com/goreleaser/goreleaser v0.159.0
)
Loading

0 comments on commit 9c8af30

Please sign in to comment.