Fix - Cleanup the makefile targets (#207)

This commit is contained in:
Naveen 2021-02-21 18:35:39 -05:00 committed by GitHub
parent 5018c5012c
commit e0a02567fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 57 additions and 22 deletions

View File

@ -13,17 +13,9 @@ jobs:
uses: actions/setup-go@v2
with:
go-version: '^1.15'
- name: fmt check
run: make fmt
- name: go mod tidy
run: make tidy
- name: Run tests
run: make test
- name: Build
run: make build
- name: lint
run: make lint
- name: Run ci-e2e
- name: Run presubmit tests
run: make all
- name: Run integration tests
env:
GITHUB_AUTH_TOKEN: ${{ secrets.GH_AUTH_TOKEN }}
run: |

View File

@ -1,27 +1,44 @@
SHELL := /bin/bash
GOBIN ?= $(GOPATH)/bin
GINKGO ?= $(GOBIN)/ginkgo
all: fmt tidy lint test
build:
.PHONY: help
help: ## Display this help
@awk \
-v "col=${COLOR}" -v "nocol=${NOCOLOR}" \
' \
BEGIN { \
FS = ":.*##" ; \
printf "Available targets:\n"; \
} \
/^[a-zA-Z0-9_-]+:.*?##/ { \
printf " %s%-25s%s %s\n", col, $$1, nocol, $$2 \
} \
/^##@/ { \
printf "\n%s%s%s\n", col, substr($$0, 5), nocol \
} \
' $(MAKEFILE_LIST)
all: ## Runs build, test and verify
.PHONY: all
all: build test verify
.PHONY: build
build: ## Runs go build and generates executable
CGO_ENABLED=0 go build -a -tags netgo -ldflags '-w -extldflags "-static"'
fmt:
go fmt ./...
# ignoring e2e tests
test:
.PHONY: test
test: ## Runs unit test
# ignoring e2e tests
go test -covermode atomic `go list ./... | grep -v e2e`
tidy:
go mod tidy
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
golangci-lint:
rm -f $(GOLANGCI_LINT) || :
set -e ;\
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell dirname $(GOLANGCI_LINT)) v1.36.0 ;\
lint: golangci-lint ## Run golangci-lint linter
lint: golangci-lint ## Runs golangci-lint linter
$(GOLANGCI_LINT) run -n
check-env:
@ -29,6 +46,7 @@ ifndef GITHUB_AUTH_TOKEN
$(error GITHUB_AUTH_TOKEN is undefined)
endif
e2e: ## Runs e2e tests
.PHONY: e2e
# export GITHUB_AUTH_TOKEN with personal access token to run the e2e
e2e: build check-env ginkgo
@ -36,6 +54,8 @@ e2e: build check-env ginkgo
ginkgo:
GO111MODULE=off go get -u github.com/onsi/ginkgo/ginkgo
ci-e2e: ## Runs ci e2e tests
.PHONY: ci-e2e
# export GITHUB_AUTH_TOKEN with personal access token to run the e2e
ci-e2e: build check-env
@ -44,3 +64,14 @@ ci-e2e: build check-env
./scorecard --repo=https://github.com/ossf/scorecard --format json > ./bin/results.json
ginkgo -p -v -cover ./...
# Verification targets
.PHONY: verify
verify: verify-go-mod lint ## Run all verification targets
.PHONY: verify-go-mod
verify-go-mod: ## Verify the go modules
export GO111MODULE=on && \
go mod tidy && \
go mod verify
./hack/tree-status

12
hack/tree-status Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
STATUS=$(git status --porcelain)
if [[ -z $STATUS ]]; then
echo tree is clean
else
echo tree is dirty, please commit all changes
echo "$STATUS"
git diff
exit 1
fi