Skip to content

Commit

Permalink
Updated makefile library
Browse files Browse the repository at this point in the history
  • Loading branch information
mrz1836 committed May 14, 2020
1 parent 0d61aad commit 748922c
Show file tree
Hide file tree
Showing 5 changed files with 182 additions and 115 deletions.
1 change: 0 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# ---------------------------
before:
hooks:
# run make all
- make all
snapshot:
name_template: "{{ .Tag }}"
Expand Down
65 changes: 65 additions & 0 deletions .make/Makefile.common
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
## Default repository domain name
ifndef GIT_DOMAIN
override GIT_DOMAIN=github.com
endif

## Do we have git available?
HAS_GIT := $(shell command -v git 2> /dev/null)

ifdef HAS_GIT
## Do we have a repo?
HAS_REPO := $(shell git rev-parse --is-inside-work-tree 2> /dev/null)
ifdef HAS_REPO
## Automatically detect the repo owner and repo name (for local use with Git)
REPO_NAME=$(shell basename "$(shell git rev-parse --show-toplevel 2> /dev/null)")
REPO_OWNER=$(shell git config --get remote.origin.url | sed 's/git@$(GIT_DOMAIN)://g' | sed 's/\/$(REPO_NAME).git//g')
VERSION_SHORT=$(shell git describe --tags --always --abbrev=0)
export REPO_NAME, REPO_OWNER, VERSION_SHORT
endif
endif

## Set the distribution folder
ifndef DISTRIBUTIONS_DIR
override DISTRIBUTIONS_DIR=./dist
endif
export DISTRIBUTIONS_DIR

help: ## Show this help message
@egrep -h '^(.+)\:\ ##\ (.+)' ${MAKEFILE_LIST} | column -t -c 2 -s ':#'

release:: ## Full production release (creates release in Github)
@test $(github_token)
@export GITHUB_TOKEN=$(github_token) && goreleaser --rm-dist

release-test: ## Full production test release (everything except deploy)
@goreleaser --skip-publish --rm-dist

release-snap: ## Test the full release (build binaries)
@goreleaser --snapshot --skip-publish --rm-dist

replace-version: ## Replaces the version in HTML/JS (pre-deploy)
@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)
@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)
@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)
@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
80 changes: 80 additions & 0 deletions .make/Makefile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
## Default to the repo name if empty
ifndef BINARY_NAME
override BINARY_NAME=app
endif

## Define the binary name
ifdef CUSTOM_BINARY_NAME
override BINARY_NAME=$(CUSTOM_BINARY_NAME)
endif

## Set the binary release names
DARWIN=$(BINARY_NAME)-darwin
LINUX=$(BINARY_NAME)-linux
WINDOWS=$(BINARY_NAME)-windows.exe

.PHONY: test lint install

bench: ## Run all benchmarks in the Go application
@go test -bench ./... -benchmem -v

build-go: ## Build the Go application (locally)
@go build -o bin/$(BINARY_NAME)

clean-mods: ## Remove all the Go mod cache
@go clean -modcache

coverage: ## Shows the test coverage
@go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out

godocs: ## Sync the latest tag with 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
@go build -o $$GOPATH/bin/$(BINARY_NAME)

install-go: ## Install the application (Using Native Go)
@go install $(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME)

lint: ## Run the Go lint application
@if [ "$(shell command -v golint)" = "" ]; then go get -u golang.org/x/lint/golint; fi
@golint

test: ## Runs vet, lint and ALL tests
@$(MAKE) vet
@$(MAKE) lint
@go test ./... -v

test-short: ## Runs vet, lint and tests (excludes integration tests)
@$(MAKE) vet
@$(MAKE) lint
@go test ./... -v -test.short

test-travis: ## Runs all tests via Travis (also exports coverage)
@$(MAKE) vet
@$(MAKE) lint
@go test ./... -race -coverprofile=coverage.txt -covermode=atomic

test-travis-short: ## Runs unit tests via Travis (also exports coverage)
@$(MAKE) vet
@$(MAKE) lint
@go test ./... -test.short -race -coverprofile=coverage.txt -covermode=atomic

uninstall: ## Uninstall the application (and remove files)
@test $(BINARY_NAME)
@test $(GIT_DOMAIN)
@test $(REPO_OWNER)
@test $(REPO_NAME)
@go clean -i $(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME)
@rm -rf $$GOPATH/src/$(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME)
@rm -rf $$GOPATH/bin/$(BINARY_NAME)

update: ## Update all project dependencies
@go get -u ./... && go mod tidy

vet: ## Run the Go vet application
@go vet -v ./...
103 changes: 10 additions & 93 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
## Default repository domain name
ifndef GIT_DOMAIN
override GIT_DOMAIN=github.com
endif

## Do we have git available?
HAS_GIT := $(shell command -v git 2> /dev/null)

ifdef HAS_GIT
## Automatically detect the repo owner and repo name (for local use with Git)
REPO_NAME=$(shell basename `git rev-parse --show-toplevel`)
REPO_OWNER=$(shell git config --get remote.origin.url | sed 's/git@$(GIT_DOMAIN)://g' | sed 's/\/$(REPO_NAME).git//g')
# Common makefile commands & variables between projects
include .make/Makefile.common

## Set the version (for go docs)
VERSION_SHORT=$(shell git describe --tags --always --abbrev=0)
endif
# Common Golang makefile commands & variables between projects
include .make/Makefile.go

## Not defined? Use default repo name which is the application
ifeq ($(REPO_NAME),)
Expand All @@ -25,90 +14,18 @@ ifeq ($(REPO_OWNER),)
REPO_OWNER="mrz1836"
endif

## Set the distribution folder
ifndef DISTRIBUTIONS_DIR
override DISTRIBUTIONS_DIR=./dist
endif

.PHONY: test lint clean release
.PHONY: clean

all: test-short ## Runs lint, test-short and vet

bench: ## Run all benchmarks in the Go application
@go test -bench ./... -benchmem -v
all: ## Runs multiple commands
@$(MAKE) test

clean: ## Remove previous builds and any test cache data
@go clean -cache -testcache -i -r
@test $(DISTRIBUTIONS_DIR)
@if [ -d $(DISTRIBUTIONS_DIR) ]; then rm -r $(DISTRIBUTIONS_DIR); fi

clean-mods: ## Remove all the Go mod cache
@go clean -modcache

coverage: ## Shows the test coverage
@go test -coverprofile=coverage.out ./... && go tool cover -func=coverage.out

godocs: ## Sync the latest tag with GoDocs
@curl https://proxy.golang.org/$(GIT_DOMAIN)/$(REPO_OWNER)/$(REPO_NAME)/@v/$(VERSION_SHORT).info

help: ## Show all make commands available
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

lint: ## Run the Go lint application
@if [ "$(shell command -v golint)" = "" ]; then go get -u golang.org/x/lint/golint; fi
@golint

release: ## Full production release (creates release in Github)
@goreleaser --rm-dist
release:: ## Runs common.release then runs godocs
@$(MAKE) godocs

release-test: ## Full production test release (everything except deploy)
@goreleaser --skip-publish --rm-dist

release-snap: ## Test the full release (build binaries)
@goreleaser --snapshot --skip-publish --rm-dist

run-examples: ## Runs all the examples
@go run examples/examples.go

tag: ## Generate a new tag and push (IE: tag version=0.0.0)
@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 (IE: tag-remove version=0.0.0)
@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 (IE: tag-update version=0.0.0)
@test $(version)
@git push --force origin HEAD:refs/tags/v$(version)
@git fetch --tags -f

test: ## Runs vet, lint and ALL tests
@$(MAKE) vet
@$(MAKE) lint
@go test ./... -v

test-short: ## Runs vet, lint and tests (excludes integration tests)
@$(MAKE) vet
@$(MAKE) lint
@go test ./... -v -test.short

test-travis: ## Runs tests via Travis (also exports coverage)
@$(MAKE) vet
@$(MAKE) lint
@go test ./... -race -coverprofile=coverage.txt -covermode=atomic

update: ## Update all project dependencies
@go get -u ./...
@go mod tidy

update-releaser: ## Update the goreleaser application
@brew update
@brew upgrade goreleaser

vet: ## Run the Go vet application
@go vet -v
@go run examples/examples.go
48 changes: 27 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ View the generated [documentation](https://pkg.go.dev/github.com/mrz1836/go-para

<details>
<summary><strong><code>Package Dependencies</code></strong></summary>
<br/>

- Gorilla's [mux](https://github.com/gorilla/mux) package.
- Julien Schmidt's [httprouter](https://github.com/julienschmidt/httprouter) package.
Expand All @@ -56,6 +57,7 @@ View the generated [documentation](https://pkg.go.dev/github.com/mrz1836/go-para

<details>
<summary><strong><code>Library Deployment</code></strong></summary>
<br/>

[goreleaser](https://github.com/goreleaser/goreleaser) for easy binary or library deployment to Github and can be installed via: `brew install goreleaser`.

Expand All @@ -66,6 +68,7 @@ Use `make release-snap` to create a snapshot version of the release, and finally

<details>
<summary><strong><code>Makefile Commands</code></strong></summary>
<br/>

View all `makefile` commands
```shell script
Expand All @@ -74,26 +77,30 @@ make help

List of all current commands:
```text
all Runs lint, test-short and vet
bench Run all benchmarks in the Go application
clean Remove previous builds and any test cache data
clean-mods Remove all the Go mod cache
coverage Shows the test coverage
godocs Sync the latest tag with GoDocs
help Show all make commands available
lint Run the Go lint application
release Full production release (creates release in Github)
release-test Full production test release (everything except deploy)
release-snap Test the full release (build binaries)
run-examples Runs all the examples
tag Generate a new tag and push (IE: tag version=0.0.0)
tag-remove Remove a tag if found (IE: tag-remove version=0.0.0)
tag-update Update an existing tag to current commit (IE: tag-update version=0.0.0)
test Runs vet, lint and ALL tests
test-short Runs vet, lint and tests (excludes integration tests)
update Update all project dependencies
update-releaser Update the goreleaser application
vet Run the Go vet application
all Runs multiple commands
clean Remove previous builds and any test cache data
clean-mods Remove all the Go mod cache
coverage Shows the test coverage
godocs Sync the latest tag with GoDocs
help Show this help message
install Install the application
install-go Install the application (Using Native Go)
lint Run the Go lint application
release Full production release (creates release in Github)
release Runs common.release then runs godocs
release-snap Test the full release (build binaries)
release-test Full production test release (everything except deploy)
replace-version Replaces the version in HTML/JS (pre-deploy)
run-examples Runs all the examples
tag Generate a new tag and push (tag version=0.0.0)
tag-remove Remove a tag if found (tag-remove version=0.0.0)
tag-update Update an existing tag to current commit (tag-update version=0.0.0)
test Runs vet, lint and ALL tests
test-short Runs vet, lint and tests (excludes integration tests)
test-travis Runs all tests via Travis (also exports coverage)
test-travis-short Runs unit tests via Travis (also exports coverage)
uninstall Uninstall the application (and remove files)
vet Run the Go vet application
```
</details>

Expand Down Expand Up @@ -162,7 +169,6 @@ func main() {
<br/>

## Maintainers

| [<img src="https://github.com/mrz1836.png" height="50" alt="MrZ" />](https://github.com/mrz1836) | [<img src="https://github.com/kayleg.png" height="50" alt="kayleg" />](https://github.com/kayleg) |
|:---:|:---:|
| [MrZ](https://github.com/mrz1836) | [kayleg](https://github.com/kayleg) |
Expand Down

0 comments on commit 748922c

Please sign in to comment.