Skip to content

Commit

Permalink
Updated makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed Oct 29, 2021
1 parent 3ed0edd commit 07fc130
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
22 changes: 20 additions & 2 deletions .make/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
37 changes: 31 additions & 6 deletions .make/go.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,68 @@ 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)
@test $(VERSION_SHORT)
@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)..."
Expand All @@ -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)
Expand All @@ -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 ./...
@go vet -v ./...

0 comments on commit 07fc130

Please sign in to comment.