From 07fc130b2831f933a5d97c378906d12ee8ff0148 Mon Sep 17 00:00:00 2001 From: mrz1836 Date: Fri, 29 Oct 2021 15:35:17 -0400 Subject: [PATCH] Updated makefile --- .make/common.mk | 22 ++++++++++++++++++++-- .make/go.mk | 37 +++++++++++++++++++++++++++++++------ 2 files changed, 51 insertions(+), 8 deletions(-) diff --git a/.make/common.mk b/.make/common.mk index 9b24ae7..5d92c0a 100644 --- a/.make/common.mk +++ b/.make/common.mk @@ -31,42 +31,60 @@ ifndef DISTRIBUTIONS_DIR endif export DISTRIBUTIONS_DIR +.PHONY: diff + +diff: ## Show the git diff + $(call print-target) + git diff --exit-code + RES=$$(git status --porcelain) ; if [ -n "$$RES" ]; then echo $$RES && exit 1 ; fi + help: ## Show this help message @egrep -h '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#' +install-releaser: ## Install the GoReleaser application + @echo "installing GoReleaser..." + @curl -sfL https://install.goreleaser.com/github.com/goreleaser/goreleaser.sh | sh + release:: ## Full production release (creates release in Github) + @echo "releasing..." @test $(github_token) @export GITHUB_TOKEN=$(github_token) && goreleaser --rm-dist release-test: ## Full production test release (everything except deploy) + @echo "creating a release test..." @goreleaser --skip-publish --rm-dist release-snap: ## Test the full release (build binaries) + @echo "creating a release snapshot..." @goreleaser --snapshot --skip-publish --rm-dist replace-version: ## Replaces the version in HTML/JS (pre-deploy) + @echo "replacing version..." @test $(version) @test "$(path)" @find $(path) -name "*.html" -type f -exec sed -i '' -e "s/{{version}}/$(version)/g" {} \; @find $(path) -name "*.js" -type f -exec sed -i '' -e "s/{{version}}/$(version)/g" {} \; tag: ## Generate a new tag and push (tag version=0.0.0) + @echo "creating new tag..." @test $(version) @git tag -a v$(version) -m "Pending full release..." @git push origin v$(version) @git fetch --tags -f tag-remove: ## Remove a tag if found (tag-remove version=0.0.0) + @echo "removing tag..." @test $(version) @git tag -d v$(version) @git push --delete origin v$(version) @git fetch --tags tag-update: ## Update an existing tag to current commit (tag-update version=0.0.0) + @echo "updating tag to new commit..." @test $(version) @git push --force origin HEAD:refs/tags/v$(version) @git fetch --tags -f update-releaser: ## Update the goreleaser application - @brew update - @brew upgrade goreleaser + @echo "updating GoReleaser application..." + @$(MAKE) install-releaser diff --git a/.make/go.mk b/.make/go.mk index fadc906..49708b6 100644 --- a/.make/go.mk +++ b/.make/go.mk @@ -13,21 +13,30 @@ DARWIN=$(BINARY_NAME)-darwin LINUX=$(BINARY_NAME)-linux WINDOWS=$(BINARY_NAME)-windows.exe -.PHONY: test lint vet install +.PHONY: test lint vet install generate bench: ## Run all benchmarks in the Go application + @echo "running benchmarks..." @go test -bench=. -benchmem build-go: ## Build the Go application (locally) + @echo "building go app..." @go build -o bin/$(BINARY_NAME) clean-mods: ## Remove all the Go mod cache + @echo "cleaning mods..." @go clean -modcache coverage: ## Shows the test coverage + @echo "creating coverage report..." @go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out +generate: ## Runs the go generate command in the base of the repo + @echo "generating files..." + @go generate -v + godocs: ## Sync the latest tag with GoDocs + @echo "syndicating to GoDocs..." @test $(GIT_DOMAIN) @test $(REPO_OWNER) @test $(REPO_NAME) @@ -35,28 +44,37 @@ godocs: ## Sync the latest tag with GoDocs @curl https://proxy.golang.org/$(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME)/@v/$(VERSION_SHORT).info install: ## Install the application + @echo "installing binary..." @go build -o $$GOPATH/bin/$(BINARY_NAME) install-go: ## Install the application (Using Native Go) + @echo "installing package..." @go install $(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME) lint: ## Run the golangci-lint application (install if not found) + @echo "installing golangci-lint..." @#Travis (has sudo) - @if [ "$(shell command -v golangci-lint)" = "" ] && [ $(TRAVIS) ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.41.1 && sudo cp ./bin/golangci-lint $(go env GOPATH)/bin/; fi; + @if [ "$(shell command -v golangci-lint)" = "" ] && [ $(TRAVIS) ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.42.1 && sudo cp ./bin/golangci-lint $(go env GOPATH)/bin/; fi; @#AWS CodePipeline - @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(CODEBUILD_BUILD_ID)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.41.1; fi; + @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(CODEBUILD_BUILD_ID)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.42.1; fi; @#Github Actions - @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(GITHUB_WORKFLOW)" != "" ]; then curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.41.1; fi; + @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(GITHUB_WORKFLOW)" != "" ]; then curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sudo sh -s -- -b $(go env GOPATH)/bin v1.42.1; fi; @#Brew - MacOS @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(shell command -v brew)" != "" ]; then brew install golangci-lint; fi; + @#MacOS Vanilla + @if [ "$(shell command -v golangci-lint)" = "" ] && [ "$(shell command -v brew)" != "" ]; then curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- v1.42.1; fi; @echo "running golangci-lint..." @golangci-lint run --verbose -test: ## Runs vet, lint and ALL tests +test: ## Runs lint and ALL tests @$(MAKE) lint @echo "running tests..." @go test ./... -v +test-unit: ## Runs tests and outputs coverage + @echo "running unit tests..." + @go test ./... -race -coverprofile=coverage.txt -covermode=atomic + test-short: ## Runs vet, lint and tests (excludes integration tests) @$(MAKE) lint @echo "running tests (short)..." @@ -77,7 +95,12 @@ test-ci-short: ## Runs unit tests via CI (exports coverage) @echo "running tests (CI - unit tests only)..." @go test ./... -test.short -race -coverprofile=coverage.txt -covermode=atomic +test-no-lint: ## Runs just tests + @echo "running tests..." + @go test ./... -v + uninstall: ## Uninstall the application (and remove files) + @echo "uninstalling go application..." @test $(BINARY_NAME) @test $(GIT_DOMAIN) @test $(REPO_OWNER) @@ -87,11 +110,13 @@ uninstall: ## Uninstall the application (and remove files) @rm -rf $$GOPATH/bin/$(BINARY_NAME) update: ## Update all project dependencies + @echo "updating dependencies..." @go get -u ./... && go mod tidy update-linter: ## Update the golangci-lint package (macOS only) + @echo "upgrading golangci-lint..." @brew upgrade golangci-lint vet: ## Run the Go vet application @echo "running go vet..." - @go vet -v ./... \ No newline at end of file + @go vet -v ./...