From 2f1e8ab06c105d017d15572217efeab75ca70bfa Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Tue, 12 Sep 2023 17:22:24 +0200 Subject: [PATCH] Add more commands to the Makefile and use them in CI (#24) * Add more commands to the Makefile and use them in CI Signed-off-by: Philippe Martin * Make check_registry.sh executable Signed-off-by: Philippe Martin * Move scripts to ./scripts directory Signed-off-by: Philippe Martin --------- Signed-off-by: Philippe Martin --- .github/workflows/CI.yml | 5 ++--- .github/workflows/check_registry.yaml | 2 +- Makefile | 28 +++++++++++++++++++++------ run_gosec.sh => scripts/run_gosec.sh | 2 +- test/check_registry/check_registry.sh | 0 5 files changed, 26 insertions(+), 11 deletions(-) rename run_gosec.sh => scripts/run_gosec.sh (60%) mode change 100644 => 100755 test/check_registry/check_registry.sh diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2daed1ed..545d01b3 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -33,9 +33,8 @@ jobs: - name: Run Gosec Security Scanner run: | - export PATH=$PATH:$(go env GOPATH)/bin - go install github.com/securego/gosec/v2/cmd/gosec@v2.14.0 - ./run_gosec.sh + make gosec_install + PATH=$PATH:$(go env GOPATH)/bin make gosec if [[ $? != 0 ]] then echo "gosec scanner failed to run " diff --git a/.github/workflows/check_registry.yaml b/.github/workflows/check_registry.yaml index abb7986f..d8e6af5e 100644 --- a/.github/workflows/check_registry.yaml +++ b/.github/workflows/check_registry.yaml @@ -32,4 +32,4 @@ jobs: id: build run: | make build - bash test/check_registry/check_registry.sh \ No newline at end of file + make check_registry diff --git a/Makefile b/Makefile index 3b02c6bb..ff2f8c98 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,35 @@ +.PHONY: help +help: ## Show this help + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) + .PHONY: gomod_tidy -gomod_tidy: +gomod_tidy: ## Update Go mod dependencies go mod tidy .PHONY: gofmt -gofmt: +gofmt: ## Run Go formatting checks go fmt -x ./... .PHONY: build -build: +build: ## Build executable without extension (Unix) go build -o alizer .PHONY: buildWin -buildWin: +buildWin: ## Build executable with Windows .exe extension go build -o alizer.exe .PHONY: test -test: - go test -coverprofile cover.out -v ./... \ No newline at end of file +test: ## Run unit tests with coverage + go test -coverprofile cover.out -v ./... + +.PHONY: check_registry +check_registry: ## Run registry checks + ./test/check_registry/check_registry.sh + +.PHONY: gosec_install +gosec_install: ## Install gosec utility + go install github.com/securego/gosec/v2/cmd/gosec@v2.14.0 + +.PHONY: gosec +gosec: ## Run go security checks + ./scripts/run_gosec.sh diff --git a/run_gosec.sh b/scripts/run_gosec.sh similarity index 60% rename from run_gosec.sh rename to scripts/run_gosec.sh index 8023217a..1dbe7ac0 100755 --- a/run_gosec.sh +++ b/scripts/run_gosec.sh @@ -3,7 +3,7 @@ if ! command -v gosec 2> /dev/null then - echo "error gosec must be installed with this command: go install github.com/securego/gosec/v2/cmd/gosec@v2.14.0" && exit 1 + echo "error gosec must be installed with this command: make gosec_install" && exit 1 fi gosec -no-fail -fmt=sarif -out=gosec.sarif -exclude-dir test -exclude-dir generator ./... diff --git a/test/check_registry/check_registry.sh b/test/check_registry/check_registry.sh old mode 100644 new mode 100755