-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from JoseLSegura/setup_tooling
Initial set of tools for running local checks from the beginning
- Loading branch information
Showing
13 changed files
with
371 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
insights-results-smart-proxy | ||
coverage.out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
.PHONY: default clean build fmt lint vet cyclo ineffassign shellcheck errcheck goconst gosec abcgo json-check style run test cover integration_tests rest_api_tests rules_content sqlite_db license before_commit help | ||
|
||
SOURCES:=$(shell find . -name '*.go') | ||
|
||
default: build | ||
|
||
clean: ## Run go clean | ||
@go clean | ||
|
||
build: ## Run go build | ||
./build.sh | ||
|
||
fmt: ## Run go fmt -w for all sources | ||
@echo "Running go formatting" | ||
./gofmt.sh | ||
|
||
lint: ## Run golint | ||
@echo "Running go lint" | ||
./golint.sh | ||
|
||
vet: ## Run go vet. Report likely mistakes in source code | ||
@echo "Running go vet" | ||
./govet.sh | ||
|
||
cyclo: ## Run gocyclo | ||
@echo "Running gocyclo" | ||
./gocyclo.sh | ||
|
||
ineffassign: ## Run ineffassign checker | ||
@echo "Running ineffassign checker" | ||
./ineffassign.sh | ||
|
||
shellcheck: ## Run shellcheck | ||
shellcheck *.sh | ||
|
||
errcheck: ## Run errcheck | ||
@echo "Running errcheck" | ||
./goerrcheck.sh | ||
|
||
goconst: ## Run goconst checker | ||
@echo "Running goconst checker" | ||
./goconst.sh | ||
|
||
gosec: ## Run gosec checker | ||
@echo "Running gosec checker" | ||
./gosec.sh | ||
|
||
abcgo: ## Run ABC metrics checker | ||
@echo "Run ABC metrics checker" | ||
./abcgo.sh | ||
|
||
style: fmt vet lint cyclo shellcheck errcheck goconst gosec ineffassign abcgo ## Run all the formatting related commands (fmt, vet, lint, cyclo) + check shell scripts | ||
|
||
run: clean build ## Build the project and executes the binary | ||
./insights-results-smart-proxy | ||
|
||
test: clean build ## Run the unit tests | ||
go test -coverprofile coverage.out $(shell go list ./... | grep -v tests) | ||
|
||
cover: test | ||
@go tool cover -html=coverage.out | ||
|
||
license: | ||
GO111MODULE=off go get -u github.com/google/addlicense && \ | ||
addlicense -c "Red Hat, Inc" -l "apache" -v ./ | ||
|
||
before_commit: style test integration_tests license | ||
./check_coverage.sh | ||
|
||
help: ## Show this help screen | ||
@echo 'Usage: make <OPTIONS> ... <TARGETS>' | ||
@echo '' | ||
@echo 'Available targets are:' | ||
@echo '' | ||
@grep -E '^[ a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \ | ||
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' | ||
@echo '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
threshold=45 | ||
|
||
BLUE=$(tput setaf 4) | ||
RED_BG=$(tput setab 1) | ||
GREEN_BG=$(tput setab 2) | ||
NC=$(tput sgr0) # No Color | ||
|
||
VERBOSE=false | ||
|
||
if [[ $* == *verbose* ]]; then | ||
VERBOSE=true | ||
fi | ||
|
||
GO111MODULE=off go get -u github.com/droptheplot/abcgo | ||
|
||
if [ "$VERBOSE" = true ]; then | ||
echo -e "${BLUE}All ABC metrics${NC}:" | ||
abcgo -path . | ||
echo -e "${BLUE}Functions with ABC metrics greater than ${threshold}${NC}:" | ||
fi | ||
|
||
if [[ $(abcgo -path . -sort -format raw | awk "\$4>${threshold}" | tee /dev/tty | wc -l) -ne 0 ]] | ||
then | ||
echo -e "${RED_BG}[FAIL]${NC} Functions with too high ABC metrics detected!" | ||
exit 1 | ||
else | ||
echo -e "${GREEN_BG}[OK]${NC} ABC metrics are ok for all functions in all packages" | ||
exit 0 | ||
fi | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# this is improper - we need to start using tags in GitHub properly | ||
version=0.5 | ||
|
||
buildtime=$(date) | ||
branch=$(git rev-parse --abbrev-ref HEAD) | ||
commit=$(git rev-parse HEAD) | ||
|
||
go build -ldflags="-X 'main.BuildTime=$buildtime' -X 'main.BuildVersion=$version' -X 'main.BuildBranch=$branch' -X 'main.BuildCommit=$commit'" | ||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
THRESHOLD=0 | ||
|
||
RED_BG=$(tput setab 1) | ||
GREEN_BG=$(tput setab 2) | ||
NC=$(tput sgr0) # No Color | ||
|
||
go_tool_cover_output=$(go tool cover -func=coverage.out) | ||
|
||
if [[ $* == *verbose* ]]; then | ||
echo "$go_tool_cover_output" | ||
fi | ||
|
||
if (( $(echo "$go_tool_cover_output" | tail -n 1 | awk '{print $NF}' | grep -E "^[0-9]+" -o) >= THRESHOLD )); then | ||
echo -e "${GREEN_BG}[OK]${NC} Code coverage is OK" | ||
exit 0 | ||
else | ||
echo "$go_tool_cover_output" | ||
echo -e "${RED_BG}[FAIL]${NC} Code coverage have to be at least $THRESHOLD%" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
GO111MODULE=off go get github.com/jgautheron/goconst/cmd/goconst | ||
|
||
if [[ $(goconst -min-occurrences=3 ./... | tee /dev/tty | wc -l) -ne 0 ]] | ||
then | ||
echo "Duplicated string(s) found" | ||
exit 1 | ||
else | ||
echo "No duplicated strings found" | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
GO111MODULE=off go get github.com/fzipp/gocyclo | ||
gocyclo -over 9 -avg . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
GO111MODULE=off go get github.com/kisielk/errcheck | ||
errcheck ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
if [ -n "$(gofmt -l .)" ]; then | ||
echo "Go code is not formatted:" | ||
gofmt -d . | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
cd "$(dirname "$0")" || exit | ||
|
||
GO111MODULE=off go get golang.org/x/lint/golint 2> /dev/null | ||
|
||
# shellcheck disable=SC2046 | ||
if golint $(go list ./...) | | ||
grep -v ALL_CAPS | | ||
grep .; then | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
RED_BG=$(tput setab 1) | ||
GREEN_BG=$(tput setab 2) | ||
BLUE=$(tput setaf 4) | ||
NC=$(tput sgr0) # No Color | ||
|
||
GO_SEC_ARGS="" | ||
|
||
if [[ $* != *verbose* ]]; then | ||
GO_SEC_ARGS="-quiet" | ||
fi | ||
|
||
cd "$(dirname "$0")" || exit | ||
|
||
echo -e "${BLUE}Security issues detection${NC}" | ||
|
||
GO111MODULE=off go get github.com/securego/gosec/cmd/gosec 2> /dev/null | ||
|
||
if ! gosec $GO_SEC_ARGS ./... | ||
then | ||
echo -e "${RED_BG}[FAIL]${NC} Potential security issues detected!" | ||
exit 1 | ||
else | ||
echo -e "${GREEN_BG}[OK]${NC} No potential security issues has been detected" | ||
exit 0 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
cd "$(dirname "$0")" || exit | ||
|
||
# shellcheck disable=SC2046 | ||
go vet $(go list ./...) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
# Copyright 2020 Red Hat, Inc | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
GO111MODULE=off go get github.com/gordonklaus/ineffassign | ||
ineffassign . |